From b9cf83b677015779c07aa5a64fa9456de2b97b4e Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 10 Sep 2025 09:34:55 +0800 Subject: [PATCH] + [misc] Add unit tests for testreportModel::getChildBuilds() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../test/lib/testreport.unittest.class.php | 25 ++++++++ .../testreport/test/model/getchildbuilds.php | 46 ++++++++++++++ .../test/model/yaml/build_getchildbuilds.yaml | 63 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100755 module/testreport/test/model/getchildbuilds.php create mode 100644 module/testreport/test/model/yaml/build_getchildbuilds.yaml diff --git a/module/testreport/test/lib/testreport.unittest.class.php b/module/testreport/test/lib/testreport.unittest.class.php index 20cdb62847..3644174a33 100644 --- a/module/testreport/test/lib/testreport.unittest.class.php +++ b/module/testreport/test/lib/testreport.unittest.class.php @@ -287,4 +287,29 @@ class testreportTest if(dao::isError()) return dao::getError(); return $isClickable ? 1 : 0; } + + /** + * Test getChildBuilds method. + * + * @param array $buildIdList + * @access public + * @return array|string + */ + public function getChildBuildsTest(array $buildIdList): array|string + { + $builds = $this->build->getByList($buildIdList); + $childBuilds = $this->objectModel->getChildBuilds($builds); + + if(dao::isError()) return dao::getError(); + + if(empty($childBuilds)) return ''; + + $result = array(); + foreach($childBuilds as $childBuild) + { + $result[] = $childBuild->id . ':' . $childBuild->name; + } + + return implode(',', $result); + } } diff --git a/module/testreport/test/model/getchildbuilds.php b/module/testreport/test/model/getchildbuilds.php new file mode 100755 index 0000000000..8eb6c3b633 --- /dev/null +++ b/module/testreport/test/model/getchildbuilds.php @@ -0,0 +1,46 @@ +#!/usr/bin/env php +id->range('1-10'); +$table->project->range('1{2},2{2},3{6}'); +$table->product->range('1{10}'); +$table->name->range('版本1.0,版本1.1,版本1.2,版本2.0,版本2.1,版本2.2,版本3.0,子版本1,子版本2,子版本3'); +$table->builds->range('[]{4},8,9,8{2},10,[]{2}'); +$table->bugs->range('1,2,3{2},[]{2},4,5{3}'); +$table->stories->range('1{3},2{2},[]{2},3{3}'); +$table->deleted->range('0{9},1'); +$table->gen(10); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$testreportTest = new testreportTest(); + +// 5. 强制要求:必须包含至少5个测试步骤 +r($testreportTest->getChildBuildsTest(array(5, 6))) && p() && e('8:子版本1,9:子版本2'); // 步骤1:获取有子版本的版本构建列表 +r($testreportTest->getChildBuildsTest(array(1, 2, 3))) && p() && e('0'); // 步骤2:获取没有子版本的版本构建列表 +r($testreportTest->getChildBuildsTest(array())) && p() && e('0'); // 步骤3:获取空版本构建列表 +r($testreportTest->getChildBuildsTest(array(4, 5, 7, 8))) && p() && e('8:子版本1'); // 步骤4:获取混合版本构建列表(有些有子版本,有些没有) +r($testreportTest->getChildBuildsTest(array(5, 6, 999))) && p() && e('8:子版本1,9:子版本2'); // 步骤5:获取包含无效版本ID的版本构建列表 \ No newline at end of file diff --git a/module/testreport/test/model/yaml/build_getchildbuilds.yaml b/module/testreport/test/model/yaml/build_getchildbuilds.yaml new file mode 100644 index 0000000000..02739a0103 --- /dev/null +++ b/module/testreport/test/model/yaml/build_getchildbuilds.yaml @@ -0,0 +1,63 @@ +--- +title: 测试 getChildBuilds 方法的版本数据 +desc: 用于测试版本构建中子版本获取功能的测试数据 +author: Claude Code +version: 1.0 + +fields: +- field: id + note: 版本ID + range: 1-10 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: project + note: 项目ID + range: 1{2},2{2},3{6} + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: product + note: 产品ID + range: 1{10} + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 版本名称 + range: 版本1.0,版本1.1,版本1.2,版本2.0,版本2.1,版本2.2,版本3.0,子版本1,子版本2,子版本3 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: builds + note: 子版本ID列表(逗号分隔) + range: '[]{4},8,9,8{2},10,[]{2}' + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: bugs + note: 关联的Bug ID列表 + range: '1,2,3{2},[]{2},4,5{3}' + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: stories + note: 关联的需求ID列表 + range: '1{3},2{2},[]{2},3{3}' + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: deleted + note: 删除标识 + range: 0{9},1 + prefix: "" + postfix: "" + loop: 0 + format: "" \ No newline at end of file