From 64bb25430be113c0314863e265cfca6d5810852f Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Sat, 25 Feb 2023 03:19:49 +0000 Subject: [PATCH] * Add the programplan unit testcase. --- module/programplan/model.php | 9 +- test/class/programplan.class.php | 86 +++++++++++++++++++ test/model/programplan/checkleafstage.php | 36 ++++++++ test/model/programplan/checktopstage.php | 38 ++++++++ .../programplan/getselfandchildrenlist.php | 38 ++++++++ test/model/programplan/getsiblings.php | 43 ++++++++++ test/model/programplan/updatesubstageattr.php | 37 ++++++++ 7 files changed, 282 insertions(+), 5 deletions(-) create mode 100755 test/model/programplan/checkleafstage.php create mode 100755 test/model/programplan/checktopstage.php create mode 100755 test/model/programplan/getselfandchildrenlist.php create mode 100755 test/model/programplan/getsiblings.php create mode 100755 test/model/programplan/updatesubstageattr.php diff --git a/module/programplan/model.php b/module/programplan/model.php index 42c004d51b..5bd2ca475f 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -1581,7 +1581,7 @@ class programplanModel extends model } /** - * Change whether it is the top stage. + * Check whether it is the top stage. * * @param int $planID * @access public @@ -1600,23 +1600,22 @@ class programplanModel extends model * * @param int $planID * @param string $attribute - * @param bool $withDeleted * @access public * @return bool */ - public function updateSubStageAttr($planID, $attribute, $withDeleted = false) + public function updateSubStageAttr($planID, $attribute) { if($attribute == 'mix') return true; $subStageList = $this->dao->select('id')->from(TABLE_EXECUTION) ->where('parent')->eq($planID) - ->beginIF(!$withDeleted)->andWhere('deleted')->eq(0)->fi() + ->andWhere('deleted')->eq(0) ->fetchAll('id'); $this->dao->update(TABLE_EXECUTION)->set('attribute')->eq($attribute)->where('id')->in(array_keys($subStageList))->exec(); foreach($subStageList as $childID => $subStage) { - $this->updateSubStageAttr($childID, $attribute, $withDeleted); + $this->updateSubStageAttr($childID, $attribute); } } diff --git a/test/class/programplan.class.php b/test/class/programplan.class.php index ef4cb9c0f3..0ba204b175 100644 --- a/test/class/programplan.class.php +++ b/test/class/programplan.class.php @@ -385,4 +385,90 @@ class programplanTest return $objects; } + + /** + * Test check if the stage is a leaf stage. + * + * @param int $planID + * @access public + * @return string + */ + public function checkLeafStageTest($planID) + { + $objects = $this->objectModel->checkLeafStage($planID); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Test check whether it is the top stage. + * + * @param int $planID + * @access public + * @return string + */ + public function checkTopStageTest($planID) + { + $objects = $this->objectModel->checkTopStage($planID); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Test update sub-stage attribute. + * + * @param int $planID + * @param string $attribute + * @param int $subStageID + * @access public + * @return string + */ + public function updateSubStageAttrTest($planID, $attribute, $subStageID) + { + global $tester; + + $objects = $this->objectModel->updateSubStageAttr($planID, $attribute); + + if(dao::isError()) return dao::getError(); + + $attribute = $tester->dao->select('attribute')->from(TABLE_EXECUTION)->where('id')->eq($subStageID)->fetch('attribute'); + + return $attribute; + } + + /** + * Test get plan and its children. + * + * @param string|int|array $executionIdList + * @access public + * @return string + */ + public function getSelfAndChildrenListTest($executionIdList) + { + $objects = $this->objectModel->getSelfAndChildrenList($executionIdList); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Test get plan's siblings. + * + * @param string|int|array $executionIdList + * @access public + * @return string + */ + public function getSiblingsTest($executionIdList) + { + $objects = $this->objectModel->getSiblings($executionIdList); + + if(dao::isError()) return dao::getError(); + + return $objects; + } } diff --git a/test/model/programplan/checkleafstage.php b/test/model/programplan/checkleafstage.php new file mode 100755 index 0000000000..7f18fb14b1 --- /dev/null +++ b/test/model/programplan/checkleafstage.php @@ -0,0 +1,36 @@ +#!/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=测试programplanModel->checkLeafStage(); +cid=1 +pid=1 + +测试id为2判断是否为叶子节点 >> 0 +测试id为5判断是否为叶子节点 >> 1 + +*/ + +$plan = new programplanTest(); + +r($plan->checkLeafStageTest(2)) && p('') && e(0); // 测试id为2判断是否为叶子节点 +r($plan->checkLeafStageTest(5)) && p('') && e(1); // 测试id为5判断是否为叶子节点 diff --git a/test/model/programplan/checktopstage.php b/test/model/programplan/checktopstage.php new file mode 100755 index 0000000000..25f46662ad --- /dev/null +++ b/test/model/programplan/checktopstage.php @@ -0,0 +1,38 @@ +#!/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=测试programplanModel->checkTopStage(); +cid=1 +pid=1 + +测试id为2判断是否为顶级阶段 >> 1 +测试id为4判断是否为顶级阶段 >> 0 +测试id为5判断是否为顶级阶段 >> 1 + +*/ + +$plan = new programplanTest(); + +r($plan->checkTopStageTest(2)) && p('') && e(1); // 测试id为2判断是否为顶级阶段 +r($plan->checkTopStageTest(4)) && p('') && e(0); // 测试id为4判断是否为顶级阶段 +r($plan->checkTopStageTest(5)) && p('') && e(1); // 测试id为5判断是否为顶级阶段 diff --git a/test/model/programplan/getselfandchildrenlist.php b/test/model/programplan/getselfandchildrenlist.php new file mode 100755 index 0000000000..c3df92c33c --- /dev/null +++ b/test/model/programplan/getselfandchildrenlist.php @@ -0,0 +1,38 @@ +#!/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=测试programplanModel->getSelfAndChildrenList(); +cid=1 +pid=1 + +测试id为2时获取自己的状态 >> doing +测试id为2时获取自己某一个后代的状态 >> 2 + +*/ + +$plan = new programplanTest(); +$topPlan = $plan->getSelfAndChildrenListTest(2); +$topPlanCount = count($topPlan[2]); + +r($topPlan[2][2]) && p('status') && e('doing'); // 测试id为2时获取自己的状态 +r($topPlanCount - 1) && p('') && e(2); // 测试id为2时获取自己后代的个数 diff --git a/test/model/programplan/getsiblings.php b/test/model/programplan/getsiblings.php new file mode 100755 index 0000000000..ad9ec76e5d --- /dev/null +++ b/test/model/programplan/getsiblings.php @@ -0,0 +1,43 @@ +#!/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=测试programplanModel->getSiblings(); +cid=1 +pid=1 + +测试id为2时获取兄弟阶段的的名称 >> 阶段b +测试id为2时获取自己兄弟阶段的个数 >> 1 +测试id为4时获取自己兄弟阶段的个数 >> 0 + +*/ + +$plan = new programplanTest(); +$topPlan = $plan->getSiblingsTest(2); +$topPlanCount = count($topPlan[2]); + +$leafPlan = $plan->getSiblingsTest(4); +$leafPlanCount = count($leafPlan[4]); + +r($topPlan[2][5]) && p('name') && e('阶段b'); // 测试id为2时获取兄弟阶段的的名称 +r($topPlanCount - 1) && p('') && e(1); // 测试id为2时获取自己兄弟阶段的个数 +r($leafPlanCount - 1) && p('') && e(0); // 测试id为4时获取自己兄弟阶段的个数 diff --git a/test/model/programplan/updatesubstageattr.php b/test/model/programplan/updatesubstageattr.php new file mode 100755 index 0000000000..6c73e0ae98 --- /dev/null +++ b/test/model/programplan/updatesubstageattr.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->attribute->range(" ,mix,request,request,review"); +$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=测试programplanModel->updateSubStageAttr(); +cid=1 +pid=1 + +测试更改id为3的阶段为综合 >> request +测试更改id为2的阶段为设计 >> design + +*/ + +$plan = new programplanTest(); + +r($plan->updateSubStageAttrTest(3, 'mix', 4)) && p('') && e('request'); // 测试更改id为3的阶段为综合 +r($plan->updateSubStageAttrTest(2, 'design', 3)) && p('') && e('design'); // 测试更改id为2的阶段为设计