From 152ec6b49c81fe34564dc38c1bf6b4012aea7ea8 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Sun, 29 Jan 2023 13:58:40 +0800 Subject: [PATCH] * Add test case and remove unused function. --- module/execution/control.php | 2 - module/execution/model.php | 38 ----------------- test/class/execution.class.php | 42 +++++++++++++++++-- test/model/execution/buildcfddata.php | 59 +++++++++++++++++++++++++++ test/model/execution/computecfd.php | 2 +- test/model/execution/getcfddata.php | 57 ++++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 44 deletions(-) create mode 100644 test/model/execution/buildcfddata.php create mode 100644 test/model/execution/getcfddata.php diff --git a/module/execution/control.php b/module/execution/control.php index 92a51ab52a..544207a2b5 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -1531,8 +1531,6 @@ class execution extends control } $dateList = date::getDateList($begin, $end, 'Y-m-d', $withWeekend == 'false'? 'noweekend' : ''); - //list($cycleTimeAvg, $throughput) = $this->execution->getCFDStatistics($executionID, $dateList, $type); - $chartData = $this->execution->buildCFDData($executionID, $dateList, $type); if(isset($chartData['line'])) $chartData['line'] = array_reverse($chartData['line']); diff --git a/module/execution/model.php b/module/execution/model.php index c161bbccf7..4e7f718631 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -3763,44 +3763,6 @@ class executionModel extends model return $data; } - /** - * Get CFD statistics. - * - * @param int $executionID - * @param array $dateList - * @param string $type - * @access public - * @return void - */ - public function getCFDStatistics($executionID, $dateList, $type) - { - $kanbanData = $this->loadModel('kanban')->getRDKanban($executionID, $type); - $kanbanData = array_shift($kanbanData); - - $cycleTime = array(); - foreach($kanbanData->groups as $group) - { - foreach($group->lanes as $lane) - { - if(!isset($lane->items['closed'])) continue; - - foreach($lane->items['closed'] as $item) - { - $diffTime = $type == 'story' ? strtotime($item['lastEditedDate']) - strtotime($item['openedDate']) : strtotime($item['closedDate']) - strtotime($item['openedDate']); - $day = round($diffTime / (3600 * 24), 1); - if($day > 0) $cycleTime[$item['id']] = $day; - } - } - } - - $itemCount = count($cycleTime); - if(!$itemCount) return array('', ''); - $cycleTimeAvg = round(array_sum($cycleTime) / $itemCount, 1); - $throughput = round(($itemCount * 7) / $cycleTimeAvg, 1) . "{$this->lang->execution->kanbanCardsUnit}/" . $this->lang->execution->week; - - return array($cycleTimeAvg, $throughput); - } - /** * Get taskes by search. * diff --git a/test/class/execution.class.php b/test/class/execution.class.php index dae6fb05bd..0ca98be129 100644 --- a/test/class/execution.class.php +++ b/test/class/execution.class.php @@ -2708,7 +2708,7 @@ class executionTest * @param int $executionID * @param int $queryID * @access public - * @return void + * @return int */ public function buildTaskSearchFormTest($executionID, $queryID) { @@ -2723,7 +2723,7 @@ class executionTest * @param int $productID * @param int $queryID * @access public - * @return void + * @return int */ public function buildBugSearchFormTest($productID, $queryID) { @@ -2742,7 +2742,7 @@ class executionTest * @param int $executionID * @param int $queryID * @access public - * @return void + * @return int */ public function buildStorySearchFormTest($executionID, $queryID) { @@ -2756,4 +2756,40 @@ class executionTest return $_SESSION['executionStorysearchParams']['queryID']; } + + /** + * Test get CFD data. + * + * @param int $executionID + * @access public + * @return array + */ + public function getCFDDataTest($executionID = 0) + { + $begin = strtotime('2022-01-12'); + $end = strtotime('2022-02-12'); + + $dateList = array(); + for($date = $begin; $date <= $end; $date += 24 * 3600) $dateList[] = date('Y-m-d', $date); + + return $this->executionModel->getCFDData($executionID, $dateList); + } + + /** + * Test build CFD data. + * + * @param int $executionID + * @access public + * @return array + */ + public function buildCFDDataTest($executionID = 0) + { + $begin = strtotime('2022-01-12'); + $end = strtotime('2022-02-12'); + + $dateList = array(); + for($date = $begin; $date <= $end; $date += 24 * 3600) $dateList[] = date('Y-m-d', $date); + + return $this->executionModel->buildCFDData($executionID, $dateList, 'task'); + } } diff --git a/test/model/execution/buildcfddata.php b/test/model/execution/buildcfddata.php new file mode 100644 index 0000000000..f7ec33ff79 --- /dev/null +++ b/test/model/execution/buildcfddata.php @@ -0,0 +1,59 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-5'); +$execution->name->range('项目集1,项目1,看板1,看板2,看板3'); +$execution->type->range('program,project,,kanban{3}'); +$execution->parent->range('0,1,2{3}'); +$execution->status->range('wait{3},closed,doing'); +$execution->openedBy->range('admin,user1'); +$execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->gen(5); + +$kanbanCell = zdTable('kanbancell'); +$kanbanCell->id->range('1-9'); +$kanbanCell->kanban->range('3{3},4{3},5{3}'); +$kanbanCell->lane->range('1-9'); +$kanbanCell->column->range('1-9'); +$kanbanCell->type->range('task,bug,story'); +$kanbanCell->cards->range('`,1,2,3,`{3},`,4,5,`{3},6{3}'); +$kanbanCell->gen(9); + +$kanbanColumn = zdTable('kanbancolumn'); +$kanbanColumn->id->range('1-9'); +$kanbanColumn->name->range('1-9')->prefix('看板列'); +$kanbanColumn->type->range('1-9')->prefix('column'); +$kanbanColumn->gen(9); + +$CFD = zdTable('cfd'); +$CFD->id->range('1-5'); +$CFD->execution->range('3'); +$CFD->count->range('1'); +$CFD->type->range('task,bug,story'); +$CFD->date->range('20220122 000000:0')->type('timestamp')->format('YY/MM/DD'); +$CFD->name->range('1-5')->prefix('看板列'); +$CFD->gen(5); + +/** + +title=测试executionModel->buildCFDData(); +cid=1 +pid=1 + +不存在执行的累计流图信息 >> 0 +存在的执行的累计流图信息 >> 2 + +*/ + +$executionTester = new executionTest(); + +r(count($executionTester->buildCFDDataTest())) && p() && e('0'); // 不存在执行的累计流图信息 + +$CFDData = $executionTester->buildCFDDataTest(3); +r(count($CFDData['line'])) && p() && e('2'); // 存在的执行的累计流图信息 diff --git a/test/model/execution/computecfd.php b/test/model/execution/computecfd.php index 5879c8e934..ea112fcc48 100644 --- a/test/model/execution/computecfd.php +++ b/test/model/execution/computecfd.php @@ -42,7 +42,7 @@ cid=1 pid=1 获取所有看板执行的累计卡片个数 >> 6 -获取看板1的累计流图信息 >> 3,task +获取看板1的累计流图信息 >> 3,task */ diff --git a/test/model/execution/getcfddata.php b/test/model/execution/getcfddata.php new file mode 100644 index 0000000000..f14659def9 --- /dev/null +++ b/test/model/execution/getcfddata.php @@ -0,0 +1,57 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-5'); +$execution->name->range('项目集1,项目1,看板1,看板2,看板3'); +$execution->type->range('program,project,,kanban{3}'); +$execution->parent->range('0,1,2{3}'); +$execution->status->range('wait{3},closed,doing'); +$execution->openedBy->range('admin,user1'); +$execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->gen(5); + +$kanbanCell = zdTable('kanbancell'); +$kanbanCell->id->range('1-9'); +$kanbanCell->kanban->range('3{3},4{3},5{3}'); +$kanbanCell->lane->range('1-9'); +$kanbanCell->column->range('1-9'); +$kanbanCell->type->range('task,bug,story'); +$kanbanCell->cards->range('`,1,2,3,`{3},`,4,5,`{3},6{3}'); +$kanbanCell->gen(9); + +$kanbanColumn = zdTable('kanbancolumn'); +$kanbanColumn->id->range('1-9'); +$kanbanColumn->name->range('1-9')->prefix('看板列'); +$kanbanColumn->type->range('1-9')->prefix('column'); +$kanbanColumn->gen(9); + +$CFD = zdTable('cfd'); +$CFD->id->range('1-5'); +$CFD->execution->range('3'); +$CFD->count->range('1'); +$CFD->type->range('task,bug,story'); +$CFD->date->range('20220122 000000:0')->type('timestamp')->format('YY/MM/DD'); +$CFD->name->range('1-5')->prefix('看板列'); +$CFD->gen(5); + +/** + +title=测试executionModel->getCFDData(); +cid=1 +pid=1 + +不存在执行的累计流图信息 >> 0 +存在的执行的累计流图信息 >> 看板列3 + +*/ + +$executionTester = new executionTest(); + +r(count($executionTester->getCFDDataTest())) && p() && e('0'); // 不存在执行的累计流图信息 +r(current($executionTester->getCFDDataTest(3))) && p('2022-01-22:name') && e('看板列3'); // 存在的执行的累计流图信息