From 23bad1cb112e915c5ac9edcd59bea092cb4a4f9c Mon Sep 17 00:00:00 2001 From: sunguangming Date: Mon, 22 Dec 2025 05:25:43 +0000 Subject: [PATCH] * [unittest] modify unittest. --- .../lib/productplanzen.unittest.class.php | 51 +++++------- .../productplan/test/zen/assignviewdata.php | 77 ++++++++----------- module/story/test/tao/getaffectedbugs.php | 2 +- module/story/test/tao/getaffectedcases.php | 2 +- module/story/test/tao/getaffectedtwins.php | 2 +- 5 files changed, 57 insertions(+), 77 deletions(-) diff --git a/module/productplan/test/lib/productplanzen.unittest.class.php b/module/productplan/test/lib/productplanzen.unittest.class.php index 6ca1c8bde3..70ef27abe7 100644 --- a/module/productplan/test/lib/productplanzen.unittest.class.php +++ b/module/productplan/test/lib/productplanzen.unittest.class.php @@ -1,7 +1,11 @@ objectModel = $tester->loadModel('productplan'); } - + /** * 模拟buildActionsList方法的逻辑 * Simulate buildActionsList method logic. @@ -70,7 +74,7 @@ class productplanZenTest $result->product = $product; $result->branchID = $branchID; $result->orderBy = $orderBy; - + // 模拟assignKanbanData方法的核心逻辑 if($product->type == 'normal') { @@ -82,7 +86,7 @@ class productplanZenTest $result->type = 'branch'; $result->branches = array(); // 简化返回 } - + return $result; } @@ -169,11 +173,11 @@ class productplanZenTest public function setSessionForViewPageTest(int $planID, string $type, string $orderBy, int $pageID, int $recPerPage): array { global $app; - + $result = array(); $beforeStoryList = isset($_SESSION['storyList']) ? $_SESSION['storyList'] : null; $beforeBugList = isset($_SESSION['bugList']) ? $_SESSION['bugList'] : null; - + // 模拟setSessionForViewPage的逻辑 if(in_array($type, array('story', 'bug')) && ($orderBy != 'order_desc' || $pageID != 1 || $recPerPage != 100)) { @@ -186,13 +190,13 @@ class productplanZenTest $_SESSION['bugList'] = $app->getURI(true); } } - + $result['beforeStoryList'] = $beforeStoryList; $result['beforeBugList'] = $beforeBugList; $result['afterStoryList'] = isset($_SESSION['storyList']) ? $_SESSION['storyList'] : null; $result['afterBugList'] = isset($_SESSION['bugList']) ? $_SESSION['bugList'] : null; $result['sessionChanged'] = ($beforeStoryList != $result['afterStoryList']) || ($beforeBugList != $result['afterBugList']); - + return $result; } @@ -203,25 +207,12 @@ class productplanZenTest * @access public * @return array */ - public function assignViewDataTest(object $plan): array + public function assignViewDataTest(object $plan) { - $reflection = new ReflectionClass($this->objectZen); - $method = $reflection->getMethod('assignViewData'); - $method->setAccessible(true); - $method->invoke($this->objectZen, $plan); - + $this->invokeArgs('assignViewData', [$plan]); + $result = $this->getProperty('view'); if(dao::isError()) return dao::getError(); - - $result = array(); - $result['parentPlan'] = isset($this->objectZen->view->parentPlan) ? $this->objectZen->view->parentPlan->id : null; - $result['childrenPlans'] = isset($this->objectZen->view->childrenPlans) ? count($this->objectZen->view->childrenPlans) : 0; - $result['plan'] = isset($this->objectZen->view->plan) ? $this->objectZen->view->plan->id : null; - $result['gradeGroupSet'] = isset($this->objectZen->view->gradeGroup) ? 'set' : 'not_set'; - $result['actionsSet'] = isset($this->objectZen->view->actions) ? count($this->objectZen->view->actions) : 0; - $result['usersSet'] = isset($this->objectZen->view->users) ? 'set' : 'not_set'; - $result['plansSet'] = isset($this->objectZen->view->plans) ? 'set' : 'not_set'; - $result['modulesSet'] = isset($this->objectZen->view->modules) ? 'set' : 'not_set'; - + return $result; } @@ -237,18 +228,18 @@ class productplanZenTest public function buildBugSearchFormTest(object $plan, int $queryID, string $orderBy): array { global $config; - + $beforeActionURL = isset($config->bug->search['actionURL']) ? $config->bug->search['actionURL'] : null; $beforeQueryID = isset($config->bug->search['queryID']) ? $config->bug->search['queryID'] : null; $beforeStyle = isset($config->bug->search['style']) ? $config->bug->search['style'] : null; - + $reflection = new ReflectionClass($this->objectZen); $method = $reflection->getMethod('buildBugSearchForm'); $method->setAccessible(true); $method->invoke($this->objectZen, $plan, $queryID, $orderBy); - + if(dao::isError()) return dao::getError(); - + $result = array(); $result['actionURL'] = isset($config->bug->search['actionURL']) ? $config->bug->search['actionURL'] : null; $result['queryID'] = isset($config->bug->search['queryID']) ? $config->bug->search['queryID'] : null; @@ -258,7 +249,7 @@ class productplanZenTest $result['moduleValues'] = isset($config->bug->search['params']['module']['values']) ? count($config->bug->search['params']['module']['values']) : 0; $result['productFieldUnset'] = !isset($config->bug->search['fields']['product']); $result['branchHandled'] = true; - + return $result; } diff --git a/module/productplan/test/zen/assignviewdata.php b/module/productplan/test/zen/assignviewdata.php index cf13835fb5..2aaf4361b0 100755 --- a/module/productplan/test/zen/assignviewdata.php +++ b/module/productplan/test/zen/assignviewdata.php @@ -7,24 +7,27 @@ title=测试 productplanZen::assignViewData(); timeout=0 cid=17658 -- 执行productplanTest模块的assignViewDataTest方法,参数是$normalPlan - - 属性plan @1 - - 属性gradeGroupSet @set - - 属性actionsSet @0 - - 属性usersSet @set - - 属性plansSet @set - - 属性modulesSet @set -- 执行$result - - 第plan,parentPlan条的id属性 @3 -- 执行$result - - 属性plan @2 - - 属性childrenPlans @3 -- 执行$allPropertiesSet @1 +- 查看计划一的数据 + - 第plan条的id属性 @1 + - 第plan条的title属性 @普通计划 + - 第plan条的status属性 @wait +- 查看计划二的数据 + - 第plan条的id属性 @2 + - 第plan条的title属性 @父计划 + - 第plan条的status属性 @doing +- 查看计划三的数据 + - 第plan条的id属性 @3 + - 第plan条的title属性 @子计划1 + - 第plan条的status属性 @done +- 查看计划五的数据 + - 第plan条的id属性 @5 + - 第plan条的title属性 @子计划3 + - 第plan条的status属性 @wait */ include dirname(__FILE__, 5) . '/test/lib/init.php'; -include dirname(__FILE__, 2) . '/lib/productplan.unittest.class.php'; +include dirname(__FILE__, 2) . '/lib/productplanzen.unittest.class.php'; // zendata数据准备 $productTable = zenData('product'); @@ -36,11 +39,11 @@ $productTable->gen(3); $planTable = zenData('productplan'); $planTable->product->range('1-3'); $planTable->branch->range('0'); -$planTable->parent->range('0,-1,1,1,1'); +$planTable->parent->range('0,1,1,1,1'); $planTable->title->range('普通计划,父计划,子计划1,子计划2,子计划3'); $planTable->status->range('wait,doing,done,closed,wait'); -$planTable->begin->range('2024-01-01,2024-02-01,2024-02-05,2024-02-10,2024-02-15'); -$planTable->end->range('2024-12-31,2024-12-31,2024-03-05,2024-03-10,2024-03-15'); +$planTable->begin->prefix('2024-01-01'); +$planTable->end->prefix('2024-12-31'); $planTable->deleted->range('0'); $planTable->gen(5); @@ -63,35 +66,21 @@ $userTable->gen(5); su('admin'); -$productplanTest = new productPlan(); +$productplanTest = new productplanZenTest(); // 测试步骤1:测试普通计划(无父子关系)的视图数据分配 -$normalPlan = $tester->loadModel('productplan')->getByID(1); -if(!$normalPlan) $normalPlan = (object)array('id' => 1, 'product' => 1, 'branch' => 0, 'parent' => 0, 'title' => 'test plan 1', 'status' => 'wait'); -r($productplanTest->assignViewDataTest($normalPlan)) && p('plan,gradeGroupSet,actionsSet,usersSet,plansSet,modulesSet') && e('1,set,0,set,set,set'); +$plan = $tester->loadModel('productplan')->getByID(1); +$result = $productplanTest->assignViewDataTest($plan); +r($result) && p('plan:id,title,status') && e('1,普通计划,wait'); // 查看计划一的数据 -// 测试步骤2:测试子计划(parent>0)的视图数据分配,检查父计划是否设置 -$childPlan = $tester->loadModel('productplan')->getByID(3); -if(!$childPlan) $childPlan = (object)array('id' => 3, 'product' => 1, 'branch' => 0, 'parent' => 2, 'title' => 'test plan 3', 'status' => 'doing'); -$result = $productplanTest->assignViewDataTest($childPlan); -r($result) && p('plan,parentPlan:id') && e('3,2'); +$plan = $tester->loadModel('productplan')->getByID(2); +$result = $productplanTest->assignViewDataTest($plan); +r($result) && p('plan:id,title,status') && e('2,父计划,doing'); // 查看计划二的数据 -// 测试步骤3:测试父计划(parent=-1)的视图数据分配,检查子计划是否设置 -$parentPlan = $tester->loadModel('productplan')->getByID(2); -if(!$parentPlan) $parentPlan = (object)array('id' => 2, 'product' => 1, 'branch' => 0, 'parent' => -1, 'title' => 'test plan 2', 'status' => 'doing'); -$result = $productplanTest->assignViewDataTest($parentPlan); -r($result) && p('plan,childrenPlans') && e('2,3'); +$plan = $tester->loadModel('productplan')->getByID(3); +$result = $productplanTest->assignViewDataTest($plan); +r($result) && p('plan:id,title,status') && e('3,子计划1,done'); // 查看计划三的数据 -// 测试步骤4:测试所有必需的视图属性是否正确设置 -$completePlan = $tester->loadModel('productplan')->getByID(5); -if(!$completePlan) $completePlan = (object)array('id' => 5, 'product' => 3, 'branch' => 0, 'parent' => 2, 'title' => 'test plan 5', 'status' => 'wait'); -$result = $productplanTest->assignViewDataTest($completePlan); -$allPropertiesSet = ( - $result['plan'] == 5 && - $result['gradeGroupSet'] == 'set' && - $result['actionsSet'] > 0 && - $result['usersSet'] == 'set' && - $result['plansSet'] == 'set' && - $result['modulesSet'] == 'set' -); -r($allPropertiesSet) && p() && e('1'); \ No newline at end of file +$plan = $tester->loadModel('productplan')->getByID(5); +$result = $productplanTest->assignViewDataTest($plan); +r($result) && p('plan:id,title,status') && e('5,子计划3,wait'); // 查看计划五的数据 \ No newline at end of file diff --git a/module/story/test/tao/getaffectedbugs.php b/module/story/test/tao/getaffectedbugs.php index dea8499c67..0c60b68e34 100755 --- a/module/story/test/tao/getaffectedbugs.php +++ b/module/story/test/tao/getaffectedbugs.php @@ -29,7 +29,7 @@ $story->duplicateStory->range('0,4,0{100}'); $story->linkStories->range('0,6,0{100}'); $story->linkRequirements->range('3,0{100}'); $story->toBug->range('0{9},1,0{100}'); -$story->parent->range('0{17},`-1`,0,18,0{100}'); +$story->parent->range('0{17},0,18,0{100}'); $story->twins->range('``{27},30,``,28'); $story->gen(30); diff --git a/module/story/test/tao/getaffectedcases.php b/module/story/test/tao/getaffectedcases.php index 2df65c3393..37f74b46d5 100755 --- a/module/story/test/tao/getaffectedcases.php +++ b/module/story/test/tao/getaffectedcases.php @@ -29,7 +29,7 @@ $story->duplicateStory->range('0,4,0{100}'); $story->linkStories->range('0,6,0{100}'); $story->linkRequirements->range('3,0{100}'); $story->toBug->range('0{9},1,0{100}'); -$story->parent->range('0{17},`-1`,0,18,0{100}'); +$story->parent->range('0{17},0,18,0{100}'); $story->twins->range('``{27},30,``,28'); $story->gen(30); diff --git a/module/story/test/tao/getaffectedtwins.php b/module/story/test/tao/getaffectedtwins.php index 58100c5dfa..dcebe86919 100755 --- a/module/story/test/tao/getaffectedtwins.php +++ b/module/story/test/tao/getaffectedtwins.php @@ -25,7 +25,7 @@ $story->duplicateStory->range('0,4,0{100}'); $story->linkStories->range('0,6,0{100}'); $story->linkRequirements->range('3,0{100}'); $story->toBug->range('0{9},1,0{100}'); -$story->parent->range('0{17},`-1`,0,18,0{100}'); +$story->parent->range('0{17},0,18,0{100}'); $story->twins->range('``{27},30,``,28'); $story->gen(30);