From 6f336c04111d3c62201faf18793bca514d74cd5e Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 23 Sep 2025 18:43:37 +0800 Subject: [PATCH] * [misc] Enhance unit tests for storyModel::getDataOfStoriesPerModule() 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 --- .../story/test/lib/story.unittest.class.php | 15 ++++ .../test/model/getdataofstoriespermodule.php | 74 ++++++++++++++----- 2 files changed, 72 insertions(+), 17 deletions(-) diff --git a/module/story/test/lib/story.unittest.class.php b/module/story/test/lib/story.unittest.class.php index 7688ae5954..510aa23729 100755 --- a/module/story/test/lib/story.unittest.class.php +++ b/module/story/test/lib/story.unittest.class.php @@ -52,6 +52,21 @@ class storyTest return $result; } + /** + * Test getDataOfStoriesPerModule method. + * + * @param string $storyType + * @access public + * @return array + */ + public function getDataOfStoriesPerModuleTest($storyType = 'story') + { + $result = $this->objectModel->getDataOfStoriesPerModule($storyType); + if(dao::isError()) return dao::getError(); + + return $result; + } + /** * Test getDataOfStoriesPerEstimate method. * diff --git a/module/story/test/model/getdataofstoriespermodule.php b/module/story/test/model/getdataofstoriespermodule.php index 0a2e5a7f56..b51e0ee593 100755 --- a/module/story/test/model/getdataofstoriespermodule.php +++ b/module/story/test/model/getdataofstoriespermodule.php @@ -3,39 +3,79 @@ /** -title=测试 storyModel->getDataOfStoriesPerModule(); +title=测试 storyModel::getDataOfStoriesPerModule(); timeout=0 cid=0 -- 按照模块分组,获取分组后的需求数量 @6 -- 按照模块分组,获取各个模块下的需求数量,查看模块2150下的数据 - - 第1条的name属性 @/这是一个模块1 - - 第1条的value属性 @4 - - 第1条的product属性 @1 +- 测试默认story类型的模块统计数据 @3 +- 测试带查询条件的模块统计第1条的value属性 @6 +- 测试requirement类型的模块统计 @3 +- 测试空数据的处理 @0 +- 测试模块名称数据结构第1条的name属性 @/这是一个模块1 */ + include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/lib/story.unittest.class.php'; +// 准备story测试数据 $story = zenData('story'); -$story->module->range('1-6'); +$story->id->range('1-20'); $story->product->range('1'); +$story->branch->range('0{15},1{5}'); +$story->module->range('1{6},2{8},3{6}'); +$story->type->range('story{15},requirement{5}'); +$story->status->range('active'); +$story->deleted->range('0'); $story->gen(20); + +// 准备module测试数据 $module = zenData('module'); -$module->root->range(1); -$module->gen(20); +$module->id->range('1-5'); +$module->root->range('1'); +$module->name->range('这是一个模块1,这是一个模块2,这是一个模块3,这是一个模块4,这是一个模块5'); +$module->type->range('story'); +$module->deleted->range('0'); +$module->gen(5); + +// 准备branch测试数据 +$branch = zenData('branch'); +$branch->id->range('1-2'); +$branch->product->range('1'); +$branch->name->range('主分支,开发分支'); +$branch->status->range('active'); +$branch->deleted->range('0'); +$branch->gen(2); + +// 准备product测试数据 zenData('product')->gen(1); su('admin'); -global $tester; -$tester->loadModel('story'); -$tester->loadModel('report'); +$storyTest = new storyTest(); -$_SESSION['storyOnlyCondition'] = true; -$_SESSION['storyQueryCondition'] = "`id` < 20"; +// 清除session条件,测试无条件情况 +unset($_SESSION['storyOnlyCondition']); +unset($_SESSION['storyQueryCondition']); -$data = $tester->story->getDataOfStoriesPerModule(); +r(count($storyTest->getDataOfStoriesPerModuleTest('story'))) && p() && e('3'); // 测试默认story类型的模块统计数据 -r(count($data)) && p() && e('6'); // 按照模块分组,获取分组后的需求数量 -r($data) && p('1:name,value,product') && e('/这是一个模块1,4,1'); // 按照模块分组,获取各个模块下的需求数量,查看模块2150下的数据 \ No newline at end of file +// 设置查询条件测试 +$_SESSION['storyOnlyCondition'] = true; +$_SESSION['storyQueryCondition'] = "`id` <= 10"; + +$result = $storyTest->getDataOfStoriesPerModuleTest('story'); +r($result) && p('1:value') && e('6'); // 测试带查询条件的模块统计 + +// 测试requirement类型 +r(count($storyTest->getDataOfStoriesPerModuleTest('requirement'))) && p() && e('3'); // 测试requirement类型的模块统计 + +// 测试空数据情况 +$_SESSION['storyQueryCondition'] = "`id` > 30"; +r(count($storyTest->getDataOfStoriesPerModuleTest('story'))) && p() && e('0'); // 测试空数据的处理 + +// 重置条件,测试模块名称拼接 +unset($_SESSION['storyOnlyCondition']); +unset($_SESSION['storyQueryCondition']); +$finalResult = $storyTest->getDataOfStoriesPerModuleTest('story'); +r($finalResult) && p('1:name') && e('/这是一个模块1'); // 测试模块名称数据结构 \ No newline at end of file