diff --git a/module/bug/test/lib/zen.class.php b/module/bug/test/lib/zen.class.php index 0066db485b..c505db974a 100644 --- a/module/bug/test/lib/zen.class.php +++ b/module/bug/test/lib/zen.class.php @@ -345,4 +345,29 @@ class bugZenTest extends baseTest return $output; } + + /** + * Test buildBugsForBatchEdit method. + * + * @param array $oldBugs + * @access public + * @return array|false + */ + public function buildBugsForBatchEditTest(array $oldBugs = array()) + { + $result = $this->invokeArgs('buildBugsForBatchEdit', [$oldBugs]); + if(dao::isError()) return false; + + $output = array(); + $output['count'] = count($result); + if(!empty($result)) + { + foreach($result as $index => $bug) + { + $output[$index] = $bug; + } + } + + return $output; + } } diff --git a/module/bug/test/zen/buildbugsforbatchedit.php b/module/bug/test/zen/buildbugsforbatchedit.php new file mode 100755 index 0000000000..8811ab83fb --- /dev/null +++ b/module/bug/test/zen/buildbugsforbatchedit.php @@ -0,0 +1,156 @@ +#!/usr/bin/env php +loadYaml('buildbugsforbatchedit/bug', false, 2)->gen(10); +zendata('product')->loadYaml('buildbugsforbatchedit/product', false, 2)->gen(3); +zendata('project')->loadYaml('buildbugsforbatchedit/project', false, 2)->gen(5); + +su('admin'); + +global $tester, $app; +$app->rawModule = 'bug'; +$app->rawMethod = 'batchedit'; + +$zen = initReference('bug'); +$func = $zen->getMethod('buildBugsForBatchEdit'); + +// 测试步骤1:空参数输入 +$oldBugs1 = array(); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs1]); +r(count($result)) && p() && e('0'); // 测试步骤1:空参数输入返回空数组 + +// 准备老bug数据 +$oldBug1 = new stdClass(); +$oldBug1->id = 1; +$oldBug1->status = 'active'; +$oldBug1->assignedTo = 'admin'; +$oldBug1->openedBy = 'user1'; + +$oldBug2 = new stdClass(); +$oldBug2->id = 2; +$oldBug2->status = 'closed'; +$oldBug2->assignedTo = 'user1'; +$oldBug2->openedBy = 'user2'; + +$oldBug3 = new stdClass(); +$oldBug3->id = 3; +$oldBug3->status = 'active'; +$oldBug3->assignedTo = 'user2'; +$oldBug3->openedBy = 'user3'; + +// 测试步骤2:验证os数组字段转换 +$_POST['id'] = array(1); +$_POST['title'] = array('测试Bug1'); +$_POST['os'] = array('windows'); +$_POST['browser'] = array('chrome'); +$_POST['assignedTo'] = array('admin'); +$_POST['resolution'] = array(''); +$_POST['resolvedBy'] = array(''); +$_POST['duplicateBug'] = array(0); +$_POST['openedBuild'] = array('trunk'); +$oldBugs2 = array(1 => $oldBug1); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs2]); +r($result) && p('0:os') && e('windows'); // 测试步骤2:验证os字段被正确处理 + +// 测试步骤3:验证browser数组字段转换 +$_POST['id'] = array(1); +$_POST['title'] = array('测试Bug1'); +$_POST['os'] = array('windows'); +$_POST['browser'] = array('firefox'); +$_POST['assignedTo'] = array('admin'); +$_POST['resolution'] = array(''); +$_POST['resolvedBy'] = array(''); +$_POST['duplicateBug'] = array(0); +$_POST['openedBuild'] = array('trunk'); +$oldBugs3 = array(1 => $oldBug1); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs3]); +r($result) && p('0:browser') && e('firefox'); // 测试步骤3:验证browser字段被正确处理 + +// 测试步骤4:验证关闭状态bug指派人不变 +$_POST['id'] = array(2); +$_POST['title'] = array('测试Bug2'); +$_POST['os'] = array('mac'); +$_POST['browser'] = array('safari'); +$_POST['assignedTo'] = array('user3'); +$_POST['resolution'] = array(''); +$_POST['resolvedBy'] = array(''); +$_POST['duplicateBug'] = array(0); +$_POST['openedBuild'] = array('trunk'); +$oldBugs4 = array(2 => $oldBug2); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs4]); +r($result) && p('0:assignedTo') && e('user1'); // 测试步骤4:验证关闭状态的bug指派人保持不变 + +// 测试步骤5:验证resolution非duplicate时duplicateBug设为0 +$_POST['id'] = array(1); +$_POST['title'] = array('测试Bug1'); +$_POST['os'] = array('windows'); +$_POST['browser'] = array('chrome'); +$_POST['assignedTo'] = array('admin'); +$_POST['resolution'] = array('fixed'); +$_POST['resolvedBy'] = array('admin'); +$_POST['duplicateBug'] = array(5); +$_POST['openedBuild'] = array('trunk'); +$oldBugs5 = array(1 => $oldBug1); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs5]); +r($result) && p('0:duplicateBug') && e('0'); // 测试步骤5:验证resolution非duplicate时duplicateBug设为0 + +// 测试步骤6:验证assignedTo变化时设置assignedDate +$_POST['id'] = array(3); +$_POST['title'] = array('测试Bug3'); +$_POST['os'] = array('linux'); +$_POST['browser'] = array('firefox'); +$_POST['assignedTo'] = array('user3'); +$_POST['resolution'] = array(''); +$_POST['resolvedBy'] = array(''); +$_POST['duplicateBug'] = array(0); +$_POST['openedBuild'] = array('trunk'); +$oldBugs6 = array(3 => $oldBug3); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs6]); +r($result) && p('0:assignedDate') && e('`^[\d\-\:\s]+$`'); // 测试步骤6:验证assignedTo变化时自动设置assignedDate + +// 测试步骤7:验证设置resolution时confirmed自动设为1 +$_POST['id'] = array(1); +$_POST['title'] = array('测试Bug1'); +$_POST['os'] = array('windows'); +$_POST['browser'] = array('chrome'); +$_POST['assignedTo'] = array('admin'); +$_POST['resolution'] = array('fixed'); +$_POST['resolvedBy'] = array('admin'); +$_POST['duplicateBug'] = array(0); +$_POST['openedBuild'] = array('trunk'); +$oldBugs7 = array(1 => $oldBug1); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs7]); +r($result) && p('0:confirmed') && e('1'); // 测试步骤7:验证设置resolution时confirmed自动设为1 + +// 测试步骤8:验证解决后状态变为resolved +$_POST['id'] = array(1); +$_POST['title'] = array('测试Bug1'); +$_POST['os'] = array('windows'); +$_POST['browser'] = array('chrome'); +$_POST['assignedTo'] = array('admin'); +$_POST['resolution'] = array('fixed'); +$_POST['resolvedBy'] = array('admin'); +$_POST['duplicateBug'] = array(0); +$_POST['openedBuild'] = array('trunk'); +$oldBugs8 = array(1 => $oldBug1); +$result = $func->invokeArgs($zen->newInstance(), [$oldBugs8]); +r($result) && p('0:status') && e('resolved'); // 测试步骤8:验证解决后状态变为resolved \ No newline at end of file diff --git a/module/bug/test/zen/yaml/buildbugsforbatchedit/bug.yaml b/module/bug/test/zen/yaml/buildbugsforbatchedit/bug.yaml new file mode 100644 index 0000000000..a868ff5fa7 --- /dev/null +++ b/module/bug/test/zen/yaml/buildbugsforbatchedit/bug.yaml @@ -0,0 +1,90 @@ +--- +title: Bug数据定义 +author: Claude +version: 1.0 + +fields: +- field: id + note: Bug ID + range: 1-10 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: product + note: 所属产品 + range: 1-3 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: project + note: 所属项目 + range: 1-5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: title + note: Bug标题 + range: Bug标题1,Bug标题2,Bug标题3,Bug标题4,Bug标题5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: status + note: Bug状态 + range: active,resolved,closed + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: assignedTo + note: 指派给 + range: admin,user1,user2,user3 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: openedBy + note: 创建人 + range: admin,user1,user2 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: os + note: 操作系统 + range: windows,linux,mac,android + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: browser + note: 浏览器 + range: chrome,firefox,safari,edge + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: resolution + note: 解决方案 + range: '',fixed,duplicate,willnotfix + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: resolvedBy + note: 解决者 + range: '',admin,user1 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: confirmed + note: 是否确认 + range: 0,1 + prefix: "" + postfix: "" + loop: 0 + format: "" diff --git a/module/bug/test/zen/yaml/buildbugsforbatchedit/product.yaml b/module/bug/test/zen/yaml/buildbugsforbatchedit/product.yaml new file mode 100644 index 0000000000..cc3001b1c8 --- /dev/null +++ b/module/bug/test/zen/yaml/buildbugsforbatchedit/product.yaml @@ -0,0 +1,34 @@ +--- +title: 产品数据定义 +author: Claude +version: 1.0 + +fields: +- field: id + note: 产品ID + range: 1-3 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 产品名称 + range: 产品1,产品2,产品3 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: type + note: 产品类型 + range: normal + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: status + note: 状态 + range: normal + prefix: "" + postfix: "" + loop: 0 + format: "" diff --git a/module/bug/test/zen/yaml/buildbugsforbatchedit/project.yaml b/module/bug/test/zen/yaml/buildbugsforbatchedit/project.yaml new file mode 100644 index 0000000000..f38a764d68 --- /dev/null +++ b/module/bug/test/zen/yaml/buildbugsforbatchedit/project.yaml @@ -0,0 +1,41 @@ +--- +title: 项目数据定义 +author: Claude +version: 1.0 + +fields: +- field: id + note: 项目ID + range: 1-5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 项目名称 + range: 项目1,项目2,项目3,项目4,项目5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: type + note: 项目类型 + range: project + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: model + note: 项目模式 + range: scrum,waterfall + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: status + note: 状态 + range: doing + prefix: "" + postfix: "" + loop: 0 + format: ""