From b6eda2f796daf61e16e8f32095ec55a5bb031f03 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 2 Jun 2023 16:31:26 +0800 Subject: [PATCH] * Refactor bugModel-getUserBugs, and modify its unit test. --- module/bug/model.php | 16 +++----- module/bug/test/bug.class.php | 23 +++++++++-- module/bug/test/model/getuserbugs.php | 55 ++++++++++++++++++++------- module/bug/test/yaml/userquery.yaml | 19 +++++++++ 4 files changed, 85 insertions(+), 28 deletions(-) create mode 100644 module/bug/test/yaml/userquery.yaml diff --git a/module/bug/model.php b/module/bug/model.php index 716360fabe..3aa063579b 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -808,6 +808,7 @@ class bugModel extends model } /** + * 测试获取当前用户的 bugs。 * Get user bugs. * * @param string $account @@ -820,18 +821,13 @@ class bugModel extends model * @access public * @return array */ - public function getUserBugs($account, $type = 'assignedTo', $orderBy = 'id_desc', $limit = 0, $pager = null, $executionID = 0, $queryID = 0) + public function getUserBugs(string $account, string $type = 'assignedTo', string $orderBy = 'id_desc', int $limit = 0, object $pager = null, int $executionID = 0, int $queryID = 0): array { + if($type != 'bySearch' and !$this->loadModel('common')->checkField(TABLE_BUG, $type)) return array(); + $moduleName = $this->app->rawMethod == 'work' ? 'workBug' : 'contributeBug'; $queryName = $moduleName . 'Query'; $formName = $moduleName . 'Form'; - $bugIdList = array(); - if($moduleName == 'contributeBug') - { - $bugsAssignedByMe = $this->loadModel('my')->getAssignedByMe($account, 0, '', $orderBy, 'bug'); - foreach($bugsAssignedByMe as $bugID => $bug) $bugIdList[$bugID] = $bugID; - } - if($queryID) { $query = $this->loadModel('search')->getQuery($queryID); @@ -852,7 +848,7 @@ class bugModel extends model $query = $this->session->$queryName; $query = preg_replace('/`(\w+)`/', 't1.`$1`', $query); - if($type != 'bySearch' and !$this->loadModel('common')->checkField(TABLE_BUG, $type)) return array(); + if($moduleName == 'contributeBug') $bugsAssignedByMe = $this->loadModel('my')->getAssignedByMe($account, 0, '', $orderBy, 'bug'); return $this->dao->select("t1.*, t2.name AS productName, t2.shadow, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) AS priOrder, IF(t1.`severity` = 0, {$this->config->maxPriValue}, t1.`severity`) AS severityOrder")->from(TABLE_BUG)->alias('t1') ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id') ->where('t1.deleted')->eq(0) @@ -867,7 +863,7 @@ class bugModel extends model ->andWhere('t1.openedBy', 1)->eq($account) ->orWhere('t1.closedBy')->eq($account) ->orWhere('t1.resolvedBy')->eq($account) - ->orWhere('t1.id')->in($bugIdList) + ->orWhere('t1.id')->in(!empty($bugsAssignedByMe) ? array_keys($bugsAssignedByMe) : array()) ->markRight(1) ->fi() ->orderBy($orderBy) diff --git a/module/bug/test/bug.class.php b/module/bug/test/bug.class.php index 101419a461..68eeb76c76 100644 --- a/module/bug/test/bug.class.php +++ b/module/bug/test/bug.class.php @@ -552,16 +552,31 @@ class bugTest } /** + * 测试获取用户的 bugs。 * Test get user bugs. * - * @param string $account - * @param string $type + * @param string $account + * @param string $type + * @param int $limit + * @param int $executionID + * @param int $queryID + * @param string $rawMethod + * @param string|bool $query * @access public * @return array */ - public function getUserBugsTest($account, $type = 'assignedTo') + public function getUserBugsTest(string $account, string $type = 'assignedTo', int $limit = 0, int $executionID = 0, int $queryID = 0, string $rawMethod = 'work', string|bool $query = false): array|int { - $array = $this->objectModel->getUserBugs($account, $type); + global $tester; + if($type == 'bySearch') + { + $moduleName = $rawMethod == 'work' ? 'workBug' : 'contributeBug'; + $queryName = $moduleName . 'Query'; + $formName = $moduleName . 'Form'; + if($query) $tester->session->set($queryName, $query); + } + + $array = $this->objectModel->getUserBugs($account, $type, 'id_desc', $limit, null, $executionID, $queryID); if(dao::isError()) { diff --git a/module/bug/test/model/getuserbugs.php b/module/bug/test/model/getuserbugs.php index 9340f10f89..bd8c8a6c88 100755 --- a/module/bug/test/model/getuserbugs.php +++ b/module/bug/test/model/getuserbugs.php @@ -1,27 +1,54 @@ #!/usr/bin/env php gen(100); +zdTable('userquery')->config('userquery')->gen(1); +zdTable('product')->gen(100); + /** title=bugModel->getUserBugs(); cid=1 pid=1 -测试获取用户admin的bug >> 85 -测试获取用户test1的bug >> 85 -测试获取用户test2的bug >> 0 -测试获取用户dev1的bug >> 55 -测试获取用户po1的bug >> 0 - */ -$accountIDList = array('admin', 'test1', 'test2', 'dev1', 'po1'); +$accountIDList = array('admin', 'dev1'); +$typeList = array('assignedTo', 'closedBy', 'all', 'bySearch'); +$limit = array(0, 10); +$execution = array(0, 101); +$queryID = array(0, 1, 1001); +$rawMethod = array('work', 'contributeBug'); +$query = '`id` < 10'; -$bug=new bugTest(); -r($bug->getUserBugsTest($accountIDList[0])) && p() && e('85'); // 测试获取用户admin的bug -r($bug->getUserBugsTest($accountIDList[1])) && p() && e('85'); // 测试获取用户test1的bug -r($bug->getUserBugsTest($accountIDList[2])) && p() && e('0'); // 测试获取用户test2的bug -r($bug->getUserBugsTest($accountIDList[3])) && p() && e('55'); // 测试获取用户dev1的bug -r($bug->getUserBugsTest($accountIDList[4])) && p() && e('0'); // 测试获取用户po1的bug \ No newline at end of file +$bug = new bugTest(); + +r($bug->getUserBugsTest($accountIDList[0], $typeList[0], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('30'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[1], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('30'); // 测试获取用户admin 关闭的 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[2], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('0'); // 测试获取用户admin 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('90'); // 测试获取用户admin 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 没有queryID 没有query值 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[0], $execution[0], $queryID[1], $rawMethod[0])) && p() && e('18'); // 测试获取用户admin 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 有queryID 没有query值 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[0], $execution[0], $queryID[0], $rawMethod[0], $query)) && p() && e('18'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 没有queryID 有query值 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[0], $execution[0], $queryID[1], $rawMethod[0], $query)) && p() && e('18'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为1的 调用方法为work 有queryID 有query值的 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[0], $limit[1], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('10'); // 测试获取用户admin 被指派的 限制数量10的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[1], $execution[0], $queryID[1], $rawMethod[0], $query)) && p() && e('10'); // 测试获取用户admin 被指派的 限制数量10的 executionID为0的 queryID 为1的 调用方法为work 有queryID query值的 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[0], $limit[0], $execution[1], $queryID[0], $rawMethod[0])) && p() && e('3'); // 测试获取用户admin 被指派的 不限制数量的 executionID为101的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[0], $execution[1], $queryID[1], $rawMethod[0], $query)) && p() && e('1'); // 测试获取用户admin 被指派的 不限制数量的 executionID为101的 queryID 为1的 调用方法为work 有queryID query值的 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[0], $limit[0], $execution[0], $queryID[0], $rawMethod[1])) && p() && e('30'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为contributeBug 的bug数量 +r($bug->getUserBugsTest($accountIDList[0], $typeList[3], $limit[0], $execution[0], $queryID[1], $rawMethod[1], $query)) && p() && e('18'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为contributeBug 有queryID query值的 的bug数量 + +r($bug->getUserBugsTest($accountIDList[1], $typeList[0], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('20'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[1], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('0'); // 测试获取用户admin 关闭的 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[2], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('0'); // 测试获取用户admin 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[0], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('0'); // 测试获取用户admin 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 没有queryID 没有query值 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[0], $execution[0], $queryID[1], $rawMethod[0])) && p() && e('0'); // 测试获取用户admin 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 有queryID 没有query值 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[0], $execution[0], $queryID[0], $rawMethod[0], $query)) && p() && e('0'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为work 没有queryID 有query值 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[0], $execution[0], $queryID[1], $rawMethod[0], $query)) && p() && e('0'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为1的 调用方法为work 有queryID 有query值的 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[0], $limit[1], $execution[0], $queryID[0], $rawMethod[0])) && p() && e('10'); // 测试获取用户admin 被指派的 限制数量10的 executionID为0的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[1], $execution[0], $queryID[1], $rawMethod[0], $query)) && p() && e('0'); // 测试获取用户admin 被指派的 限制数量10的 executionID为0的 queryID 为1的 调用方法为work 有queryID query值的 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[0], $limit[0], $execution[1], $queryID[0], $rawMethod[0])) && p() && e('0'); // 测试获取用户admin 被指派的 不限制数量的 executionID为101的 queryID 为0的 调用方法为work 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[0], $execution[1], $queryID[1], $rawMethod[0], $query)) && p() && e('0'); // 测试获取用户admin 被指派的 不限制数量的 executionID为101的 queryID 为1的 调用方法为work 有queryID query值的 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[0], $limit[0], $execution[0], $queryID[0], $rawMethod[1])) && p() && e('20'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为contributeBug 的bug数量 +r($bug->getUserBugsTest($accountIDList[1], $typeList[3], $limit[0], $execution[0], $queryID[1], $rawMethod[1], $query)) && p() && e('0'); // 测试获取用户admin 被指派的 不限制数量的 executionID为0的 queryID 为0的 调用方法为contributeBug 有queryID query值的 的bug数量 diff --git a/module/bug/test/yaml/userquery.yaml b/module/bug/test/yaml/userquery.yaml new file mode 100644 index 0000000000..75f12c0fc2 --- /dev/null +++ b/module/bug/test/yaml/userquery.yaml @@ -0,0 +1,19 @@ +--- +title: zt_userquery +author: Mengyi Liu +version: "1.0" +fields: + - field: form + note: "表单字段" + range: '`a:60:{s:9:\"fieldname\";s:0:\"\";s:11:\"fieldstatus\";s:0:\"\";s:9:\"fielddesc\";s:0:\"\";s:15:\"fieldassignedTo\";s:0:\"\";s:8:\"fieldpri\";s:1:\"0\";s:14:\"fieldexecution\";s:0:\"\";s:11:\"fieldmodule\";s:4:\"ZERO\";s:13:\"fieldestimate\";s:0:\"\";s:9:\"fieldleft\";s:0:\"\";s:13:\"fieldconsumed\";s:0:\"\";s:9:\"fieldtype\";s:0:\"\";s:12:\"fieldfromBug\";s:0:\"\";s:17:\"fieldclosedReason\";s:0:\"\";s:13:\"fieldopenedBy\";s:0:\"\";s:15:\"fieldfinishedBy\";s:0:\"\";s:13:\"fieldclosedBy\";s:0:\"\";s:13:\"fieldcancelBy\";s:1:\"0\";s:17:\"fieldlastEditedBy\";s:0:\"\";s:11:\"fieldmailto\";s:0:\"\";s:17:\"fieldfinishedList\";s:0:\"\";s:15:\"fieldopenedDate\";s:0:\"\";s:13:\"fielddeadline\";s:0:\"\";s:15:\"fieldestStarted\";s:0:\"\";s:16:\"fieldrealStarted\";s:0:\"\";s:17:\"fieldassignedDate\";s:0:\"\";s:17:\"fieldfinishedDate\";s:0:\"\";s:15:\"fieldclosedDate\";s:0:\"\";s:17:\"fieldcanceledDate\";s:0:\"\";s:19:\"fieldlastEditedDate\";s:0:\"\";s:7:\"fieldid\";s:0:\"\";s:15:\"fieldcanceledBy\";s:0:\"\";s:6:\"andOr1\";s:3:\"AND\";s:6:\"field1\";s:4:\"name\";s:9:\"operator1\";s:7:\"include\";s:6:\"value1\";s:2:\"aa\";s:6:\"andOr2\";s:3:\"and\";s:6:\"field2\";s:2:\"id\";s:9:\"operator2\";s:1:\"=\";s:6:\"value2\";s:0:\"\";s:6:\"andOr3\";s:3:\"and\";s:6:\"field3\";s:6:\"status\";s:9:\"operator3\";s:1:\"=\";s:6:\"value3\";s:0:\"\";s:10:\"groupAndOr\";s:3:\"and\";s:6:\"andOr4\";s:3:\"AND\";s:6:\"field4\";s:4:\"desc\";s:9:\"operator4\";s:7:\"include\";s:6:\"value4\";s:0:\"\";s:6:\"andOr5\";s:3:\"and\";s:6:\"field5\";s:10:\"assignedTo\";s:9:\"operator5\";s:1:\"=\";s:6:\"value5\";s:0:\"\";s:6:\"andOr6\";s:3:\"and\";s:6:\"field6\";s:3:\"pri\";s:9:\"operator6\";s:1:\"=\";s:6:\"value6\";s:1:\"0\";s:6:\"module\";s:4:\"task\";s:9:\"actionURL\";s:77:\"/index.php?m=execution&f=task&executionID=101&status=bySearch¶m=myQueryID\";s:10:\"groupItems\";s:1:\"3\";s:8:\"formType\";s:4:\"lite\";}`' + postfix: "" + loop: 0 + format: "" + - field: sql + note: "SQL条件" + range: "(( 1 AND `id` LIKE '%2%' ) AND ( 1 )) AND `deleted` = '0'" + postfix: "" + loop: 0 + format: "" +... +