From 348b956c5b63e83ec04924502841cc2a59934b34 Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 18 Sep 2023 15:57:42 +0800 Subject: [PATCH] * testtask: refactor the linkCase method. --- module/testtask/control.php | 88 ++++++++-------------------- module/testtask/ui/linkcase.html.php | 17 +++--- 2 files changed, 34 insertions(+), 71 deletions(-) diff --git a/module/testtask/control.php b/module/testtask/control.php index c8b5724578..5b94ba58e4 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -795,6 +795,7 @@ class testtask extends control } /** + * 关联测试用例到一个测试单。 * Link cases to a test task. * * @param int $taskID @@ -806,7 +807,7 @@ class testtask extends control * @access public * @return void */ - public function linkCase($taskID, $type = 'all', $param = 0, $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function linkCase(int $taskID, string $type = 'all', int $param = 0, int $recTotal = 0, int $recPerPage = 20, int $pageID = 1) { if(!empty($_POST)) { @@ -815,78 +816,41 @@ class testtask extends control return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('cases', "taskID={$taskID}"))); } + /* 保存部分内容到 session 中供后面使用。*/ /* Save session. */ $this->session->set('caseList', $this->app->getURI(true), 'qa'); - /* Get task and product id. */ - $task = $this->testtask->getByID($taskID); - $productID = $this->loadModel('product')->checkAccess($task->product, $this->products); - $product = $this->product->getByID($productID); + /* 获取测试单信息。*/ + /* Get testtask info. */ + $task = $this->testtask->getByID($taskID); - if(!isset($this->products[$productID])) $this->products[$productID] = $product->name; + /* 检查是否有权限访问测试单所属产品。*/ + /* Check if user have permission to access the product to which the testtask belongs. */ + $productID = $this->loadModel('product')->checkAccess($task->product, $this->products); $this->testtaskZen->setMenu($productID, $task->branch, $task->project, $task->execution); + $this->testtaskZen->setSearchParamsForLinkCase($product, $task, $type, $param); - /* Load pager. */ + /* 如果测试单所属产品在产品键值对中不存在,将其加入。*/ + /* Prepare the product key-value pairs. */ + $product = $this->product->getByID($productID); + if(!isset($this->products[$productID])) $this->products[$productID] = $product->name; + + /* 从数据库中查询一个测试单下可以关联的测试用例。*/ + /* Query the cases that can be associated with a testtask from the database. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); - - /* Build the search form. */ - $this->loadModel('testcase'); - $this->config->testcase->search['params']['product']['values'] = array($productID => $this->products[$productID]); - $this->config->testcase->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $task->branch); - $this->config->testcase->search['actionURL'] = inlink('linkcase', "taskID=$taskID&type=$type¶m=$param"); - $this->config->testcase->search['params']['scene']['values'] = $this->testcase->getSceneMenu($productID, 0, $viewType = 'case', $startSceneID = 0, 0); - $this->config->testcase->search['style'] = 'simple'; - - $build = $this->loadModel('build')->getByID($task->build); - $stories = array(); - if($build) - { - $stories = $this->dao->select('id,title')->from(TABLE_STORY)->where('id')->in($build->stories)->fetchPairs(); - $this->config->testcase->search['params']['story']['values'] = $stories; - $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story'); - } - - if($product->shadow) unset($this->config->testcase->search['fields']['product']); - if($type != 'bystory') - { - unset($this->config->testcase->search['fields']['story']); - unset($this->config->testcase->search['params']['story']); - } - if($task->productType == 'normal') - { - unset($this->config->testcase->search['fields']['branch']); - unset($this->config->testcase->search['params']['branch']); - } - else - { - $this->config->testcase->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$task->productType]); - $branchName = $this->loadModel('branch')->getById($task->branch); - $branches = array('' => '', BRANCH_MAIN => $this->lang->branch->main, $task->branch => $branchName); - $this->config->testcase->search['params']['branch']['values'] = $branches; - } - - if(!$this->config->testcase->needReview) unset($this->config->testcase->search['params']['status']['values']['wait']); - $this->loadModel('search')->setSearchParams($this->config->testcase->search); - - $this->view->title = $task->name . $this->lang->colon . $this->lang->testtask->linkCase; - - $testTask = $this->testtask->getRelatedTestTasks($productID, $taskID); - - /* Get cases. */ $cases = $this->testtask->getLinkableCases($productID, $task, $taskID, $type, $param, $pager); - $this->view->users = $this->loadModel('user')->getPairs('noletter'); - $this->view->cases = $cases; - $this->view->taskID = $taskID; - $this->view->testTask = $testTask; - $this->view->pager = $pager; - $this->view->task = $task; - $this->view->type = $type; - $this->view->param = $param; - $this->view->suiteList = $this->loadModel('testsuite')->getSuites($task->product); - + $this->view->title = $task->name . $this->lang->colon . $this->lang->testtask->linkCase; + $this->view->users = $this->loadModel('user')->getPairs('noletter'); + $this->view->suites = $this->loadModel('testsuite')->getSuites($task->product); + $this->view->relatedTasks = $this->testtask->getRelatedTestTasks($productID, $taskID); + $this->view->cases = $cases; + $this->view->task = $task; + $this->view->type = $type; + $this->view->param = $param; + $this->view->pager = $pager; $this->display(); } diff --git a/module/testtask/ui/linkcase.html.php b/module/testtask/ui/linkcase.html.php index 5c08c1b30c..0bef62b61b 100644 --- a/module/testtask/ui/linkcase.html.php +++ b/module/testtask/ui/linkcase.html.php @@ -16,9 +16,9 @@ foreach($lang->testtask->featureBar['linkcase'] as $key => $label) $isActive = $key == $type; if($key == 'bysuite' || $key == 'bybuild') { - if($isActive) $label = $key == 'bysuite' ? $suiteList[$param]->name : zget($testTask, $param); + if($isActive) $label = $key == 'bysuite' ? $suites[$param]->name : zget($relatedTasks, $param); $subItems = array(); - $dataList = $key == 'bysuite' ? $suiteList : $testTask; + $dataList = $key == 'bysuite' ? $suites : $relatedTasks; if($dataList) { foreach($dataList as $dataID => $data) @@ -29,7 +29,7 @@ foreach($lang->testtask->featureBar['linkcase'] as $key => $label) ( 'text' => $text, 'active' => $key == $type && $dataID == $param, - 'url' => createLink('testtask', 'linkCase', "taskID={$taskID}&type={$key}¶m={$dataID}"), + 'url' => createLink('testtask', 'linkCase', "taskID={$task->id}&type={$key}¶m={$dataID}"), 'badge' => $dataID == $param && !empty($pager->recTotal) ? array('text' => $pager->recTotal, 'class' => 'size-sm rounded-full white') : null, 'props' => ['data-id' => $text, 'data-load' => 'table'] ); @@ -56,7 +56,7 @@ foreach($lang->testtask->featureBar['linkcase'] as $key => $label) ( 'text' => $label, 'active' => $isActive, - 'url' => createLink('testtask', 'linkCase', "taskID={$taskID}&type={$key}"), + 'url' => createLink('testtask', 'linkCase', "taskID={$task->id}&type={$key}"), 'badge' => $isActive && !empty($pager->recTotal) ? array('text' => $pager->recTotal, 'class' => 'size-sm rounded-full white') : null, 'props' => ['data-id' => $label, 'data-load' => 'table'] ); @@ -66,14 +66,14 @@ featureBar ( set::items($items), set::current($type), - set::linkParams("taskID=$taskID&type={key}"), + set::linkParams("taskID={$task->id}&type={key}"), to::before(backBtn(set::icon('back'), set::className('btn secondary'), $lang->goback)), li(searchToggle()) ); $footToolbar = array('items' => array ( - array('text' => $lang->save, 'className' => 'batch-btn ajax-btn', 'data-url' => helper::createLink('testtask', 'linkCase', "taskID={$taskID}&type={$type}¶m={$param}")) + array('text' => $lang->save, 'className' => 'batch-btn ajax-btn', 'data-url' => helper::createLink('testtask', 'linkCase', "taskID={$task->id}&type={$type}¶m={$param}")) ), 'btnProps' => array('size' => 'sm', 'btnType' => 'secondary')); div @@ -86,12 +86,11 @@ div $lang->testtask->unlinkedCases . "({$pager->recTotal})" ) ); -$cases = initTableData($cases, $config->testtask->linkcase->dtable->fieldList, $this->testcase); -$data = array_values($cases); + dtable ( set::userMap($users), - set::data($data), + set::data(array_values($cases)), set::cols($config->testtask->linkcase->dtable->fieldList), set::fixedLeftWidth('33%'), set::checkable(true),