* [misc] Enhance unit tests for storyModel::getDataOfStoriesPerModule() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:16:38 +08:00
co-authored by Claude
parent 334d7c29b3
commit 6f336c0411
2 changed files with 72 additions and 17 deletions
@@ -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.
*
@@ -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下的数据
// 设置查询条件测试
$_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'); // 测试模块名称数据结构