From 340ae715e6de0958dd078be519841db83a2b3c3b Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Fri, 24 Feb 2023 08:27:55 +0000 Subject: [PATCH] * Add execution module unit testcase. --- module/execution/model.php | 25 ++-- test/class/execution.class.php | 133 ++++++++++++++++++ test/model/execution/batchchangestatus.php | 33 +++++ .../execution/buildexecutionbystatus.php | 26 ++++ test/model/execution/changestatus2doing.php | 37 +++++ .../execution/changestatus2inactived.php | 37 +++++ test/model/execution/changestatus2wait.php | 37 +++++ 7 files changed, 319 insertions(+), 9 deletions(-) create mode 100755 test/model/execution/batchchangestatus.php create mode 100755 test/model/execution/buildexecutionbystatus.php create mode 100755 test/model/execution/changestatus2doing.php create mode 100755 test/model/execution/changestatus2inactived.php create mode 100755 test/model/execution/changestatus2wait.php diff --git a/module/execution/model.php b/module/execution/model.php index 928965ab8d..3b5386d02f 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1019,7 +1019,6 @@ class executionModel extends model public function batchChangeStatus($executionIdList, $status) { $this->loadModel('programplan'); - $this->loadModel('action'); /* Sort the IDs, the child stage comes first, and the parent stage follows. */ $executionIdList = $this->dao->select('id')->from(TABLE_EXECUTION)->where('id')->in($executionIdList)->orderBy('grade_desc')->fetchPairs(); @@ -1068,6 +1067,9 @@ class executionModel extends model */ public function changeStatus2Wait($executionID, $selfAndChildren, $siblingStages) { + $this->loadModel('programplan'); + $this->loadModel('action'); + $parentID = $selfAndChildren[$executionID]->parent; /* There are already tasks consuming work in this phase or its sub-phases already have start times. */ @@ -1075,7 +1077,7 @@ class executionModel extends model $hasConsumedTasks = $this->dao->select('count(consumed) as count')->from(TABLE_TASK)->where('deleted')->eq(0)->andWhere('execution')->in(array_keys($selfAndChildren))->andWhere('consumed')->gt(0)->fetch('count'); if($hasStartedChildren or $hasConsumedTasks) return "'{$selfAndChildren[$executionID]->name}',"; - $newExecution = $this->buildExecutionBySstatus('wait'); + $newExecution = $this->buildExecutionByStatus('wait'); $this->dao->update(TABLE_EXECUTION)->data($newExecution)->where('id')->eq($executionID)->exec(); if(!dao::isError()) @@ -1112,7 +1114,7 @@ class executionModel extends model $parentStatus = (!helper::isZeroDate($parent->realBegan) or $parentHasConsumedTasks) ? 'doing' : 'wait'; if($parent->status == $parentStatus) return ''; - $newParent = $this->buildExecutionBySstatus($parentStatus); + $newParent = $this->buildExecutionByStatus($parentStatus); $this->dao->update(TABLE_EXECUTION)->data($newParent)->where('id')->eq($parentID)->exec(); if(!dao::isError()) @@ -1139,10 +1141,13 @@ class executionModel extends model */ public function changeStatus2Doing($executionID, $selfAndChildren) { + $this->loadModel('programplan'); + $this->loadModel('action'); + $type = $selfAndChildren[$executionID]->type; $parentID = $selfAndChildren[$executionID]->parent; - $newExecution = $this->buildExecutionBySstatus('doing'); + $newExecution = $this->buildExecutionByStatus('doing'); $this->dao->update(TABLE_EXECUTION)->data($newExecution)->where('id')->eq($executionID)->exec(); if(!dao::isError()) { @@ -1159,7 +1164,7 @@ class executionModel extends model $parent = $this->dao->select('*')->from(TABLE_EXECUTION)->where('id')->eq($parentID)->fetch(); if($parent->status == 'doing') return ''; - $newParent = $this->buildExecutionBySstatus('doing'); + $newParent = $this->buildExecutionByStatus('doing'); $this->dao->update(TABLE_EXECUTION)->data($newParent)->where('id')->eq($parentID)->exec(); if(!dao::isError()) @@ -1186,6 +1191,9 @@ class executionModel extends model */ public function changeStatus2Inactived($executionID, $status, $selfAndChildren, $siblingStages) { + $this->loadModel('programplan'); + $this->loadModel('action'); + $type = $selfAndChildren[$executionID]->type; $parentID = $selfAndChildren[$executionID]->parent; $checkedStatus = $status == 'suspended' ? 'wait,doing' : 'wait,doing,suspended'; @@ -1203,7 +1211,7 @@ class executionModel extends model } } - $newExecution = $this->buildExecutionBySstatus($status); + $newExecution = $this->buildExecutionByStatus($status); $this->dao->update(TABLE_EXECUTION)->data($newExecution)->where('id')->eq($executionID)->exec(); if(!dao::isError()) { @@ -1235,7 +1243,7 @@ class executionModel extends model $parent = $this->dao->select('*')->from(TABLE_EXECUTION)->where('id')->eq($parentID)->fetch(); if($parent->status == $status) return ''; - $newParent = $this->buildExecutionBySstatus($status); + $newParent = $this->buildExecutionByStatus($status); $this->dao->update(TABLE_EXECUTION)->data($newParent)->where('id')->eq($parentID)->exec(); if(!dao::isError()) @@ -1248,7 +1256,6 @@ class executionModel extends model } } } - } /** @@ -5915,7 +5922,7 @@ class executionModel extends model * @access public * @return object */ - public function buildExecutionBySstatus($status) + public function buildExecutionByStatus($status) { $execution = new stdclass(); $execution->status = $status; diff --git a/test/class/execution.class.php b/test/class/execution.class.php index 2c93e4b48d..5c79afdd64 100644 --- a/test/class/execution.class.php +++ b/test/class/execution.class.php @@ -321,6 +321,127 @@ class executionTest } } + /** + * function batchChangeStatus test by execution + * + * @param array $executionIdList + * @param string $status + * @access public + * @return array + */ + public function batchChangeStatusObject($executionIdList = '', $status = '') + { + $result = $this->executionModel->batchChangeStatus($executionIdList, $status); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return empty($result) ? 'empty' : $result; + } + } + + /** + * function changeStatus2Wait test by execution + * + * @param int $executionID + * @access public + * @return string|array + */ + public function changeStatus2WaitObject($executionID) + { + global $tester; + + $tester->loadModel('programplan'); + $selfAndChildrenList = $tester->programplan->getSelfAndChildrenList($executionID); + $siblingStages = $tester->programplan->getSiblings($executionID); + + $selfAndChildren = $selfAndChildrenList[$executionID]; + $execution = $selfAndChildren[$executionID]; + $executionType = $execution->type; + + $siblingList = array(); + if($executionType == 'stage') $siblingList = $siblingStages[$executionID]; + + $result = $this->executionModel->changeStatus2Wait($executionID, $selfAndChildren, $siblingList); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return (empty($result) or $result == "'',") ? 'empty' : $result; + } + } + + /** + * function changeStatus2Doing test by execution + * + * @param int $executionID + * @access public + * @return bool|array + */ + public function changeStatus2DoingObject($executionID) + { + global $tester; + + $tester->loadModel('programplan'); + $selfAndChildrenList = $tester->programplan->getSelfAndChildrenList($executionID); + + $selfAndChildren = $selfAndChildrenList[$executionID]; + $execution = $selfAndChildren[$executionID]; + $executionType = $execution->type; + + $this->executionModel->changeStatus2Doing($executionID, $selfAndChildren); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return true; + } + } + + /** + * function changeStatus2Inactived test by execution + * + * @param int $executionID + * @param string $status suspended|closed + * @access public + * @return bool|array + */ + public function changeStatus2InactivedObject($executionID, $status) + { + global $tester; + + $tester->loadModel('programplan'); + $selfAndChildrenList = $tester->programplan->getSelfAndChildrenList($executionID); + $siblingStages = $tester->programplan->getSiblings($executionID); + + $selfAndChildren = $selfAndChildrenList[$executionID]; + $execution = $selfAndChildren[$executionID]; + $executionType = $execution->type; + + $siblingList = array(); + if($executionType == 'stage') $siblingList = $siblingStages[$executionID]; + + $result = $this->executionModel->changeStatus2Inactived($executionID, $status, $selfAndChildren, $siblingList); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return (empty($result) or $result == "'',") ? 'empty' : $result; + } + } + /** * function start test by execution * @@ -2807,6 +2928,18 @@ class executionTest ->orderBy('date DESC, id asc')->fetchGroup('name', 'date'); } + /** + * Test build execution object by status. + * + * @param string $status + * @access public + * @return object + */ + public function buildExecutionByStatusTest($status) + { + return $this->executionModel->buildExecutionByStatus($status); + } + /** * Reset execution sorts. * diff --git a/test/model/execution/batchchangestatus.php b/test/model/execution/batchchangestatus.php new file mode 100755 index 0000000000..66d5af9a10 --- /dev/null +++ b/test/model/execution/batchchangestatus.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-5'); +$execution->name->range('瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b'); +$execution->type->range('project,stage{4}'); +$execution->project->range('0,1{4}'); +$execution->parent->range('0,1,2,3,1'); +$execution->path->range("`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`"); +$execution->status->range('wait{5}'); +$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); + +/** + +title=测试executionModel->batchChangeStatus(); +cid=1 +pid=1 + +*/ + +$execution = new executionTest(); +r($execution->batchChangeStatusObject(array(4), 'doing')) && p('') && e('empty'); // 测试批量修改执行状态为进行中 +r($execution->batchChangeStatusObject(array(2), 'wait')) && p('') && e('empty'); // 测试批量修改执行状态为未开始 +r($execution->batchChangeStatusObject(array(5), 'suspended')) && p('') && e('empty'); // 测试批量修改执行状态为已挂起 +r($execution->batchChangeStatusObject(array(3), 'closed')) && p('') && e('阶段a子1'); // 测试批量修改执行状态为已关闭 diff --git a/test/model/execution/buildexecutionbystatus.php b/test/model/execution/buildexecutionbystatus.php new file mode 100755 index 0000000000..a7fb400b3b --- /dev/null +++ b/test/model/execution/buildexecutionbystatus.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +/** + +title=测试executionModel->buildExecutionByStatus(); +cid=1 +pid=1 + +测试传入未开始状态,返回对象的实际开始时间 >> 0 +测试传入进行中状态,返回对象的状态 >> doing +测试传入已挂起状态,返回对象的状态 >> suspended +测试传入已关闭状态,返回对象的由谁关闭 >> admin + +*/ + +$execution = new executionTest(); +$waitObject = $execution->buildExecutionByStatusTest('wait'); +r($waitObject->realBegan) && p('') && e('0'); // 测试传入未开始状态,返回对象的实际开始时间 +r($execution->buildExecutionByStatusTest('doing')) && p('status') && e("doing"); // 测试传入进行中状态,返回对象的状态 +r($execution->buildExecutionByStatusTest('suspended')) && p('status') && e('suspended'); // 测试传入已挂起状态,返回对象的状态 +r($execution->buildExecutionByStatusTest('closed')) && p('closedBy') && e('admin'); // 测试传入已关闭状态,返回对象的由谁关闭 diff --git a/test/model/execution/changestatus2doing.php b/test/model/execution/changestatus2doing.php new file mode 100755 index 0000000000..7d49031e87 --- /dev/null +++ b/test/model/execution/changestatus2doing.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-5'); +$execution->name->range('瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b'); +$execution->type->range('project,stage{4}'); +$execution->project->range('0,1{4}'); +$execution->parent->range('0,1,2,3,1'); +$execution->path->range("`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`"); +$execution->status->range('doing,doing,doing,closed,suspended'); +$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->realBegan->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->gen(5); + +/** + +title=测试executionModel->changeStatus2Doing(); +cid=1 +pid=1 + +测试修改顶级父阶段执行状态为进行中 >> 1 +测试修改子阶段执行状态为进行中 >> 1 +测试修改叶子阶段执行状态为进行中 >> 1 + +*/ + +$execution = new executionTest(); +r($execution->changeStatus2DoingObject(2)) && p('') && e('1'); // 测试修改顶级父阶段执行状态为进行中 +r($execution->changeStatus2DoingObject(3)) && p('') && e('1'); // 测试修改子阶段执行状态为进行中 +r($execution->changeStatus2DoingObject(4)) && p('') && e('1'); // 测试修改叶子阶段执行状态为进行中 diff --git a/test/model/execution/changestatus2inactived.php b/test/model/execution/changestatus2inactived.php new file mode 100755 index 0000000000..b374c04277 --- /dev/null +++ b/test/model/execution/changestatus2inactived.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-5'); +$execution->name->range('瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b'); +$execution->type->range('project,stage{4}'); +$execution->project->range('0,1{4}'); +$execution->parent->range('0,1,2,3,1'); +$execution->path->range("`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`"); +$execution->status->range('doing,doing,doing,closed,suspended'); +$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->realBegan->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->gen(5); + +/** + +title=测试executionModel->changeStatus2Inactived(); +cid=1 +pid=1 + +测试修改顶级父阶段执行状态为已挂起 >> '阶段a', +测试修改子阶段执行状态为已关闭 >> empty +测试修改叶子阶段执行状态为已关闭 >> empty + +*/ + +$execution = new executionTest(); +r($execution->changeStatus2InactivedObject(2, 'suspended')) && p('') && e("'阶段a',"); // 测试修改顶级父阶段执行状态为已挂起 +r($execution->changeStatus2InactivedObject(3, 'closed')) && p('') && e("empty"); // 测试修改子阶段执行状态为已关闭 +r($execution->changeStatus2InactivedObject(4, 'closed')) && p('') && e('empty'); // 测试修改叶子阶段执行状态为已关闭 diff --git a/test/model/execution/changestatus2wait.php b/test/model/execution/changestatus2wait.php new file mode 100755 index 0000000000..41bc3a08cb --- /dev/null +++ b/test/model/execution/changestatus2wait.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-5'); +$execution->name->range('瀑布项目1,阶段a,阶段a子1,阶段a子1子1,阶段b'); +$execution->type->range('project,stage{4}'); +$execution->project->range('0,1{4}'); +$execution->parent->range('0,1,2,3,1'); +$execution->path->range("`,1,`,`,1,2,`,`,1,2,3,`,`,1,2,3,4,`,`,1,5,`"); +$execution->status->range('doing,doing,doing,closed,suspended'); +$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->realBegan->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->gen(5); + +/** + +title=测试executionModel->changeStatus2Wait(); +cid=1 +pid=1 + +测试修改顶级父阶段执行状态为未开始 >> '阶段a', +测试修改子阶段执行状态为未开始 >> '阶段a子1', +测试修改叶子阶段执行状态为未开始 >> empty + +*/ + +$execution = new executionTest(); +r($execution->changeStatus2WaitObject(2)) && p('') && e("'阶段a',"); // 测试修改顶级父阶段执行状态为未开始 +r($execution->changeStatus2WaitObject(3)) && p('') && e("'阶段a子1',"); // 测试修改子阶段执行状态为未开始 +r($execution->changeStatus2WaitObject(4)) && p('') && e('empty'); // 测试修改叶子阶段执行状态为未开始