From 1b61b51f97411ef529e06b131e6f422d60342704 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 26 Aug 2022 15:06:48 +0800 Subject: [PATCH 1/2] * Add case for execution module. --- test/class/execution.class.php | 103 +++++++++++++++++- test/model/execution/checkbeginandenddate.php | 30 +++++ test/model/execution/checkpriv.php | 31 ++++++ test/model/execution/checkworkload.php | 71 ++++++++++++ test/model/execution/getstatdata.php | 76 +++++++++++++ 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100755 test/model/execution/checkbeginandenddate.php create mode 100755 test/model/execution/checkpriv.php create mode 100755 test/model/execution/checkworkload.php create mode 100755 test/model/execution/getstatdata.php diff --git a/test/class/execution.class.php b/test/class/execution.class.php index e958b9a486..3058bff2c5 100644 --- a/test/class/execution.class.php +++ b/test/class/execution.class.php @@ -13,6 +13,18 @@ class executionTest $this->objectModel = $tester->loadModel('execution'); } + /** + * Check the privilege. + * + * @param mixed $executionID + * @access public + * @return bool + */ + public function checkPrivTest($executionID) + { + return $this->objectModel->checkPriv($executionID); + } + /** * get todate * @@ -351,6 +363,76 @@ class executionTest } } + /** + * Check the workload format and total. + * + * @param int $executionID + * @param string $type + * @param int $percent + * @access public + * @return bool + */ + public function checkWorkloadTest($executionID = 0, $type = '', $percent = 0) + { + global $tester; + $tester->app->loadLang('programplan'); + $_POST['products'] = array(1, 81, 91); + $_POST['percent'] = $percent; + $_POST['parent'] = 0; + + $oldExecution = $executionID ? $this->objectModel->getByID($executionID) : ''; + if(!empty($oldExecution->parent)) $_POST['parent'] = $oldExecution->parent; + + $result = $this->objectModel->checkWorkload($type, $percent, $oldExecution); + if(dao::isError()) return dao::getError(true); + + return $result; + } + + /** + * Check begin and end date. + * + * @param int $projectID + * @param string $checkType empty|normal|gt|lt|eq + * @access public + * @return bool + */ + public function checkBeginAndEndDateTest($projectID, $checkType) + { + if($projectID) $project = $this->objectModel->getByID($projectID); + switch($checkType) + { + case 'empty': + $_POST['begin'] = ''; + $_POST['end'] = ''; + break; + case 'normal': + $_POST['begin'] = empty($project->begin) ? '' : date("Y-m-d",strtotime("+1 days",strtotime($project->begin))); + $_POST['end'] = empty($project->end) ? '' : date("Y-m-d",strtotime("-1 days",strtotime($project->end))); + break; + case 'lt': + $_POST['begin'] = empty($project->begin) ? '' : date("Y-m-d",strtotime("-1 days",strtotime($project->begin))); + $_POST['end'] = empty($project->end) ? '' : date("Y-m-d",strtotime("-1 days",strtotime($project->end))); + break; + case 'gt': + $_POST['begin'] = empty($project->begin) ? '' : date("Y-m-d",strtotime("+1 days",strtotime($project->begin))); + $_POST['end'] = empty($project->end) ? '' : date("Y-m-d",strtotime("+1 days",strtotime($project->end))); + break; + case 'eq': + $_POST['begin'] = empty($project->begin) ? '' : $project->begin; + $_POST['end'] = empty($project->end) ? '' : $project->end; + break; + } + + $begin = $_POST['begin']; + $end = $_POST['end']; + + $this->objectModel->checkBeginAndEndDate($projectID, $begin, $end); + if(dao::isError()) return dao::getError(true); + + return true; + } + /** * function getPairs test by execution * @@ -523,7 +605,6 @@ class executionTest { $object = $this->objectModel->getIdList($projectID); - if(dao::isError()) { $error = dao::getError(); @@ -539,6 +620,26 @@ class executionTest } } + /** + * Get execution stat data. + * + * @param int $projectID + * @param string $browseType + * @param int $productID + * @param int $branch + * @param bool $withTasks + * @param string $param + * @param string $orderBy + * @param object $pager + * @access public + * @return int + */ + public function getStatDataTest($projectID = 0, $browseType = 'undone', $productID = 0, $branch = 0, $withTasks = false, $param = '', $orderBy = 'id_asc', $pager = null) + { + $objects = $this->objectModel->getStatData($projectID); + return count($objects); + } + /** * function getBranches test execution * diff --git a/test/model/execution/checkbeginandenddate.php b/test/model/execution/checkbeginandenddate.php new file mode 100755 index 0000000000..d1b7e0dd41 --- /dev/null +++ b/test/model/execution/checkbeginandenddate.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +checkBeginAndEndDate(); +cid=1 +pid=1 + +测试传入空值 >> 1 +测试检查正常的日期 >> 1 +测试检查小于开始的日期 >> 迭代开始日期应大于等于项目的开始日期:2022-05-26。\n +测试检查大于开始的日期 >> 迭代截止日期应小于等于项目的截止日期:2022-09-30。\n +测试检查等于开始跟结束的日期 >> 1 + +*/ + +$projectIdList = array(0, 11); +$checkType = array('empty', 'normal', 'lt', 'gt', 'eq'); + +$execution = new executionTest(); + +r($execution->checkBeginAndEndDateTest($projectIdList[0], $checkType[0])) && p() && e('1'); // 测试传入空值 +r($execution->checkBeginAndEndDateTest($projectIdList[1], $checkType[1])) && p() && e('1'); // 测试检查正常的日期 +r($execution->checkBeginAndEndDateTest($projectIdList[1], $checkType[2])) && p() && e('迭代开始日期应大于等于项目的开始日期:2022-05-26。\n'); // 测试检查小于开始的日期 +r($execution->checkBeginAndEndDateTest($projectIdList[1], $checkType[3])) && p() && e('迭代截止日期应小于等于项目的截止日期:2022-09-30。\n'); // 测试检查大于开始的日期 +r($execution->checkBeginAndEndDateTest($projectIdList[1], $checkType[4])) && p() && e('1'); // 测试检查等于开始跟结束的日期 diff --git a/test/model/execution/checkpriv.php b/test/model/execution/checkpriv.php new file mode 100755 index 0000000000..4b89f77306 --- /dev/null +++ b/test/model/execution/checkpriv.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +checkPriv(); +cid=1 +pid=1 + +测试传入空值 >> 0 +测试传入0 >> 0 +测试传入正确的项目ID的权限判断 >> 1 +测试传入迭代ID的权限判断 >> 1 +测试传入阶段ID的权限判断 >> 1 +测试传入看板ID的权限判断 >> 1 + +*/ + +$executionIdList = array('', 0, 1, 101, 131, 161); + +$execution = new executionTest(); + +r($execution->checkPrivTest($executionIdList[0])) && p() && e('0'); // 测试传入空值 +r($execution->checkPrivTest($executionIdList[1])) && p() && e('0'); // 测试传入0 +r($execution->checkPrivTest($executionIdList[2])) && p() && e('1'); // 测试传入正确的项目ID的权限判断 +r($execution->checkPrivTest($executionIdList[3])) && p() && e('1'); // 测试传入迭代ID的权限判断 +r($execution->checkPrivTest($executionIdList[4])) && p() && e('1'); // 测试传入阶段ID的权限判断 +r($execution->checkPrivTest($executionIdList[5])) && p() && e('1'); // 测试传入看板ID的权限判断 diff --git a/test/model/execution/checkworkload.php b/test/model/execution/checkworkload.php new file mode 100755 index 0000000000..2745a6f65b --- /dev/null +++ b/test/model/execution/checkworkload.php @@ -0,0 +1,71 @@ +#!/usr/bin/env php +checkWorkload(); +cid=1 +pid=1 + +测试传入空数据 >> 0 +测试创建迭代的工作量 >> 0 +测试创建迭代的工作量 >> 工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n +测试创建迭代的工作量 >> "工作量比例"必须为数字\n +测试创建迭代的工作量 >> 0 +测试更新迭代的工作量 >> 0 +测试更新迭代的工作量 >> 工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n +测试更新迭代的工作量 >> "工作量比例"必须为数字\n +测试更新迭代的工作量 >> 0 +测试创建阶段的工作量 >> 0 +测试创建阶段的工作量 >> 工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n +测试创建阶段的工作量 >> "工作量比例"必须为数字\n +测试创建阶段的工作量 >> 0 +测试更新阶段的工作量 >> 0 +测试更新阶段的工作量 >> 工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n +测试更新阶段的工作量 >> "工作量比例"必须为数字\n +测试更新阶段的工作量 >> 0 +测试创建看板的工作量 >> 0 +测试创建看板的工作量 >> 工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n +测试创建看板的工作量 >> "工作量比例"必须为数字\n +测试创建看板的工作量 >> 0 +测试更新看板的工作量 >> 0 +测试更新看板的工作量 >> 工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n +测试更新看板的工作量 >> "工作量比例"必须为数字\n +测试更新看板的工作量 >> 0 + +*/ + +$executionIdList = array(0, 101, 131, 161); +$typeList = array('', 'create', 'update'); +$percentList = array('0', '123', 'all', '10'); + +$execution = new executionTest(); + +r($execution->checkWorkloadTest($executionIdList[0], $typeList[0], $percentList[0])) && p() && e('0'); // 测试传入空数据 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[1], $percentList[0])) && p() && e('0'); // 测试创建迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[1], $percentList[1])) && p() && e('工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n'); // 测试创建迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[1], $percentList[2])) && p() && e('"工作量比例"必须为数字\n'); // 测试创建迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[1], $percentList[3])) && p() && e('0'); // 测试创建迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[2], $percentList[0])) && p() && e('0'); // 测试更新迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[2], $percentList[1])) && p() && e('工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n'); // 测试更新迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[2], $percentList[2])) && p() && e('"工作量比例"必须为数字\n'); // 测试更新迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[1], $typeList[2], $percentList[3])) && p() && e('0'); // 测试更新迭代的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[1], $percentList[0])) && p() && e('0'); // 测试创建阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[1], $percentList[1])) && p() && e('工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n'); // 测试创建阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[1], $percentList[2])) && p() && e('"工作量比例"必须为数字\n'); // 测试创建阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[1], $percentList[3])) && p() && e('0'); // 测试创建阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[2], $percentList[0])) && p() && e('0'); // 测试更新阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[2], $percentList[1])) && p() && e('工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n'); // 测试更新阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[2], $percentList[2])) && p() && e('"工作量比例"必须为数字\n'); // 测试更新阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[2], $typeList[2], $percentList[3])) && p() && e('0'); // 测试更新阶段的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[1], $percentList[0])) && p() && e('0'); // 测试创建看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[1], $percentList[1])) && p() && e('工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n'); // 测试创建看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[1], $percentList[2])) && p() && e('"工作量比例"必须为数字\n'); // 测试创建看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[1], $percentList[3])) && p() && e('0'); // 测试创建看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[2], $percentList[0])) && p() && e('0'); // 测试更新看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[2], $percentList[1])) && p() && e('工作量占比累计不应当超过100, 当前产品下的工作量之和为%\n'); // 测试更新看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[2], $percentList[2])) && p() && e('"工作量比例"必须为数字\n'); // 测试更新看板的工作量 +r($execution->checkWorkloadTest($executionIdList[3], $typeList[2], $percentList[3])) && p() && e('0'); // 测试更新看板的工作量 diff --git a/test/model/execution/getstatdata.php b/test/model/execution/getstatdata.php new file mode 100755 index 0000000000..dc50f1b7e9 --- /dev/null +++ b/test/model/execution/getstatdata.php @@ -0,0 +1,76 @@ +#!/usr/bin/env php +getStatData(); +cid=1 +pid=1 + +测试默认值 >> 0 +测试传入空值 >> 0 +测试projectID为1的所有未关闭执行 >> 0 +测试projectID为1的所有执行 >> 0 +测试projectID为1的未开始执行 >> 0 +测试projectID为1的进行中执行 >> 0 +测试projectID为1的已挂起执行 >> 0 +测试projectID为1的已关闭执行 >> 0 +测试projectID为1的我参与执行 >> 0 +测试projectID为1的搜索出来的执行 >> 0 +测试projectID为1的评审执行 >> 0 +测试projectID为1, productID为1, branchID为0的所有执行 >> 0 +测试projectID为1, productID为1, branchID为0的所有执行和任务 >> 0 +测试projectID为1, productID为1, branchID为0的非父阶段 >> 0 +测试projectID为11的所有未关闭执行 >> 7 +测试projectID为11的所有执行 >> 7 +测试projectID为11的未开始执行 >> 7 +测试projectID为11的进行中执行 >> 7 +测试projectID为11的已挂起执行 >> 7 +测试projectID为11的已关闭执行 >> 7 +测试projectID为11的我参与执行 >> 7 +测试projectID为11的搜索出来的执行 >> 7 +测试projectID为11的评审执行 >> 7 +测试projectID为11, productID为1, branchID为0的所有执行 >> 7 +测试projectID为11, productID为1, branchID为0的所有执行和任务 >> 7 +测试projectID为11, productID为1, branchID为0的非父阶段 >> 7 + +*/ + +$projectIdList = array(0, 1, 11); +$browseTypeList = array('all', 'wait', 'doing', 'suspended', 'closed', 'involved', 'bySearch', 'review'); +$productID = 1; +$branchID = 0; +$withTasksList = array(false, true); +$param = 'skipParent'; + +$execution = new executionTest(); + +r($execution->getStatDataTest()) && p() && e('0'); // 测试默认值 +r($execution->getStatDataTest($projectIdList[0])) && p() && e('0'); // 测试传入空值 +r($execution->getStatDataTest($projectIdList[1])) && p() && e('0'); // 测试projectID为1的所有未关闭执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[0])) && p() && e('0'); // 测试projectID为1的所有执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[1])) && p() && e('0'); // 测试projectID为1的未开始执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[2])) && p() && e('0'); // 测试projectID为1的进行中执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[3])) && p() && e('0'); // 测试projectID为1的已挂起执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[4])) && p() && e('0'); // 测试projectID为1的已关闭执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[5])) && p() && e('0'); // 测试projectID为1的我参与执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[6])) && p() && e('0'); // 测试projectID为1的搜索出来的执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[7])) && p() && e('0'); // 测试projectID为1的评审执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[0], $productID, $branchID)) && p() && e('0'); // 测试projectID为1, productID为1, branchID为0的所有执行 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[0], $productID, $branchID), $withTasksList[1]) && p() && e('0'); // 测试projectID为1, productID为1, branchID为0的所有执行和任务 +r($execution->getStatDataTest($projectIdList[1], $browseTypeList[0], $productID, $branchID), $withTasksList[0], $param) && p() && e('0'); // 测试projectID为1, productID为1, branchID为0的非父阶段 +r($execution->getStatDataTest($projectIdList[2])) && p() && e('7'); // 测试projectID为11的所有未关闭执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[0])) && p() && e('7'); // 测试projectID为11的所有执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[1])) && p() && e('7'); // 测试projectID为11的未开始执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[2])) && p() && e('7'); // 测试projectID为11的进行中执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[3])) && p() && e('7'); // 测试projectID为11的已挂起执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[4])) && p() && e('7'); // 测试projectID为11的已关闭执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[5])) && p() && e('7'); // 测试projectID为11的我参与执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[6])) && p() && e('7'); // 测试projectID为11的搜索出来的执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[7])) && p() && e('7'); // 测试projectID为11的评审执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[0], $productID, $branchID)) && p() && e('7'); // 测试projectID为11, productID为1, branchID为0的所有执行 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[0], $productID, $branchID), $withTasksList[1]) && p() && e('7'); // 测试projectID为11, productID为1, branchID为0的所有执行和任务 +r($execution->getStatDataTest($projectIdList[2], $browseTypeList[0], $productID, $branchID), $withTasksList[0], $param) && p() && e('7'); // 测试projectID为11, productID为1, branchID为0的非父阶段 From db4a18e3bd4bae246bea45c9e1dae2093fb039e8 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 26 Aug 2022 15:10:31 +0800 Subject: [PATCH 2/2] * Methods to optimize execution modules. --- module/execution/model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module/execution/model.php b/module/execution/model.php index 591f8318fe..d1aff79680 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1151,7 +1151,7 @@ class executionModel extends model } /* The total workload of the first stage should not exceed 100%. */ - if($type == 'create' or $oldExecution->grade == 1) + if($type == 'create' or (empty($oldExecution) and $oldExecution->grade == 1)) { $oldPercentTotal = $this->dao->select('SUM(t2.percent) as total')->from(TABLE_PROJECTPRODUCT)->alias('t1') ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.project=t2.id') @@ -1198,6 +1198,7 @@ class executionModel extends model public function checkBeginAndEndDate($projectID, $begin, $end) { $project = $this->loadModel('project')->getByID($projectID); + if(empty($project)) return; if($begin < $project->begin) dao::$errors['begin'] = sprintf($this->lang->execution->errorCommonBegin, $project->begin); if($end > $project->end) dao::$errors['end'] = sprintf($this->lang->execution->errorCommonEnd, $project->end); @@ -1463,6 +1464,8 @@ class executionModel extends model */ public function getStatData($projectID = 0, $browseType = 'undone', $productID = 0, $branch = 0, $withTasks = false, $param = '', $orderBy = 'id_asc', $pager = null) { + if($projectID) return array(); + /* Construct the query SQL at search executions. */ $executionQuery = ''; if($browseType == 'bySearch')