From 59fd03260a4c3a8539bf4baafa35d4e86b31f7c3 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 2 Jun 2023 16:45:37 +0800 Subject: [PATCH] * Refactor bugModel-getUserBugPairs, and modify its unit test. --- module/bug/model.php | 7 +++-- module/bug/test/bug.class.php | 10 +++++-- module/bug/test/model/getuserbugpairs.php | 34 +++++++++++++++-------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index 3aa063579b..1b5152ca90 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -873,9 +873,10 @@ class bugModel extends model } /** + * 测试获取用户的bugs的 id => title 数组。 * Get bug pairs of a user. * - * @param int $account + * @param string $account * @param bool $appendProduct * @param int $limit * @param array $skipProductIdList @@ -884,9 +885,9 @@ class bugModel extends model * @access public * @return array */ - public function getUserBugPairs($account, $appendProduct = true, $limit = 0, $skipProductIdList = array(), $skipExecutionIdList = array(), $appendBugID = 0) + public function getUserBugPairs(string $account, bool $appendProduct = true, int $limit = 0, array $skipProductIdList = array(), array $skipExecutionIdList = array(), array|int $appendBugID = 0): array { - $deletedProjectIdList = $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(1)->fetchPairs('id', 'id'); + $deletedProjectIdList = $this->dao->select('id')->from(TABLE_PROJECT)->where('deleted')->eq(1)->fetchPairs(); $bugs = array(); $stmt = $this->dao->select('t1.id, t1.title, t2.name as product') diff --git a/module/bug/test/bug.class.php b/module/bug/test/bug.class.php index 68eeb76c76..74bb6c5bd8 100644 --- a/module/bug/test/bug.class.php +++ b/module/bug/test/bug.class.php @@ -589,15 +589,21 @@ class bugTest } /** + * 测试获取取用户的bugs的 id => title 数组。 * Test get bug pairs of a user. * * @param string $account + * @param bool $appendProduct + * @param int $limit + * @param array $skipProductIdList + * @param array $skipExecutionIdList + * @param int|array $appendBugID * @access public * @return array */ - public function getUserBugPairsTest($account) + public function getUserBugPairsTest(string $account, bool $appendProduct = true, int $limit = 0, array $skipProductIdList = array(), array $skipExecutionIdList = array(), array|int $appendBugID = 0): array|int { - $array = $this->objectModel->getUserBugPairs($account); + $array = $this->objectModel->getUserBugPairs($account, $appendProduct, $limit, $skipProductIdList, $skipExecutionIdList, $appendBugID); if(dao::isError()) { diff --git a/module/bug/test/model/getuserbugpairs.php b/module/bug/test/model/getuserbugpairs.php index 88e8a96869..836852ef02 100755 --- a/module/bug/test/model/getuserbugpairs.php +++ b/module/bug/test/model/getuserbugpairs.php @@ -1,27 +1,37 @@ #!/usr/bin/env php gen(100); +zdTable('product')->gen(100); + /** title=bugModel->getUserBugPairs(); cid=1 pid=1 -测试获取用户admin的bug >> 85 -测试获取用户test1的bug >> 65 -测试获取用户test2的bug >> 0 -测试获取用户dev1的bug >> 55 -测试获取用户po1的bug >> 0 - */ $accountIDList = array('admin', 'test1', 'test2', 'dev1', 'po1'); +$appendProduct = array(true, false); +$limit = array(0, 10); +$skipProductIdList = array(array(), array(2, 4)); +$skipExecutionIdList = array(array(), array(11, 13)); +$appendBugID = array(array(), array(2, 4)); + $bug=new bugTest(); -r($bug->getUserBugPairsTest($accountIDList[0])) && p() && e('85'); // 测试获取用户admin的bug -r($bug->getUserBugPairsTest($accountIDList[1])) && p() && e('65'); // 测试获取用户test1的bug -r($bug->getUserBugPairsTest($accountIDList[2])) && p() && e('0'); // 测试获取用户test2的bug -r($bug->getUserBugPairsTest($accountIDList[3])) && p() && e('55'); // 测试获取用户dev1的bug -r($bug->getUserBugPairsTest($accountIDList[4])) && p() && e('0'); // 测试获取用户po1的bug \ No newline at end of file +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('30'); // 测试获取用户admin 的bug +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[1], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('30'); // 测试获取用户admin 追加产品名称 的bug +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[0], $limit[1], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('10'); // 测试获取用户admin 限制数量10 的bug +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[0], $limit[0], $skipProductIdList[1], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('24'); // 测试获取用户admin 跳过产品2 4 的bug +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[1], $appendBugID[0])) && p() && e('30'); // 测试获取用户admin 跳过执行 11 13 的bug +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[1])) && p() && e('30'); // 测试获取用户admin 追加bug 2 4 的bug +r($bug->getUserBugPairsTest($accountIDList[0], $appendProduct[1], $limit[1], $skipProductIdList[1], $skipExecutionIdList[1], $appendBugID[1])) && p() && e('10'); // 测试获取用户admin 追加产品名称 限制数量10 跳过产品2 4 跳过执行 11 13 追加bug 2 4 的bug + +r($bug->getUserBugPairsTest($accountIDList[1], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('20'); // 测试获取用户test1的bug +r($bug->getUserBugPairsTest($accountIDList[2], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('0'); // 测试获取用户test2的bug +r($bug->getUserBugPairsTest($accountIDList[3], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('20'); // 测试获取用户dev1的bug +r($bug->getUserBugPairsTest($accountIDList[4], $appendProduct[0], $limit[0], $skipProductIdList[0], $skipExecutionIdList[0], $appendBugID[0])) && p() && e('0'); // 测试获取用户po1的bug