From 32ee67bf6ff8de0e7c31f2a01c22bc42e356fc58 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 22 Sep 2023 15:14:26 +0800 Subject: [PATCH] * Refactor testtask::browse. --- module/execution/model.php | 13 +++++ module/execution/test/execution.class.php | 16 ++++++ .../execution/test/model/getpairsbylist.php | 26 ++++++++++ module/testreport/control.php | 46 +++++------------ module/testreport/zen.php | 51 +++++++++++++++++++ module/testtask/model.php | 13 +++++ module/testtask/test/model/getpairsbylist.php | 26 ++++++++++ module/testtask/test/testtask.class.php | 16 ++++++ 8 files changed, 173 insertions(+), 34 deletions(-) create mode 100644 module/execution/test/model/getpairsbylist.php create mode 100644 module/testreport/zen.php create mode 100644 module/testtask/test/model/getpairsbylist.php diff --git a/module/execution/model.php b/module/execution/model.php index 7e00afe5fa..e247ebd2ab 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -4845,4 +4845,17 @@ class executionModel extends model { return $this->dao->select('DISTINCT type')->from(TABLE_EXECUTION)->where('deleted')->eq(0)->andWhere('parent')->eq($parentID)->fetchPairs('type'); } + + /** + * 通过 ID 列表获取执行键对。 + * Get execution pairs by id list. + * + * @param array $executionIdList + * @access public + * @return array + */ + public function getPairsByList(array $executionIdList): array + { + return $this->dao->select('id,name')->from(TABLE_EXECUTION)->where('id')->in($executionIdList)->fetchPairs(); + } } diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index ac3a5ed57c..06f30e7e43 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -3035,4 +3035,20 @@ class executionTest return $this->executionModel->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq('execution')->fetchAll(); } } + + /** + * 测试通过 ID 列表获取执行键对。 + * Test get execution pairs by id list. + * + * @param string $executionIdList + * @access public + * @return string|array + */ + public function getPairsByListTest(string $executionIdList): string|array + { + $executions = $this->executionModel->getPairsByList(explode(',', $executionIdList)); + + if(dao::isError()) return dao::getError(); + return implode(',', $executions); + } } diff --git a/module/execution/test/model/getpairsbylist.php b/module/execution/test/model/getpairsbylist.php new file mode 100644 index 0000000000..95bf3b3ec4 --- /dev/null +++ b/module/execution/test/model/getpairsbylist.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +gen(15); +zdTable('user')->gen(1); +su('admin'); + +/** + +title=测试executionModel->getByIdListTest(); +timeout=0 +cid=1 + +*/ + +$executionIdList = array('1,2,3', '4,5,6', '7,8,9', '10,11,12', '13,14,15'); + +$execution = new executionTest(); + +r($execution->getPairsByListTest($executionIdList[0])) && p() && e('项目集1,项目集2,项目集3'); // 测试查找执行 ID 1 2 3 的名称 +r($execution->getPairsByListTest($executionIdList[1])) && p() && e('项目集4,项目集5,项目集6'); // 测试查找执行 ID 4 5 6 的名称 +r($execution->getPairsByListTest($executionIdList[2])) && p() && e('项目集7,项目集8,项目集9'); // 测试查找执行 ID 7 8 9 的名称 +r($execution->getPairsByListTest($executionIdList[3])) && p() && e('项目集10,项目11,项目12'); // 测试查找执行 ID 10 11 12 的名称 +r($execution->getPairsByListTest($executionIdList[4])) && p() && e('项目13,项目14,项目15'); // 测试查找执行 ID 13 14 15 的名称 diff --git a/module/testreport/control.php b/module/testreport/control.php index 374d30165c..4eca3bb80f 100644 --- a/module/testreport/control.php +++ b/module/testreport/control.php @@ -74,11 +74,12 @@ class testreport extends control } /** + * 浏览测试报告。 * Browse report. * * @param int $objectID * @param string $objectType - * @param string $extra + * @param int $extra * @param string $orderBy * @param int $recTotal * @param int $recPerPage @@ -86,41 +87,22 @@ class testreport extends control * @access public * @return void */ - public function browse($objectID = 0, $objectType = 'product', $extra = '', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function browse(int $objectID = 0, string $objectType = 'product', int $extra = 0, string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1) { - if(strpos('product|execution|project', $objectType) === false) return print('Type Error!'); + if(strpos('product|execution|project', $objectType) === false) return $this->send(array('result' => 'fail', 'message' => 'Type Error!')); $objectID = $this->commonAction($objectID, $objectType); $object = $this->$objectType->getById($objectID); if($extra) $task = $this->testtask->getByID($extra); - $title = $extra ? $task->name : $object->name; - - /* Load pager. */ - $this->app->loadClass('pager', $static = true); - if($this->app->getViewType() == 'mhtml') $recPerPage = 10; - $pager = pager::init($recTotal, $recPerPage, $pageID); - - $reports = $this->testreport->getList($objectID, $objectType, $extra, $orderBy, $pager); - - if(strpos('project|execution', $objectType) !== false and ($extra or isset($_POST['taskIdList']))) - { - $taskIdList = isset($_POST['taskIdList']) ? $_POST['taskIdList'] : array($extra); - foreach($reports as $reportID => $report) - { - $tasks = explode(',', $report->tasks); - if(count($tasks) != count($taskIdList) or array_diff($tasks, $taskIdList)) unset($reports[$reportID]); - } - $pager->setRecTotal(count($reports)); - } - - if(empty($reports) and common::hasPriv('testreport', 'create')) + $reports = $this->testreportZen->getReportsForBrowse($objectID, $objectType, $extra, $orderBy, $recTotal, $recPerPage, $pageID); + if(empty($reports) && common::hasPriv('testreport', 'create')) { $param = ''; - if($objectType == 'product' and $extra) $param = "objectID=$extra&objectType=testtask"; - if(($objectType == 'project' or $objectType == 'execution') and ($extra or !empty($_POST['taskIdList']))) + if($objectType == 'product' && $extra) $param = "objectID={$extra}&objectType=testtask"; + if(strpos('|project|execution|', $objectType) !== false && ($extra || !empty($_POST['taskIdList']))) { - $param = "objectID=$objectID&objectType=$objectType"; + $param = "objectID={$objectID}&objectType={$objectType}"; $param .= isset($_POST['taskIdList']) ? '&extra=' . join(',', $_POST['taskIdList']) : '&extra=' . $extra; } if($param) $this->locate($this->createLink('testreport', 'create', $param)); @@ -135,21 +117,17 @@ class testreport extends control $executions[$report->execution] = $report->execution; foreach(explode(',', $report->tasks) as $taskID) $tasks[$taskID] = $taskID; } - if($executions) $executions = $this->dao->select('id,name')->from(TABLE_PROJECT)->where('id')->in($executions)->fetchPairs(); - if($tasks) $tasks = $this->dao->select('id,name')->from(TABLE_TESTTASK)->where('id')->in($tasks)->fetchPairs('id', 'name'); - - $this->view->title = $title . $this->lang->colon . $this->lang->testreport->common; + $this->view->title = ($extra ? $task->name : $object->name) . $this->lang->colon . $this->lang->testreport->common; $this->view->reports = $reports; $this->view->orderBy = $orderBy; $this->view->objectID = $objectID; $this->view->objectType = $objectType; $this->view->object = $object; $this->view->extra = $extra; - $this->view->pager = $pager; $this->view->users = $this->user->getPairs('noletter|noclosed|nodeleted'); - $this->view->tasks = $tasks; - $this->view->executions = $executions; + $this->view->tasks = $tasks ? $this->loadModel('testtask')->getPairsByList($tasks) : array(); + $this->view->executions = $executions ? $this->loadModel('execution')->getPairsByList($executions) : array(); $this->view->canBeChanged = common::canModify($objectType, $object); // Determines whether an object is editable. $this->display(); } diff --git a/module/testreport/zen.php b/module/testreport/zen.php new file mode 100644 index 0000000000..5bdf21c9bd --- /dev/null +++ b/module/testreport/zen.php @@ -0,0 +1,51 @@ + + * @package testreport + * @link https://www.zentao.net + */ +class testreportZen extends testreport +{ + /** + * Get reports for browse. + * + * @param int $objectID + * @param string $objectType + * @param int $extra + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access protected + * @return array + */ + protected function getReportsForBrowse(int $objectID = 0, string $objectType = 'product', int $extra = 0, string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1): array + { + /* Load pager. */ + $this->app->loadClass('pager', $static = true); + if($this->app->getViewType() == 'mhtml') $recPerPage = 10; + $pager = pager::init($recTotal, $recPerPage, $pageID); + + $reports = $this->testreport->getList($objectID, $objectType, $extra, $orderBy, $pager); + + if(strpos('|project|execution|', $objectType) !== false && ($extra || isset($_POST['taskIdList']))) + { + $taskIdList = isset($_POST['taskIdList']) ? $_POST['taskIdList'] : array($extra); + foreach($reports as $reportID => $report) + { + $tasks = explode(',', $report->tasks); + if(count($tasks) != count($taskIdList) || array_diff($tasks, $taskIdList)) unset($reports[$reportID]); + } + $pager->setRecTotal(count($reports)); + } + + $this->view->pager = $pager; + return $reports; + } +} + diff --git a/module/testtask/model.php b/module/testtask/model.php index 981f54481d..3a649eac0f 100755 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -2568,4 +2568,17 @@ class testtaskModel extends model return array('suites' => $suites, 'cases' => $cases, 'results' => $results, 'suiteNames' => $suiteNames, 'caseTitles' => $caseTitles); } + + /** + * 通过 ID 列表获取测试单键对。 + * Get task pairs by id list. + * + * @param array $taskIdList + * @access public + * @return array + */ + public function getPairsByList(array $taskIdList): array + { + return $this->dao->select('id,name')->from(TABLE_TESTTASK)->where('id')->in($taskIdList)->fetchPairs(); + } } diff --git a/module/testtask/test/model/getpairsbylist.php b/module/testtask/test/model/getpairsbylist.php new file mode 100644 index 0000000000..6449fd0bc4 --- /dev/null +++ b/module/testtask/test/model/getpairsbylist.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +gen(15); +zdTable('user')->gen(1); +su('admin'); + +/** + +title=测试testtaskModel->getByIdListTest(); +timeout=0 +cid=1 + +*/ + +$testtaskIdList = array('1,2,3', '4,5,6', '7,8,9', '10,11,12', '13,14,15'); + +$testtask = new testtaskTest(); + +r($testtask->getPairsByListTest($testtaskIdList[0])) && p() && e('测试单1,测试单2,测试单3'); // 测试查找测试单 ID 1 2 3 的名称 +r($testtask->getPairsByListTest($testtaskIdList[1])) && p() && e('测试单4,测试单5,测试单6'); // 测试查找测试单 ID 4 5 6 的名称 +r($testtask->getPairsByListTest($testtaskIdList[2])) && p() && e('测试单7,测试单8,测试单9'); // 测试查找测试单 ID 7 8 9 的名称 +r($testtask->getPairsByListTest($testtaskIdList[3])) && p() && e('测试单10,测试单11,测试单12'); // 测试查找测试单 ID 10 11 12 的名称 +r($testtask->getPairsByListTest($testtaskIdList[4])) && p() && e('测试单13,测试单14,测试单15'); // 测试查找测试单 ID 13 14 15 的名称 diff --git a/module/testtask/test/testtask.class.php b/module/testtask/test/testtask.class.php index 0d94e49bf1..1fd6a0b73c 100644 --- a/module/testtask/test/testtask.class.php +++ b/module/testtask/test/testtask.class.php @@ -481,4 +481,20 @@ class testtaskTest return $return; } + + /** + * 测试通过 ID 列表获取测试单键对。 + * Test get testtask pairs by id list. + * + * @param string $taskIdList + * @access public + * @return string|array + */ + public function getPairsByListTest(string $taskIdList): string|array + { + $tasks = $this->objectModel->getPairsByList(explode(',', $taskIdList)); + + if(dao::isError()) return dao::getError(); + return implode(',', $tasks); + } }