From 63c69a104ee3a38270a4fcc1abc62ff1b5796003 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Wed, 17 Aug 2022 14:35:27 +0800 Subject: [PATCH] * Unit test of bug. --- module/bug/model.php | 1 - test/class/bug.class.php | 89 ++++++++++++++++++++++++++++ test/model/bug/getrelatedobjects.php | 33 +++++++++++ test/model/bug/getreviewbugs.php | 39 ++++++++++++ test/model/bug/getstatistic.php | 27 +++++++++ 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100755 test/model/bug/getrelatedobjects.php create mode 100755 test/model/bug/getreviewbugs.php create mode 100755 test/model/bug/getstatistic.php diff --git a/module/bug/model.php b/module/bug/model.php index 34c06d1800..164caa3f5c 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1558,7 +1558,6 @@ class bugModel extends model $bugCount = $this->dao->select("count(id) as num, date_format($field, '%m/%d') as date")->from(TABLE_BUG) ->where('product')->eq($productID) ->andWhere($field)->ne('0000-00-00 00:00:00') - ->andWhere($field)->ne('') ->andWhere('deleted')->eq(0) ->andWhere($field)->between($startDate, $endDate . ' 23:50:59') ->groupBy('date') diff --git a/test/class/bug.class.php b/test/class/bug.class.php index 9ff50201bf..f9a54a65f9 100644 --- a/test/class/bug.class.php +++ b/test/class/bug.class.php @@ -2080,4 +2080,93 @@ class bugTest return $title; } } + + /** + * Test get statistic. + * + * @param int $productID + * @access public + * @return string + */ + public function getStatisticTest($productID = 0) + { + $dates = $this->objectModel->getStatistic($productID); + $returns = array(); + $today = date('m/d', time()); + foreach($dates as $dateType => $dateList) + { + $returns[$dateType] = $dateList[$today]; + } + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $returns; + } + } + + /** + * Test get bugs to review. + * + * @param array $productIDList + * @param int|string $branch + * @param array $modules + * @param array $executions + * @param string $orderBy + * @access public + * @return string + */ + public function getReviewBugsTest($productIDList, $branch, $modules, $executions, $orderBy) + { + $bugs = $this->objectModel->getReviewBugs($productIDList, $branch, $modules, $executions, $orderBy); + $ids = ''; + foreach($bugs as $bug) + { + $ids .= ",$bug->id"; + } + $ids = trim($ids, ','); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $ids; + } + } + + /** + * Test get related objects id lists. + * + * @param array $productIDList + * @param int|string $branch + * @param array $modules + * @param array $executions + * @param string $orderBy + * @access public + * @return string + */ + public function getRelatedObjectsTest($object, $pairs) + { + $objects = $this->objectModel->getRelatedObjects($object, $pairs); + $ids = ''; + foreach($objects as $objectID => $object) + { + $ids .= ",$objectID:$object"; + } + $ids = trim($ids, ','); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $ids; + } + } } diff --git a/test/model/bug/getrelatedobjects.php b/test/model/bug/getrelatedobjects.php new file mode 100755 index 0000000000..47b535517c --- /dev/null +++ b/test/model/bug/getrelatedobjects.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +getRelatedObjects(); +cid=1 +pid=1 + +获取bug关联的 branch 的 id,name >> :,0: +获取bug关联的 task 的 id,name >> :,0: +获取bug关联的 case 的 id,title >> :,0: +获取bug关联的 resolvedBuild 的 id,name >> :,0:,trunk:主干 +获取bug关联的 openedBuild 的 id,name >> :,0:,trunk:主干,1:项目版本版本1 +获取bug关联的 story 的 id,title >> :,0:,2:软件需求2,6:软件需求6,10:软件需求10,14:软件需求14,18:软件需求18,22:软件需求22,26:软件需求26,30:软件需求30,34:软件需求34 + +*/ + +$objects = array('branch', 'task', 'case', 'resolvedBuild', 'openedBuild', 'story'); +$pairs = array('id,name', 'id,title'); + +$bug=new bugTest(); +$_SESSION['bugQueryCondition'] = 'id < 10'; + +r($bug->getRelatedObjectsTest($objects[0], $pairs[0])) && p() && e(':,0:'); // 获取bug关联的 branch 的 id,name +r($bug->getRelatedObjectsTest($objects[1], $pairs[0])) && p() && e(':,0:'); // 获取bug关联的 task 的 id,name +r($bug->getRelatedObjectsTest($objects[2], $pairs[1])) && p() && e(':,0:'); // 获取bug关联的 case 的 id,title +r($bug->getRelatedObjectsTest($objects[3], $pairs[0])) && p() && e(':,0:,trunk:主干'); // 获取bug关联的 resolvedBuild 的 id,name +r($bug->getRelatedObjectsTest($objects[4], $pairs[0])) && p() && e(':,0:,trunk:主干,1:项目版本版本1'); // 获取bug关联的 openedBuild 的 id,name +r($bug->getRelatedObjectsTest($objects[5], $pairs[1])) && p() && e(':,0:,2:软件需求2,6:软件需求6,10:软件需求10,14:软件需求14,18:软件需求18,22:软件需求22,26:软件需求26,30:软件需求30,34:软件需求34'); // 获取bug关联的 story 的 id,title diff --git a/test/model/bug/getreviewbugs.php b/test/model/bug/getreviewbugs.php new file mode 100755 index 0000000000..d02b3b45d8 --- /dev/null +++ b/test/model/bug/getreviewbugs.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +getReviewBugs(); +cid=1 +pid=1 + +*/ + +$productIDList = array('1,2,3,1000001', '1,3'); +$branch = array('all', '1'); +$moduleIDList = array('1821,1825,1832,1000001', '1821, 1825'); +$executions = array(array(101,102), array(101,111)); +$orderBy = 'id_asc'; + +$bug=new bugTest(); + +r($bug->getReviewBugsTest($productIDList[0], $branch[0], $moduleIDList[0], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支all 模块1821, 1825, 1832 不存在的模块1000001 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[1], $moduleIDList[0], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支1 模块1821, 1825, 1832 不存在的模块1000001 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[0], $moduleIDList[1], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支all 模块1821, 1825 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[1], $moduleIDList[1], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支1 模块1821, 1825 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[0], $moduleIDList[0], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支all 模块1821, 1825, 1832 不存在的模块1000001 执行101 111下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[1], $moduleIDList[0], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支1 模块1821, 1825, 1832 不存在的模块1000001 执行101 111下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[0], $moduleIDList[1], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支all 模块1821, 1825 执行101 111下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[0], $branch[1], $moduleIDList[1], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 2 3 不存在的产品10001 与分支1 模块1821, 1825 执行101 111下审批人为当前用户的bug +// +r($bug->getReviewBugsTest($productIDList[1], $branch[0], $moduleIDList[0], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支all 模块1821, 1825, 1832 不存在的模块1000001 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[1], $moduleIDList[0], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支1 模块1821, 1825, 1832 不存在的模块1000001 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[0], $moduleIDList[1], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支all 模块1821, 1825 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[1], $moduleIDList[1], $executions[0], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支1 模块1821, 1825 执行101 102下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[0], $moduleIDList[0], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支all 模块1821, 1825, 1832 不存在的模块1000001 执行101 111下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[1], $moduleIDList[0], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支1 模块1821, 1825, 1832 不存在的模块1000001 执行101 111下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[0], $moduleIDList[1], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支all 模块1821, 1825 执行101 111下审批人为当前用户的bug +r($bug->getReviewBugsTest($productIDList[1], $branch[1], $moduleIDList[1], $executions[1], $orderBy)) && p('') && e(''); // 查询产品1 3 与分支1 模块1821, 1825 执行101 111下审批人为当前用户的bug diff --git a/test/model/bug/getstatistic.php b/test/model/bug/getstatistic.php new file mode 100755 index 0000000000..0277bfe50b --- /dev/null +++ b/test/model/bug/getstatistic.php @@ -0,0 +1,27 @@ +#!/usr/bin/env php +getStatistic(); +cid=1 +pid=1 + +*/ + +$productIDList = array('1', '11', '31', '61', '91', '10001'); + +$bug=new bugTest(); + +r($bug->getStatisticTest()) && p('openedDate:num') && e('0'); // 查询product id为0创建日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[0])) && p('openedDate:num') && e('0'); // 查询product id为1创建日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[0])) && p('resolvedDate:num') && e('0'); // 查询product id为1创建日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[0])) && p('closedDate:num') && e('0'); // 查询product id为1创建日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[1])) && p('openedDate:num') && e('1'); // 查询product id为11解决日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[2])) && p('openedDate:num') && e('0'); // 查询product id为31解决日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[3])) && p('openedDate:num') && e('0'); // 查询product id为61解决日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[4])) && p('openedDate:num') && e('0'); // 查询product id为91关闭日期在今天的统计信息 +r($bug->getStatisticTest($productIDList[5])) && p('openedDate:num') && e('0'); // 查询product id为10001关闭日期在今天的统计信息