From 07ed5bc1e56dbb2fdd9cd30af8147b25bba101e5 Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 6 Nov 2025 14:45:33 +0800 Subject: [PATCH] + [misc] Add unit tests for kanbanTao::refreshStoryCards() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../kanban/test/lib/kanban.unittest.class.php | 60 ++------------- module/kanban/test/lib/tao.class.php | 16 ++++ module/kanban/test/tao/refreshstorycards.php | 76 +++++++++++++++++++ 3 files changed, 98 insertions(+), 54 deletions(-) create mode 100755 module/kanban/test/tao/refreshstorycards.php diff --git a/module/kanban/test/lib/kanban.unittest.class.php b/module/kanban/test/lib/kanban.unittest.class.php index b2f323c3f6..97a1029822 100755 --- a/module/kanban/test/lib/kanban.unittest.class.php +++ b/module/kanban/test/lib/kanban.unittest.class.php @@ -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; } /** diff --git a/module/kanban/test/lib/tao.class.php b/module/kanban/test/lib/tao.class.php index 7c2c3518cc..59407d4b13 100644 --- a/module/kanban/test/lib/tao.class.php +++ b/module/kanban/test/lib/tao.class.php @@ -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; + } } diff --git a/module/kanban/test/tao/refreshstorycards.php b/module/kanban/test/tao/refreshstorycards.php new file mode 100755 index 0000000000..718a7d8395 --- /dev/null +++ b/module/kanban/test/tao/refreshstorycards.php @@ -0,0 +1,76 @@ +#!/usr/bin/env php +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,'); \ No newline at end of file