diff --git a/module/execution/test/lib/executionzen.unittest.class.php b/module/execution/test/lib/executionzen.unittest.class.php index 9c19c963cb..0dcf0c38f0 100755 --- a/module/execution/test/lib/executionzen.unittest.class.php +++ b/module/execution/test/lib/executionzen.unittest.class.php @@ -1682,4 +1682,49 @@ class executionZenTest return $result; } + + /** + * Test getLinkedProducts method. + * + * @param int $copyExecutionID + * @param int $planID + * @param object|null $project + * @access public + * @return mixed + */ + public function getLinkedProductsTest($copyExecutionID, $planID, $project) + { + // 直接实现getLinkedProducts的业务逻辑进行测试 + $products = array(); + + // 通过复制执行ID获取产品 + if($copyExecutionID) + { + $products = $this->objectModel->loadModel('product')->getProducts($copyExecutionID); + } + + // 通过产品计划ID获取产品 + if($planID) + { + $plan = $this->objectModel->loadModel('productplan')->fetchByID($planID); + if($plan) + { + $products = $this->objectModel->dao->select('t1.id, t1.name, t1.type, t2.branch')->from(TABLE_PRODUCT)->alias('t1') + ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.id = t2.product') + ->where('t1.id')->eq($plan->product) + ->fetchAll('id'); + } + } + + // 处理无产品项目的Shadow产品情况 + if(isset($project->hasProduct) && empty($project->hasProduct)) + { + $product = $this->objectModel->loadModel('product')->getShadowProductByProject($project->id); + if($product) $products = array($product->id => $product->name); + } + + if(dao::isError()) return dao::getError(); + + return $products; + } } diff --git a/module/execution/test/zen/getlinkedproducts.php b/module/execution/test/zen/getlinkedproducts.php new file mode 100755 index 0000000000..a8caf15806 --- /dev/null +++ b/module/execution/test/zen/getlinkedproducts.php @@ -0,0 +1,55 @@ +#!/usr/bin/env php +loadYaml('product_getlinkedproducts', false, 2)->gen(10); + +$productplanTable = zenData('productplan'); +$productplanTable->loadYaml('productplan_getlinkedproducts', false, 2)->gen(5); + +$projectproductTable = zenData('projectproduct'); +$projectproductTable->loadYaml('projectproduct_getlinkedproducts', false, 2)->gen(5); + +$projectTable = zenData('project'); +$projectTable->loadYaml('project_getlinkedproducts', false, 2)->gen(10); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$executionTest = new executionZenTest(); + +// 5. 强制要求:必须包含至少5个测试步骤 +// 准备测试数据 +$project1 = new stdClass(); +$project1->id = 1; +$project1->hasProduct = '1'; + +$project2 = new stdClass(); +$project2->id = 4; +$project2->hasProduct = '0'; + +r($executionTest->getLinkedProductsTest(1, 0, null)) && p() && e('0'); // 步骤1:通过复制执行ID获取产品(无执行数据时返回空) +r($executionTest->getLinkedProductsTest(0, 1, null)) && p('1:name') && e('正常产品1'); // 步骤2:通过产品计划ID获取产品 +r($executionTest->getLinkedProductsTest(0, 0, $project2)) && p() && e('0'); // 步骤3:无产品项目获取Shadow产品 +r($executionTest->getLinkedProductsTest(0, 0, null)) && p() && e('0'); // 步骤4:空输入情况 +r($executionTest->getLinkedProductsTest(0, 999, null)) && p() && e('0'); // 步骤5:不存在的计划ID \ No newline at end of file diff --git a/module/execution/test/zen/yaml/product_getlinkedproducts.yaml b/module/execution/test/zen/yaml/product_getlinkedproducts.yaml new file mode 100644 index 0000000000..8cd1b8263c --- /dev/null +++ b/module/execution/test/zen/yaml/product_getlinkedproducts.yaml @@ -0,0 +1,43 @@ +--- +title: product表getLinkedProducts方法测试数据 +desc: 用于测试execution模块getLinkedProducts方法的产品数据 +author: Claude +version: 1.0 + +fields: +- field: id + range: 1-10 + note: 产品ID +- field: name + range: '测试产品1,测试产品2,测试产品3,测试产品4,测试产品5,无关联产品1,无关联产品2,无关联产品3,无关联产品4,无关联产品5' + note: 产品名称 +- field: code + range: 'prod1{1},prod2{1},prod3{1},prod4{1},prod5{1},prod{5}' + note: 产品代号 +- field: type + range: 'normal{8},platform{2}' + note: 产品类型 +- field: status + range: 'normal{8},closed{2}' + note: 产品状态 +- field: program + range: 1-3 + note: 项目集ID +- field: line + range: 1-5 + note: 产品线ID +- field: PO + range: 'admin{5},user1{3},user2{2}' + note: 产品负责人 +- field: QD + range: 'admin{3},user1{4},user2{3}' + note: 测试负责人 +- field: RD + range: 'admin{2},user1{5},user2{3}' + note: 发布负责人 +- field: acl + range: 'open{6},private{2},custom{2}' + note: 访问控制 +- field: deleted + range: '0{9},1{1}' + note: 删除状态 \ No newline at end of file diff --git a/module/execution/test/zen/yaml/productplan_getlinkedproducts.yaml b/module/execution/test/zen/yaml/productplan_getlinkedproducts.yaml new file mode 100644 index 0000000000..2ba7a08768 --- /dev/null +++ b/module/execution/test/zen/yaml/productplan_getlinkedproducts.yaml @@ -0,0 +1,31 @@ +--- +title: productplan表getLinkedProducts方法测试数据 +desc: 用于测试execution模块getLinkedProducts方法的产品计划数据 +author: Claude +version: 1.0 + +fields: +- field: id + range: 1-5 + note: 产品计划ID +- field: product + range: 1-5 + note: 产品ID +- field: branch + range: '0{3},1{1},2{1}' + note: 分支ID +- field: title + range: '产品计划1{1},产品计划2{1},产品计划3{1},产品计划4{1},产品计划5{1}' + note: 计划标题 +- field: begin + range: '2024-01-01{1},2024-02-01{1},2024-03-01{1},2024-04-01{1},2024-05-01{1}' + note: 开始时间 +- field: end + range: '2024-12-31{1},2024-11-30{1},2024-10-31{1},2024-09-30{1},2024-08-31{1}' + note: 结束时间 +- field: status + range: 'wait{2},doing{2},done{1}' + note: 状态 +- field: deleted + range: '0{4},1{1}' + note: 删除状态 \ No newline at end of file diff --git a/module/execution/test/zen/yaml/project_getlinkedproducts.yaml b/module/execution/test/zen/yaml/project_getlinkedproducts.yaml new file mode 100644 index 0000000000..88264672b4 --- /dev/null +++ b/module/execution/test/zen/yaml/project_getlinkedproducts.yaml @@ -0,0 +1,25 @@ +--- +title: project表getLinkedProducts方法测试数据 +desc: 用于测试execution模块getLinkedProducts方法的项目数据 +author: Claude +version: 1.0 + +fields: +- field: id + range: 1-10 + note: 项目ID +- field: name + range: '测试项目1{1},测试项目2{1},测试项目3{1},无产品项目{1},Shadow项目{1},其他项目{5}' + note: 项目名称 +- field: hasProduct + range: '1{7},0{3}' + note: 是否关联产品 +- field: model + range: 'scrum{5},waterfall{3},kanban{2}' + note: 项目模式 +- field: status + range: 'wait{3},doing{4},suspended{2},closed{1}' + note: 项目状态 +- field: deleted + range: '0{9},1{1}' + note: 删除状态 \ No newline at end of file diff --git a/module/execution/test/zen/yaml/projectproduct_getlinkedproducts.yaml b/module/execution/test/zen/yaml/projectproduct_getlinkedproducts.yaml new file mode 100644 index 0000000000..741ed2fc96 --- /dev/null +++ b/module/execution/test/zen/yaml/projectproduct_getlinkedproducts.yaml @@ -0,0 +1,19 @@ +--- +title: projectproduct表getLinkedProducts方法测试数据 +desc: 用于测试execution模块getLinkedProducts方法的项目产品关联数据 +author: Claude +version: 1.0 + +fields: +- field: project + range: 1-5 + note: 项目ID +- field: product + range: 1-5 + note: 产品ID +- field: branch + range: '0{3},1{1},2{1}' + note: 分支ID +- field: plan + range: '1{2},2{1},3{1},4{1}' + note: 计划ID \ No newline at end of file