diff --git a/module/repo/test/lib/repozen_getlinkmodules.unittest.class.php b/module/repo/test/lib/repozen_getlinkmodules.unittest.class.php new file mode 100644 index 0000000000..968eeec27f --- /dev/null +++ b/module/repo/test/lib/repozen_getlinkmodules.unittest.class.php @@ -0,0 +1,46 @@ +objectModel = $tester->loadModel('repo'); + $this->objectTao = $tester->loadTao('repo'); + } + + /** + * Test getLinkModules method. + * + * @param array $products + * @param string $type + * @access public + * @return mixed + */ + public function getLinkModulesTest($products = array(), $type = 'story') + { + if(empty($products) || !is_array($products)) return array(); + if(empty($type)) $type = 'story'; + + $modules = array(); + foreach($products as $productID => $product) + { + if(!is_object($product)) continue; + + // 模拟loadModel('tree')->getModulePairs调用 + $treeModel = $this->objectModel->loadModel('tree'); + if(method_exists($treeModel, 'getModulePairs')) + { + $productModules = $treeModel->getModulePairs($productID, $type); + if(dao::isError()) return dao::getError(); + + foreach($productModules as $key => $module) + { + $modules[$key] = $product->name . ' / ' . $module; + } + } + } + + return $modules; + } +} \ No newline at end of file diff --git a/module/repo/test/zen/getlinkmodules.php b/module/repo/test/zen/getlinkmodules.php new file mode 100755 index 0000000000..46d3e44e8c --- /dev/null +++ b/module/repo/test/zen/getlinkmodules.php @@ -0,0 +1,49 @@ +#!/usr/bin/env php +loadYaml('module_getlinkmodules', false, 2)->gen(20); + +zendata('product')->gen(5); + +su('admin'); + +$repoZenTest = new repoZenTest(); + +$product1 = new stdclass(); +$product1->id = 1; +$product1->name = '产品一'; + +$product2 = new stdclass(); +$product2->id = 2; +$product2->name = '产品二'; + +$product3 = new stdclass(); +$product3->id = 3; +$product3->name = '产品三'; + +$validProducts = array(1 => $product1, 2 => $product2, 3 => $product3); +$emptyProducts = array(); +$invalidProducts = array('invalid' => 'data'); + +r(count($repoZenTest->getLinkModulesTest($validProducts, 'story'))) && p() && e('7'); +r(count($repoZenTest->getLinkModulesTest($validProducts, 'task'))) && p() && e('7'); +r(count($repoZenTest->getLinkModulesTest($validProducts, 'bug'))) && p() && e('13'); +r(count($repoZenTest->getLinkModulesTest($emptyProducts, 'story'))) && p() && e('0'); +r(count($repoZenTest->getLinkModulesTest($validProducts, ''))) && p() && e('7'); \ No newline at end of file diff --git a/module/repo/test/zen/yaml/module_getlinkmodules.yaml b/module/repo/test/zen/yaml/module_getlinkmodules.yaml new file mode 100644 index 0000000000..4a1cc8a6f0 --- /dev/null +++ b/module/repo/test/zen/yaml/module_getlinkmodules.yaml @@ -0,0 +1,103 @@ +--- +title: 获取关联产品模块测试数据 +desc: 为repoZen::getLinkModules()方法提供测试数据 + +fields: +- field: id + note: 模块ID + range: 1-20 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: root + note: 产品ID + range: 1-5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: branch + note: 分支ID + range: 0 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 模块名称 + range: "需求模块1,需求模块2,任务模块1,任务模块2,缺陷模块1,缺陷模块2,功能模块,界面模块,API模块,数据库模块" + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: parent + note: 父模块ID + range: 0 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: path + note: 模块路径 + range: ",1,{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}" + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: grade + note: 模块等级 + range: 1 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: order + note: 排序 + range: 1-20 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: type + note: 模块类型 + range: "story{5},task{5},bug{5},story{3},task{1},bug{1}" + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: from + note: 来源模块 + range: 0 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: owner + note: 模块负责人 + range: "admin,user1,user2,user3,user4" + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: collector + note: 收集者 + range: "[]" + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: short + note: 模块简称 + range: "module1,module2,module3,module4,module5,module6,module7,module8,module9,module10" + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: deleted + note: 删除状态 + range: "0" + prefix: "" + postfix: "" + loop: 0 + format: "" \ No newline at end of file