+ [misc] Add unit tests for kanbanTao::refreshStoryCards() method

- Modified kanban.unittest.class.php to call the actual tao method via reflection
- Updated tao.class.php with refreshStoryCardsTest method
- Created refreshstorycards.php test script with 10 test cases covering various story stages

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-11-07 10:30:55 +08:00
co-authored by Claude
parent 43b897f56c
commit 07ed5bc1e5
3 changed files with 98 additions and 54 deletions
@@ -2326,64 +2326,16 @@ class kanbanTest
*/
public function refreshStoryCardsTest($cardPairs, $executionID, $otherCardList)
{
// 创建模拟的故事数据来避免数据库依赖
$mockStories = array();
if($executionID == 1)
{
$mockStories = array(
1 => (object)array('id' => 1, 'stage' => 'projected', 'title' => '需求1'),
2 => (object)array('id' => 2, 'stage' => 'projected', 'title' => '需求2'),
3 => (object)array('id' => 3, 'stage' => 'designing', 'title' => '需求3'),
4 => (object)array('id' => 4, 'stage' => 'designed', 'title' => '需求4'),
5 => (object)array('id' => 5, 'stage' => 'developing', 'title' => '需求5'),
);
}
// 使用反射来调用protected方法
$reflection = new ReflectionClass($this->objectTao);
$method = $reflection->getMethod('refreshStoryCards');
$method->setAccessible(true);
// 模拟storyColumnStageList配置
$storyColumnStageList = array(
'backlog' => 'projected',
'ready' => 'projected',
'designing' => 'designing',
'designed' => 'designed',
'developing' => 'developing',
'developed' => 'developed',
'testing' => 'testing',
'tested' => 'tested',
'verified' => 'verified',
'rejected' => 'rejected',
'pending' => 'pending',
'released' => 'released',
'closed' => 'closed'
);
// 模拟refreshStoryCards方法的核心逻辑
foreach($mockStories as $storyID => $story)
{
foreach($storyColumnStageList as $colType => $stage)
{
if(!isset($cardPairs[$colType])) continue;
if($story->stage != $stage and strpos($cardPairs[$colType], ",$storyID,") !== false)
{
$cardPairs[$colType] = str_replace(",$storyID,", ',', $cardPairs[$colType]);
}
if(strpos(',ready,backlog,design,develop,test,', $colType) !== false) continue;
if($story->stage == $stage and strpos($cardPairs[$colType], ",$storyID,") === false)
{
$cardPairs[$colType] = empty($cardPairs[$colType]) ? ",$storyID," : ",$storyID" . $cardPairs[$colType];
}
}
if(strpos('wait,projected', $story->stage) !== false and strpos($cardPairs['ready'], ",$storyID,") === false and strpos($cardPairs['backlog'], ",$storyID,") === false)
{
$cardPairs['backlog'] = empty($cardPairs['backlog']) ? ",$storyID," : ",$storyID" . $cardPairs['backlog'];
}
}
$result = $method->invoke($this->objectTao, $cardPairs, $executionID, $otherCardList);
if(dao::isError()) return dao::getError();
return $cardPairs;
return $result;
}
/**
+16
View File
@@ -40,4 +40,20 @@ class kanbanTaoTest extends baseTest
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test refreshStoryCards method.
*
* @param array $cardPairs 卡片对集合
* @param int $executionID 执行ID
* @param string $otherCardList 其他卡片列表
* @access public
* @return array
*/
public function refreshStoryCardsTest($cardPairs = array(), $executionID = 0, $otherCardList = '')
{
$result = $this->invokeArgs('refreshStoryCards', [$cardPairs, $executionID, $otherCardList]);
if(dao::isError()) return dao::getError();
return $result;
}
}
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env php
<?php
/**
title=测试 kanbanTao::refreshStoryCards();
timeout=0
cid=0
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs0, 999, '' @10
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs1, 101, ''
- 属性backlog @
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs2, 101, '' 属性designing @~~
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs3, 101, ''
- 属性designed @
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs4, 101, '' 属性developing @~~
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs5, 101, ''
- 属性developed @
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs6, 101, '' 属性testing @~~
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs7, 101, ''
- 属性tested @
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs8, 101, '' 属性verified @~~
- 执行kanbanTest模块的refreshStoryCardsTest方法,参数是$cardPairs9, 101, ''
- 属性closed @
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/kanban.unittest.class.php';
$project = zenData('project');
$project->id->range('101,999');
$project->name->range('项目101,项目999');
$project->type->range('sprint');
$project->status->range('doing');
$project->gen(2);
$story = zenData('story');
$story->id->range('1-10');
$story->product->range('1');
$story->status->range('active');
$story->stage->range('projected{2},designing,designed,developing,developed,testing,tested,verified,closed');
$story->title->range('需求1,需求2,需求3,需求4,需求5,需求6,需求7,需求8,需求9,需求10');
$story->gen(10);
$projectStory = zenData('projectstory');
$projectStory->project->range('101');
$projectStory->product->range('1');
$projectStory->story->range('1-10');
$projectStory->gen(10);
su('admin');
$kanbanTest = new kanbanTest();
$cardPairs0 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs1 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs2 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs3 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs4 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs5 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs6 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs7 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs8 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
$cardPairs9 = array('backlog' => '', 'ready' => '', 'designing' => '', 'designed' => '', 'developing' => '', 'developed' => '', 'testing' => '', 'tested' => '', 'verified' => '', 'closed' => '');
r(count($kanbanTest->refreshStoryCardsTest($cardPairs0, 999, ''))) && p() && e('10');
r($kanbanTest->refreshStoryCardsTest($cardPairs1, 101, '')) && p('backlog') && e(',2,');
r($kanbanTest->refreshStoryCardsTest($cardPairs2, 101, '')) && p('designing') && e('~~');
r($kanbanTest->refreshStoryCardsTest($cardPairs3, 101, '')) && p('designed') && e(',4,');
r($kanbanTest->refreshStoryCardsTest($cardPairs4, 101, '')) && p('developing') && e('~~');
r($kanbanTest->refreshStoryCardsTest($cardPairs5, 101, '')) && p('developed') && e(',6,');
r($kanbanTest->refreshStoryCardsTest($cardPairs6, 101, '')) && p('testing') && e('~~');
r($kanbanTest->refreshStoryCardsTest($cardPairs7, 101, '')) && p('tested') && e(',8,');
r($kanbanTest->refreshStoryCardsTest($cardPairs8, 101, '')) && p('verified') && e('~~');
r($kanbanTest->refreshStoryCardsTest($cardPairs9, 101, '')) && p('closed') && e(',10,');