From f171cbf39d00679faa2836acd955407fd5f6a3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B9=BF=E6=98=8E?= Date: Fri, 1 Apr 2022 10:00:52 +0800 Subject: [PATCH 1/3] * Add program test. --- test/class/program.class.php | 340 +------------------------ test/model/program/create.php | 1 + test/model/program/getprogresslist.php | 12 +- test/model/program/gettoppairs.php | 12 +- test/model/program/gettreemenu.php | 17 ++ test/model/program/update.php | 48 +++- 6 files changed, 73 insertions(+), 357 deletions(-) create mode 100644 test/model/program/gettreemenu.php diff --git a/test/class/program.class.php b/test/class/program.class.php index c80d39ce51..df8ed413c6 100644 --- a/test/class/program.class.php +++ b/test/class/program.class.php @@ -12,7 +12,6 @@ class programTest { global $tester; - su('admin'); $this->program = $tester->loadModel('program'); } @@ -51,35 +50,6 @@ class programTest return $this->program->getStakeholdersByPrograms($programID); } - /** - * getBudgetLeft - * - * @param int mixed $programID - * @access public - * @return void - */ - public function getBudgetLeft($programID) - { - $program = $this->program->getById(1); - - return $this->program->getBudgetLeft($program); - } - - /** - * getBudgetUnitList - * - * @access public - * @return void - */ - public function getBudgetUnitList() - { - global $app; - $app->loadConfig('project'); - $app->loadLang('project'); - - return $this->program->getBudgetUnitList(); - } - /** * getById * @@ -119,25 +89,6 @@ class programTest } } - /** - * Test get pairs by list. - * - * @param string|array $programIDList - * @access public - * @return void - */ - public function getPairsByList($programIDList = '') - { - if(empty($this->program->getPairsByList($programIDList))) - { - return array('code' => '404', 'message' => 'Not Found'); - } - else - { - return $this->program->getPairsByList($programIDList); - } - } - /** * Test get list. * @@ -156,228 +107,6 @@ class programTest } - /** - * getParentPairs - * - * @access public - * @return void - */ - public function getParentPairs() - { - return $this->program->getParentPairs(); - } - - /** - * getParentPM - * - * @param array mixed $programIdList - * @access public - * @return void - */ - public function getParentPM($programIdList) - { - return $this->program->getParentPM($programIdList); - } - - /** - * getProductPairsByID - * - * @param int $programID - * @access public - * @return void - */ - public function getProductPairsByID($programID = 0) - { - $program = $this->program->getByID($programID); - if(empty($program)) return array('message' => 'Not Found'); - return $this->program->getProductPairs($programID, 'assign', 'all'); - } - - /** - * getProductPairsByMod - * - * @param string $mode - * @access public - * @return void - */ - public function getProductPairsByMod($mode = 'assign') - { - return $this->program->getProductPairs(1, $mode, 'noclosed'); - } - - /** - * getProductPairsByStatus - * - * @param string $status - * @access public - * @return void - */ - public function getProductPairsByStatus($status = 'all') - { - return $this->program->getProductPairs(1, 'assign', $status); - } - - /** - * getProgressList - * - * @access public - * @return void - */ - public function getProgressList() - { - return $this->program->getProgressList(); - } - - /** - * getStatsByProgramID - * - * @param int $programID - * @access public - * @return void - */ - public function getStatsByProgramID($programID = 0) - { - return count($this->program->getProjectStats($programID)); - } - - /** - * getStatsByStatus - * - * @param string $browseType - * @access public - * @return void - */ - public function getStatsByStatus($browseType = 'all') - { - $projects = $this->program->getProjectStats('0', $browseType); - - if(!$projects) return 0; - foreach($projects as $project) - { - if($project->status != $browseType and $browseType != 'all' and $browseType != 'undone') return 0; - if($browseType == 'undone' and ($project->status != ('wait' or 'doing'))) return 0; - } - - return count($projects); - } - - /** - * getStatsByOrder - * - * @param string $orderBy - * @access public - * @return void - */ - public function getStatsByOrder($orderBy = 'id_desc') - { - $projects = $this->program->getProjectStats('0', 'all', '0', $orderBy); - - return checkOrder($projects, $orderBy); - } - - /** - * getStatsAddProgramTitle - * - * @param int $programTitle - * @access public - * @return void - */ - public function getStatsAddProgramTitle($programTitle = 0) - { - return $this->program->getProjectStats('0', 'all', '0', 'id_desc', '', $programTitle); - } - - /** - * getStatsByInvolved - * - * @param int $involved - * @param string $count - * @access public - * @return void - */ - public function getStatsByInvolved($involved = 0, $count = '') - { - $projects = $this->program->getProjectStats('0', 'all', '0', 'id_desc', '', '0', $involved); - - if($count == 'count') return count($projects); - return $projects; - } - - /** - * getByPrograms - * - * @param int $programIdList - * @access public - * @return void - */ - public function getByPrograms($programIdList = 0) - { - $stakeHolders = $this->program->getStakeholdersByPrograms($programIdList); - - return $stakeHolders; - } - - /** - * getByOrder - * - * @param string $orderBy - * @access public - * @return void - */ - public function getByOrder($orderBy = 'id_desc') - { - $stakeholders = $this->program->getStakeholders(2, $orderBy); - - return checkOrder($stakeholders, $orderBy); - } - - /** - * getTopPairs - * - * @param string $count - * @access public - * @return void - */ - public function getTopPairs($count = '') - { - if($count == 'count') return count($this->program->getTopPairs()); - return $this->program->getTopPairs(); - } - - /** - * getUnfinished - * - * @param mixed $programID - * @access public - * @return void - */ - public function getUnfinished($programID) - { - $program = $this->program->getById($programID); - - return $this->program->hasUnfinished($program); - } - - /** - * setTreePath - * - * @param mixed $programID - * @access public - * @return void - */ - public function setTreePath($programID) - { - $programPath = $this->program->setTreePath($programID); - if($programPath) - { - return $this->program->getById($programID); - } - else - { - return 0; - } - } - /** * update * @@ -388,75 +117,10 @@ class programTest */ public function update($programID, $data) { - global $app; - $_POST = $data; - $result = $this->program->update(10); + $this->program->update($programID); if(dao::isError()) return array('message' => dao::getError()); - $app->dbh->query("UPDATE " . TABLE_PROGRAM . " SET name = '" . $result[0]['old']. "' where id = '" . $programID . "'"); - return $result; + return $this->program->getByID($programID); } - - /** - * updateProgram - * - * @param mixed $programID - * @param int $status - * @access public - * @return void - */ - public function updateProgram($programID, $status = 0) - { - $data = array( - 'parent' => '0', - 'name' => '测试更新项目集十', - 'begin' => '2020-10-10', - 'end' => '2020-10-11', - 'acl' => 'private', - 'budget' => '100', - 'budgetUnit' => 'CNY', - 'whitelist' => array('dev10', 'dev12') - ); - - switch($status) - { - case '1': // 项目集名称已经存在时 - $data['name'] = '项目集1'; - break; - case '2': // 当计划开始为空时更新项目集信息 - $data['begin'] = ''; - break; - case '3': // 当计划完成为空时更新项目集信息 - $data['end'] = ''; - break; - case '4': // 当计划完成小于计划开始时 - $data['end'] = '2020-01-01'; - break; - case '5': // 项目集开始时间小于父项目集时 - $data['parent'] = '9'; - $data['begin'] = '2019-01-01'; - break; - default: // 更新id为10的项目集信息 - } - return $this->update($programID, $data); - } - - /** - * Test process node method. - * - * @param int $programID - * @param int $parentID - * @param string $oldPath - * @param int $oldGrade - * @access public - * @return void - */ - public function processNode($programID, $parentID, $oldPath, $oldGrade) - { - $programs = $this->program->processNode($programID, $parentID, $oldPath, $oldGrade); - return $programs; - } - } -?> diff --git a/test/model/program/create.php b/test/model/program/create.php index f6a8015851..2482bf3a23 100755 --- a/test/model/program/create.php +++ b/test/model/program/create.php @@ -2,6 +2,7 @@ loadModel('program'); +$progressList = $tester->program->getProgressList(); -r($getItemsets->getCount3()) && p() && e('100'); // 获取项目和项目集的个数 -r($getItemsets->getProgressList()) && p('1') && e('0'); // 获取id=1的项目的进度 -r($getItemsets->getProgressList()) && p('11') && e('45'); // 获取id=11的项目集的进度 \ No newline at end of file +r(count($progressList)) && p() && e('120'); // 获取项目和项目集的个数 +r($progressList) && p('1') && e('41'); // 获取id=1的项目的进度 +r($progressList) && p('11') && e('45'); // 获取id=11的项目集的进度 diff --git a/test/model/program/gettoppairs.php b/test/model/program/gettoppairs.php index 58a674e8cb..30add3b6f9 100755 --- a/test/model/program/gettoppairs.php +++ b/test/model/program/gettoppairs.php @@ -1,7 +1,7 @@ #!/usr/bin/env php loadModel('program'); -$t_checkId = 'count'; - -r($program->getTopPairs()) && p('1') && e('项目集1'); // 查看id=1的父项目集 -r($program->getTopPairs($t_checkId)) && p() && e('6'); // 查看父项目集的个数 \ No newline at end of file +r(count($tester->program->getTopPairs())) && p() && e('10'); // 获取系统中所有顶级项目集数量 +r(count($tester->program->getTopPairs('', 'noclosed'))) && p() && e('10'); // 获取系统中所有未关闭的顶级项目集数量 +r(count($tester->program->getTopPairs('', '', true))) && p() && e('10'); // 获取系统中所有顶级项目集数量 diff --git a/test/model/program/gettreemenu.php b/test/model/program/gettreemenu.php new file mode 100644 index 0000000000..efd0c0f9ba --- /dev/null +++ b/test/model/program/gettreemenu.php @@ -0,0 +1,17 @@ +#!/usr/bin/env php +loadModel('program'); +$programs1 = $tester->program->getTreeMenu(1); + +r(strlen($programs1)) && p() && e('789'); // 查看返回的字符个数 diff --git a/test/model/program/update.php b/test/model/program/update.php index 660a4b04e5..a81e60f420 100755 --- a/test/model/program/update.php +++ b/test/model/program/update.php @@ -2,6 +2,7 @@ updateProgram(10)) && p('message:end') && e('测试更新项目集十'); // 更新id为10的项目集信息 -r($t->updateProgram(10, 2)) && p('message[begin]:0') && e('『计划开始』不能为空。'); //当计划开始为空时更新项目集信息 -r($t->updateProgram(10, 3)) && p('message[end]:0') && e('『计划完成』不能为空。'); //当计划完成为空时更新项目集信息 -r($t->updateProgram(10, 4)) && p('message[end]:0') && e('『计划完成』应当大于『2020-10-10』。'); //当计划完成小于计划开始时 -r($t->updateProgram(10, 1)) && p('message[name]:0') && e('『项目集名称』已经有『项目集1』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。'); //项目集名称已经存在时 -r($t->updateProgram(10, 5)) && p('message:begin;message:end') && e('父项目集的开始日期:2019-09-09,开始日期不能小于父项目集的开始日期;父项目集的完成日期:2019-09-09,完成日期不能大于父项目集的完成日期');// 项目集开始时间小于父项目集时 -system("./ztest init"); \ No newline at end of file +$data = array( + 'parent' => '0', + 'name' => '测试更新项目集十', + 'begin' => '2020-10-10', + 'end' => '2022-06-01', + 'acl' => 'private', + 'budget' => '100', + 'budgetUnit' => 'CNY', + 'syncPRJUnit' => true, + 'exchangeRate' => '', + 'whitelist' => array('dev10', 'dev12') +); + +$normalProgram = $data; + +$emptyTitleProgram = $data; +$emptyTitleProgram['name'] = '项目集1'; + +$emptyBeginProgram = $data; +$emptyBeginProgram['begin'] = ''; + +$emptyEndProgram = $data; +$emptyEndProgram['end'] = ''; + +$beginGtEndProgram = $data; +$beginGtEndProgram['begin'] = '2022-07-01'; + +$beginLtParentProgram = $data; +$beginLtParentProgram['parent'] = '9'; +$beginLtParentProgram['begin'] = '2019-01-01'; + +r($program->update(10, $normalProgram)) && p('name') && e('测试更新项目集十'); // 正常更新项目集的情况 +r($program->update(10, $emptyTitleProgram)) && p('message[name]:0') && e('『项目集名称』已经有『项目集1』这条记录了。如果您确定该记录已删除,请到后台-系统-数据-回收站还原。'); // 更新项目集名称重复时 +r($program->update(10, $emptyBeginProgram)) && p('message[begin]:0') && e('『计划开始』不能为空。'); // 当计划完成为空时更新项目集信息 +r($program->update(10, $emptyEndProgram)) && p('message:end') && e('子项目的最大完成日期:2022-05-27,父项目的完成日期不能小于子项目的最大完成日期'); //当计划完成小于计划开始时 +r($program->update(10, $beginGtEndProgram)) && p('message:begin') && e('子项目集的最小开始日期:2022-02-01,父项目集的开始日期不能大于子项目集的最小开始日期'); // 父项目集的开始日期大于子项目集的开始日期时 +r($program->update(10, $beginLtParentProgram)) && p('message:begin;message:end') && e('父项目集的开始日期:2022-02-09,开始日期不能小于父项目集的开始日期;父项目集的完成日期:2022-04-16,完成日期不能大于父项目集的完成日期'); // 项目集开始、结束日期和子项目不符的情况 +system("./ztest init"); From c4a0eb47af35185899d95bb903c855f2b01873d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B9=BF=E6=98=8E?= Date: Fri, 1 Apr 2022 11:03:05 +0800 Subject: [PATCH 2/3] * Add program test. --- test/class/program.class.php | 39 ------------------------------ test/model/program/getchildren.php | 13 +++++----- test/model/program/gettopbyid.php | 14 +++++------ 3 files changed, 13 insertions(+), 53 deletions(-) diff --git a/test/class/program.class.php b/test/class/program.class.php index df8ed413c6..de87cfb82b 100644 --- a/test/class/program.class.php +++ b/test/class/program.class.php @@ -50,45 +50,6 @@ class programTest return $this->program->getStakeholdersByPrograms($programID); } - /** - * getById - * - * @param iont mixed $programID - * @access public - * @return void - */ - public function getById($programID) - { - if(empty($this->program->getById($programID))) - { - return array('code' => 'fail', 'message' => 'Not Found'); - } - else - { - return $this->program->getById($programID); - } - } - - /** - * getChildren - * - * @param int mixed $programID - * @access public - * @return void - */ - public function getChildren($programID) - { - $programInfo = $this->program->getChildren($programID); - if(empty($programInfo)) - { - return array('code' => 'fail' , 'message' => 'Not Found'); - } - else - { - return $programInfo; - } - } - /** * Test get list. * diff --git a/test/model/program/getchildren.php b/test/model/program/getchildren.php index 96326969c1..8a8a156d03 100755 --- a/test/model/program/getchildren.php +++ b/test/model/program/getchildren.php @@ -1,7 +1,7 @@ #!/usr/bin/env php loadModel('program'); -$t_findnu = array('1', '22', '221'); - -r($SubprojectSet->getChildren($t_findnu[0])) && p() && e('9'); // 通过id查找id=1的子项目集个数 -r($SubprojectSet->getChildren($t_findnu[1])) && p() && e('7'); // 通过id查找id=22的子项目集个数 -r($SubprojectSet->getChildren($t_findnu[2])) && p('message') && e('Not Found'); // 通过id查找id=221的子项目集个数 \ No newline at end of file +r($tester->program->getChildren(1)) && p() && e('9'); // 通过id查找id=1的子项目集个数 +r($tester->program->getChildren(22)) && p() && e('7'); // 通过id查找id=22的子项目集个数 +r($tester->program->getChildren(221)) && p() && e('0'); // 通过id查找id=221的子项目集个数 diff --git a/test/model/program/gettopbyid.php b/test/model/program/gettopbyid.php index aaa710cc1b..12d472e321 100755 --- a/test/model/program/gettopbyid.php +++ b/test/model/program/gettopbyid.php @@ -1,9 +1,8 @@ #!/usr/bin/env php loadModel('program'); +$top1 = $tester->program->getTopByID(1); +$top1000 = $tester->program->getTopByID(1000); -$program_id = array(1, 1000); - -r($t->getByID3($program_id[0])) && p() && e('1'); //获取项目集1最上级的项目集id -r($t->getByID3($program_id[1])) && p() && e('Not Found'); //获取项目集1000最上级的项目集id \ No newline at end of file +r($top1) && p() && e('1'); //获取项目集1最上级的项目集id +r($top1000) && p() && e('0'); //获取项目集1000最上级的项目集id From e3e050f3e3b3119733ea81937570d87cf51570a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B9=BF=E6=98=8E?= Date: Sat, 2 Apr 2022 09:58:00 +0800 Subject: [PATCH 3/3] * Add program test. --- test/model/program/createstakeholder.php | 13 ++++++++---- test/model/program/getbudgetleft.php | 13 +++++++----- test/model/program/getparentpairs.php | 10 ++++++--- test/model/program/getparentpm.php | 11 +++++++--- test/model/program/gettoppath.php | 20 ++++++++++++++++++ test/model/program/hasunfinished.php | 12 ++++++----- test/model/program/isclickable.php | 27 ++++++++++++++++++++++++ test/model/program/settreepath.php | 13 ++++++++---- 8 files changed, 95 insertions(+), 24 deletions(-) create mode 100644 test/model/program/gettoppath.php create mode 100644 test/model/program/isclickable.php diff --git a/test/model/program/createstakeholder.php b/test/model/program/createstakeholder.php index dceaa75950..36749a7f29 100755 --- a/test/model/program/createstakeholder.php +++ b/test/model/program/createstakeholder.php @@ -12,9 +12,14 @@ pid=1 创建id=1的项目集的干系人dev1,dev2并查看。 >> dev2;dev1 */ -$Stakeholder = new Program('admin'); -$t_Stakeholder = array('1'); +global $tester; +$tester->loadModel('program'); -r($Stakeholder->createStakeholder($t_Stakeholder[0])) && p('0:account;1:account') && e('dev2;dev1'); // 创建id=1的项目集的干系人dev1,dev2并查看。 -system("./ztest init"); \ No newline at end of file +$_POST['accounts'] = array('dev1', 'dev2'); +$tester->program->createStakeholder(1); +$result = $tester->program->getStakeholdersByPrograms(1); + +r(count($result)) && p('') && e('2'); // 创建id=1的项目集的干系人并查看数量。 +r($result) && p('0:account;1:account') && e('dev2;dev1'); // 创建id=1的项目集的干系人dev1,dev2并查看Account。 +system("./ztest init"); diff --git a/test/model/program/getbudgetleft.php b/test/model/program/getbudgetleft.php index 74aa772645..0e366e6d3e 100755 --- a/test/model/program/getbudgetleft.php +++ b/test/model/program/getbudgetleft.php @@ -1,7 +1,7 @@ #!/usr/bin/env php loadModel('program'); +$program1 = $tester->program->getById(11); +$program2 = $tester->program->getById(12); +$result1 = $tester->program->getBudgetLeft($program1); +$result2 = $tester->program->getBudgetLeft($program2); -$t_itemsid = array('1'); - -r($parentProjectSet->getBudgetLeft($t_itemsid[0])) && p() && e('0'); // 查看父项目集id=1的预算剩余 \ No newline at end of file +r($result) && p() && e('0'); // 查看父项目集id=1的预算剩余 diff --git a/test/model/program/getparentpairs.php b/test/model/program/getparentpairs.php index 8a2149b575..03c6bfe6ab 100755 --- a/test/model/program/getparentpairs.php +++ b/test/model/program/getparentpairs.php @@ -13,7 +13,11 @@ pid=1 */ -$ParentProjectSet = new Program('admin'); +global $tester; +$tester->loadModel('program'); +$program1 = $tester->program->getParentPairs(); +$program2 = $tester->program->getParentPairs('waterfall'); -r($ParentProjectSet->getCount1()) && p() && e('11'); // -r($ParentProjectSet->getParentPairs()) && p('1') && e(''); // 获取父项目集的id/name关联数组 \ No newline at end of file +r(count($program1)) && p() && e('7'); // 获取所有父项目集的数量 +r(count($program2)) && p() && e('1'); // 获取瀑布类型父项目集的数量 +r($program1) && p('1') && e('/项目集1'); // 获取ID为1的父项目集的名称 diff --git a/test/model/program/getparentpm.php b/test/model/program/getparentpm.php index 0150d8a870..7433c0b947 100755 --- a/test/model/program/getparentpm.php +++ b/test/model/program/getparentpm.php @@ -1,7 +1,7 @@ #!/usr/bin/env php > 0 */ -$getPM = new Program('admin'); +global $tester; +$tester->loadModel('program'); + +$programIdList = array(1, 2, 3); +$parentPM = $tester->program->getParentPM($programIdList); +a($parentPM);die; /* GetParentPM($programIdList). */ -r($getPM->getParentPM('1')) && p() && e('0'); // \ No newline at end of file +r($getPM->getParentPM('1')) && p() && e('0'); // diff --git a/test/model/program/gettoppath.php b/test/model/program/gettoppath.php new file mode 100644 index 0000000000..426f94621b --- /dev/null +++ b/test/model/program/gettoppath.php @@ -0,0 +1,20 @@ +#!/usr/bin/env php +loadModel('program'); +$path1 = ',2,3,4,'; +$path2 = '100,101'; + +r($tester->program->getTopByPath($path1)) && p() && e('2'); // 传入一个path,返回最顶级path +r($tester->program->getTopByPath($path2)) && p() && e('100'); // 传入一个path,返回最顶级path diff --git a/test/model/program/hasunfinished.php b/test/model/program/hasunfinished.php index 67d934dc72..4e616b1334 100755 --- a/test/model/program/hasunfinished.php +++ b/test/model/program/hasunfinished.php @@ -1,7 +1,7 @@ #!/usr/bin/env php loadModel('program'); +$program1 = $tester->program->getById(1); +$program2 = $tester->program->getById(2); -$unFinish = 1; - -r($program->getUnfinished($unFinish)) && p() && e('9'); // 获取项目集1下未完成的项目和项目集 \ No newline at end of file +r($tester->program->hasUnfinished($program1)) && p() && e('9'); // 获取项目集1下未完成的项目和项目集数量 +r($tester->program->hasUnfinished($program2)) && p() && e('7'); // 获取项目集2下未完成的项目和项目集数量 diff --git a/test/model/program/isclickable.php b/test/model/program/isclickable.php new file mode 100644 index 0000000000..e8019a13a7 --- /dev/null +++ b/test/model/program/isclickable.php @@ -0,0 +1,27 @@ +#!/usr/bin/env php +> dev2;dev1 + +*/ + +global $tester; +$tester->loadModel('program'); + +$program1 = $tester->program->getById(1); +$program2 = $tester->program->getById(2); + +r($tester->program->isClickable($program1, 'close')) && p('') && e('1'); // 传入项目集1,动作为closed,判断是否可点击 +r($tester->program->isClickable($program1, 'activate')) && p('') && e('0'); // 传入项目集1,动作为activate,判断是否可点击 +r($tester->program->isClickable($program1, 'suspend')) && p('') && e('1'); // 传入项目集1,动作为suspend,判断是否可点击 +r($tester->program->isClickable($program2, 'close')) && p('') && e('1'); // 传入项目集2,动作为closed,判断是否可点击 +r($tester->program->isClickable($program2, 'activate')) && p('') && e('0'); // 传入项目集2,动作为activate,判断是否可点击 +r($tester->program->isClickable($program2, 'suspend')) && p('') && e('1'); // 传入项目集2,动作为activate,判断是否可点击 diff --git a/test/model/program/settreepath.php b/test/model/program/settreepath.php index f9e57a98df..91d6381257 100755 --- a/test/model/program/settreepath.php +++ b/test/model/program/settreepath.php @@ -1,7 +1,7 @@ #!/usr/bin/env php loadModel('program'); -$findId = array(12, 1000); +$before = $tester->program->getById(12); +$tester->program->setTreePath(12); +$after = $tester->program->getById(12); -r($program->setTreePath($findId[0])) && p('path') && e(',2,12,'); // 查找id=12的项目集的path \ No newline at end of file +r($before) && p('path') && e(',2,12,'); // 设置之前的项目集的path +r($after) && p('path') && e(',2,12,'); // 设置之后的项目集的path +system('./ztest init');