* Add execution module unit testcase.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/execution.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('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'); // 测试批量修改执行状态为已关闭
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/execution.class.php';
|
||||
zdTable('user')->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'); // 测试传入已关闭状态,返回对象的由谁关闭
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/execution.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=测试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'); // 测试修改叶子阶段执行状态为进行中
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/execution.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=测试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'); // 测试修改叶子阶段执行状态为已关闭
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/execution.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=测试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'); // 测试修改叶子阶段执行状态为未开始
|
||||
Reference in New Issue
Block a user