* Refactor bugModel::linkBugToBuild, and modify its unit test.
This commit is contained in:
+12
-7
@@ -1786,26 +1786,31 @@ class bugModel extends model
|
||||
/**
|
||||
* Link bug to build and release
|
||||
*
|
||||
* @param string|array $bugs
|
||||
* @param int $resolvedBuild
|
||||
* @param int $bugID
|
||||
* @param int|string $resolvedBuild
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function linkBugToBuild($bugs, $resolvedBuild)
|
||||
public function linkBugToBuild(int $bugID, int|string $resolvedBuild): bool
|
||||
{
|
||||
if(empty($resolvedBuild) or $resolvedBuild == 'trunk') return true;
|
||||
if(is_array($bugs)) $bugs = implode(',', $bugs);
|
||||
/* 如果版本为空,或者版本为主干,返回。 */
|
||||
/* If resolved build is empty or resolved build is trunk, return true. */
|
||||
if(empty($resolvedBuild) || $resolvedBuild == 'trunk') return true;
|
||||
|
||||
/* 获取版本信息,并且将bugs关联到版本。 */
|
||||
/* Get build information, and relate the bugs to the build. */
|
||||
$build = $this->dao->select('id,product,bugs')->from(TABLE_BUILD)->where('id')->eq($resolvedBuild)->fetch();
|
||||
$buildBugs = $build->bugs . ',' . $bugs;
|
||||
$buildBugs = $build->bugs . ',' . $bugID;
|
||||
$buildBugs = explode(',', trim($buildBugs, ','));
|
||||
$buildBugs = array_unique($buildBugs);
|
||||
$this->dao->update(TABLE_BUILD)->set('bugs')->eq(implode(',', $buildBugs))->where('id')->eq($resolvedBuild)->exec();
|
||||
|
||||
/* 将bugs关联到版本关联的发布。 */
|
||||
/* Relate bugs to the build-related release. */
|
||||
$release = $this->dao->select('id,bugs')->from(TABLE_RELEASE)->where('product')->eq($build->product)->andWhere("(FIND_IN_SET('$resolvedBuild', build) or shadow = $resolvedBuild)")->andWhere('deleted')->eq('0')->fetch();
|
||||
if($release)
|
||||
{
|
||||
$releaseBugs = $release->bugs . ',' . $bugs;
|
||||
$releaseBugs = $release->bugs . ',' . $bugID;
|
||||
$releaseBugs = explode(',', trim($releaseBugs, ','));
|
||||
$releaseBugs = array_unique($releaseBugs);
|
||||
$this->dao->update(TABLE_RELEASE)->set('bugs')->eq(implode(',', $releaseBugs))->where('id')->eq($release->id)->exec();
|
||||
|
||||
@@ -1143,14 +1143,14 @@ class bugTest
|
||||
/**
|
||||
* Test link bug to build and release.
|
||||
*
|
||||
* @param array $bugIDList
|
||||
* @param int $resolvedBuild
|
||||
* @param int $bugID
|
||||
* @param int|string $resolvedBuild
|
||||
* @access public
|
||||
* @return object
|
||||
* @return object|array|bool
|
||||
*/
|
||||
public function linkBugToBuildTest($bugIDList, $resolvedBuild)
|
||||
public function linkBugToBuildTest(int $bugID, int|string $resolvedBuild): array|object|bool
|
||||
{
|
||||
$this->objectModel->linkBugToBuild($bugIDList, $resolvedBuild);
|
||||
$this->objectModel->linkBugToBuild($bugID, $resolvedBuild);
|
||||
|
||||
global $tester;
|
||||
$release = $tester->dao->select('id,bugs')->from(TABLE_RELEASE)->where('build')->eq($resolvedBuild)->andWhere('deleted')->eq('0')->fetch();
|
||||
|
||||
@@ -18,17 +18,16 @@ pid=1
|
||||
|
||||
*/
|
||||
|
||||
$bugIDList1 = array('1', '2');
|
||||
$bugIDList2 = array('3', '4');
|
||||
$bugIDList3 = array('5', '6');
|
||||
$bugIDList4 = array('7', '8');
|
||||
$bugIDList5 = array('9', '10');
|
||||
$bugIDList = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
|
||||
$buildList = array('1', '3', '5');
|
||||
$buildList = array(1, 3, 5, 'trunk', 0, '');
|
||||
|
||||
$bug = new bugTest();
|
||||
r($bug->linkBugToBuildTest($bugIDList1, $buildList[0])) && p('bugs', '-') && e('1,2'); // 把bug 1 2关联到build 1
|
||||
r($bug->linkBugToBuildTest($bugIDList2, $buildList[1])) && p('bugs', '-') && e('3,4'); // 把bug 3 4关联到build 3
|
||||
r($bug->linkBugToBuildTest($bugIDList3, $buildList[2])) && p('bugs', '-') && e('5,6'); // 把bug 5 6关联到build 5
|
||||
r($bug->linkBugToBuildTest($bugIDList4, $buildList[0])) && p('bugs', '-') && e('1,2,7,8'); // 把bug 5 6关联到build 1
|
||||
r($bug->linkBugToBuildTest($bugIDList5, $buildList[0])) && p('bugs', '-') && e('1,2,7,8,9,10'); // 把bug 5 6关联到build 1
|
||||
r($bug->linkBugToBuildTest($bugIDList[0], $buildList[0])) && p('bugs', '-') && e('1'); // 把bug 1关联到build 1
|
||||
r($bug->linkBugToBuildTest($bugIDList[1], $buildList[1])) && p('bugs', '-') && e('2'); // 把bug 2关联到build 3
|
||||
r($bug->linkBugToBuildTest($bugIDList[2], $buildList[2])) && p('bugs', '-') && e('3'); // 把bug 3关联到build 5
|
||||
r($bug->linkBugToBuildTest($bugIDList[3], $buildList[0])) && p('bugs', '-') && e('1,4'); // 把bug 4 关联到build 1
|
||||
r($bug->linkBugToBuildTest($bugIDList[4], $buildList[0])) && p('bugs', '-') && e('1,4,5'); // 把bug 5 关联到build 1
|
||||
r($bug->linkBugToBuildTest($bugIDList[5], $buildList[3])) && p('bugs', '-') && e('0'); // 把bug 6 关联到build trunk
|
||||
r($bug->linkBugToBuildTest($bugIDList[6], $buildList[4])) && p('bugs', '-') && e('0'); // 把bug 7 关联到build 0
|
||||
r($bug->linkBugToBuildTest($bugIDList[7], $buildList[5])) && p('bugs', '-') && e('0'); // 把bug 8 关联到build ''
|
||||
|
||||
Reference in New Issue
Block a user