* Add the programplan unit testcase.

This commit is contained in:
hufangzhou
2023-02-25 03:19:49 +00:00
parent a7db149f73
commit 64bb25430b
7 changed files with 282 additions and 5 deletions
+4 -5
View File
@@ -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);
}
}
+86
View File
@@ -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;
}
}
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
include dirname(dirname(dirname(__FILE__))) . '/class/programplan.class.php';
zdTable('user')->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判断是否为叶子节点
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
include dirname(dirname(dirname(__FILE__))) . '/class/programplan.class.php';
zdTable('user')->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判断是否为顶级阶段
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
include dirname(dirname(dirname(__FILE__))) . '/class/programplan.class.php';
zdTable('user')->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时获取自己后代的个数
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
include dirname(dirname(dirname(__FILE__))) . '/class/programplan.class.php';
zdTable('user')->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时获取自己兄弟阶段的个数
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
include dirname(dirname(dirname(__FILE__))) . '/class/programplan.class.php';
zdTable('user')->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的阶段为设计