* Refactor batchUnlinkBug method and case.
This commit is contained in:
@@ -688,15 +688,16 @@ class build extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch unlink story.
|
||||
* 批量解除Bug跟版本的关联关系。
|
||||
* Batch unlink bugs.
|
||||
*
|
||||
* @param int $buildID
|
||||
* @param int $buildID
|
||||
* @access public
|
||||
* @return bool
|
||||
* @return void
|
||||
*/
|
||||
public function batchUnlinkBug(int $buildID)
|
||||
{
|
||||
$this->build->batchUnlinkBug($buildID);
|
||||
if($this->post->bugIdList) $this->build->batchUnlinkBug($buildID, $this->post->bugIdList);
|
||||
return $this->sendSuccess(array('load' => $this->createLink('build', 'view', "buildID=$buildID&type=bug")));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-6
@@ -710,25 +710,31 @@ class buildModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量解除Bug跟版本的关联关系。
|
||||
* Batch unlink bug.
|
||||
*
|
||||
* @param int $buildID
|
||||
* @param array $bugIdList
|
||||
* @access public
|
||||
* @return true|void
|
||||
* @return bool
|
||||
*/
|
||||
public function batchUnlinkBug(int $buildID)
|
||||
public function batchUnlinkBug(int $buildID, array $bugIdList): bool
|
||||
{
|
||||
$bugList = $this->post->bugIdList;
|
||||
if(empty($bugList)) return true;
|
||||
if(empty($bugIdList)) return true;
|
||||
|
||||
$build = $this->getByID($buildID);
|
||||
if(!$build) return false;
|
||||
|
||||
$build->bugs = ",$build->bugs,";
|
||||
foreach($bugList as $bugID) $build->bugs = str_replace(",$bugID,", ',', $build->bugs);
|
||||
foreach($bugIdList as $bugID) $build->bugs = str_replace(",$bugID,", ',', $build->bugs);
|
||||
$build->bugs = trim($build->bugs, ',');
|
||||
|
||||
$this->dao->update(TABLE_BUILD)->set('bugs')->eq($build->bugs)->where('id')->eq((int)$buildID)->exec();
|
||||
|
||||
$this->loadModel('action');
|
||||
foreach($bugList as $unlinkBugID) $this->action->create('bug', $unlinkBugID, 'unlinkedfrombuild', '', $buildID);
|
||||
foreach($bugIdList as $unlinkBugID) $this->action->create('bug', $unlinkBugID, 'unlinkedfrombuild', '', $buildID);
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -364,26 +364,21 @@ class buildTest
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function batchUnlinkBugTest($buildID, $bugs)
|
||||
/**
|
||||
* 批量解除Bug跟版本的关联关系。
|
||||
* Batch unlink bugs.
|
||||
*
|
||||
* @param int $buildID
|
||||
* @param array $bugIdList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function batchUnlinkBugTest(int $buildID, array $bugIdList): array
|
||||
{
|
||||
global $tester;
|
||||
|
||||
$createFields = array('bugs' => $bugs);
|
||||
foreach($createFields as $field => $defaultValue) $_POST[$field] = $defaultValue;
|
||||
$this->objectModel->linkBug($buildID);
|
||||
|
||||
unset($_POST);
|
||||
|
||||
$newFields = array('unlinkBugs' => $bugs);
|
||||
foreach($newFields as $field => $defaultValue) $_POST[$field] = $defaultValue;
|
||||
$this->objectModel->batchUnlinkBug($buildID);
|
||||
|
||||
$objects = $tester->dao->select('*')->from(TABLE_BUILD)->where('id')->in($buildID)->fetchAll('id');
|
||||
|
||||
unset($_POST);
|
||||
$this->objectModel->batchUnlinkBug($buildID, $bugIdList);
|
||||
$objects = $this->objectModel->dao->select('*')->from(TABLE_BUILD)->where('id')->in($buildID)->fetchAll('id');
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/build.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 buildModel->batchUnlinkBug();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
批量解除项目版本bug >> ,11
|
||||
批量解除执行版本bug >> ,101
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/build.class.php';
|
||||
|
||||
$buildIDList = array('1', '11');
|
||||
$bugs = array('301', '311');
|
||||
$build = zdTable('build')->config('build');
|
||||
$build->bugs->range('`1,2,3`,`4,5,6`');
|
||||
$build->gen(5);
|
||||
|
||||
$build = new buildTest();
|
||||
zdTable('user')->gen(5);
|
||||
su('admin');
|
||||
|
||||
r($build->batchUnlinkBugTest($buildIDList[0],$bugs)) && p('1:bugs,project') && e(',11');//批量解除项目版本bug
|
||||
r($build->batchUnlinkBugTest($buildIDList[1],$bugs)) && p('11:bugs,execution') && e(',101');//批量解除执行版本bug
|
||||
$buildIdList = array(0, 1, 2, 6);
|
||||
$bugIdList[0] = array();
|
||||
$bugIdList[1] = array(1, 2);
|
||||
$bugIdList[2] = array(4, 5);
|
||||
|
||||
$buildTester = new buildTest();
|
||||
r($buildTester->batchUnlinkBugTest($buildIdList[0], $bugIdList[0])) && p() && e('0'); // 测试buildID=0,bug ID 列表为空
|
||||
r($buildTester->batchUnlinkBugTest($buildIdList[1], $bugIdList[1])) && p('1:id,bugs') && e('1,3'); // 测试buildID=1,bug ID 列表为1,2
|
||||
r($buildTester->batchUnlinkBugTest($buildIdList[2], $bugIdList[2])) && p('2:id,bugs') && e('2,6'); // 测试buildID=2,bug ID 列表为4,5
|
||||
r($buildTester->batchUnlinkBugTest($buildIdList[3], $bugIdList[1])) && p() && e('0'); // 测试buildID不存在,bug ID 列表为1,2
|
||||
|
||||
Reference in New Issue
Block a user