From 975357c2ba9aef2fe2cb0d5f292564855f924cc2 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 25 Aug 2023 11:06:52 +0800 Subject: [PATCH] * Refactor testcase::groupCase, and add testcaseZen::getGroupCases. --- module/testcase/control.php | 56 +++++++----------------------- module/testcase/ui/header.html.php | 2 +- module/testcase/zen.php | 48 +++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index 5f9e2198ee..fc0425d96a 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -115,6 +115,7 @@ class testcase extends control } /** + * 分组查看用例。 * Group case. * * @param int $productID @@ -127,64 +128,31 @@ class testcase extends control */ public function groupCase(int $productID = 0, string $branch = '', string $groupBy = 'story', int $projectID = 0, string $caseType = '') { - $groupBy = empty($groupBy) ? 'story' : $groupBy; + /* 设置SESSION和COOKIE,获取产品信息。 */ + /* Set session and cookie, and get product. */ $productID = $this->product->saveState($productID, $this->products); $product = $this->product->getByID($productID); - if($branch === '') $branch = $this->cookie->preBranch; - - $this->app->loadLang('testtask'); - - $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch); - if($this->app->tab == 'project') - { - $products = array('0' => $this->lang->product->all) + $this->product->getProducts($this->session->project, 'all', '', false); - if(!$product->shadow) $this->lang->modulePageNav = $this->product->select($products, $productID, 'testcase', 'groupCase', $projectID, $branch); - } - $this->session->set('caseList', $this->app->getURI(true), $this->app->tab); - $cases = $this->testcase->getModuleCases($productID, $branch, 0, '', 'no', $caseType, $groupBy); - $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', false); - $cases = $this->loadModel('story')->checkNeedConfirm($cases); - $cases = $this->testcase->appendData($cases); + if($branch === '') $branch = $this->cookie->preBranch; + if(empty($groupBy)) $groupBy = 'story'; - $groupCases = array(); - foreach($cases as $case) - { - if($groupBy == 'story') $groupCases[$case->story][] = $case; - } - - $story = null; - foreach($cases as $index => $case) - { - if($case->storyDeleted) - { - unset($cases[$index]); - continue; - } - $case->rowspan = 0; - if($story !== $case->story) - { - $story = $case->story; - if(!empty($groupCases[$case->story])) $case->rowspan = count($groupCases[$case->story]); - } - } - - $this->app->loadLang('execution'); - $this->app->loadLang('task'); + /* 设置菜单。 */ + /* Set menu. */ + if($this->app->tab == 'project') $this->loadModel('project')->setMenu((int)$this->session->project); + if($this->app->tab == 'qa') $this->testcase->setMenu($this->products, $productID, $branch); + /* 展示变量. */ + /* Show the variables. */ $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->common; $this->view->projectID = $projectID; $this->view->productID = $productID; - $this->view->productName = $this->products[$productID]; $this->view->users = $this->user->getPairs('noletter'); $this->view->browseType = 'group'; $this->view->groupBy = $groupBy; $this->view->orderBy = $groupBy; - $this->view->cases = $cases; + $this->view->cases = $this->testcaseZen->getGroupCases($productID, $branch, $groupBy, $caseType); $this->view->suiteList = $this->loadModel('testsuite')->getSuites($productID); - $this->view->suiteID = 0; - $this->view->moduleID = 0; $this->view->branch = $branch; $this->view->caseType = $caseType; $this->view->product = $product; diff --git a/module/testcase/ui/header.html.php b/module/testcase/ui/header.html.php index 91794740e1..c98e357232 100644 --- a/module/testcase/ui/header.html.php +++ b/module/testcase/ui/header.html.php @@ -192,7 +192,7 @@ featureBar $rawMethod != 'browseunits' && $rawMethod != 'groupcase' ? (searchToggle(set::open($browseType == 'bysearch'))) : null ); -$viewItems = array(array('text' => $lang->testcase->listView, 'url' => inlink('browse', "productID=$productID&branch=$branch&browseType=all"), 'active' => $rawMethod != 'groupcase' ? true : false)); +$viewItems = array(array('text' => $lang->testcase->listView, 'url' => $app->tab == 'project' ? createLink('project', 'testcase', "projectID={$projectID}") : inlink('browse', "productID=$productID&branch=$branch&browseType=all"), 'active' => $rawMethod != 'groupcase' ? true : false)); $exportItems = array(); $importItems = array(); $createItems = array(); diff --git a/module/testcase/zen.php b/module/testcase/zen.php index a8b216d9cf..14c2b97d4a 100644 --- a/module/testcase/zen.php +++ b/module/testcase/zen.php @@ -936,6 +936,54 @@ class testcaseZen extends testcase return $case; } + /** + * 获取分组用例。 + * Get group cases. + * + * @param int $productID + * @param string $branch + * @param string $groupBy + * @param string $caseType + * @access protected + * @return array + */ + protected function getGroupCases(int $productID, string $branch, string $groupBy, string $caseType): array + { + /* 获取用例。 */ + /* Get cases. */ + $cases = $this->testcase->getModuleCases($productID, $branch, 0, '', 'no', $caseType, $groupBy); + $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', false); + $cases = $this->loadModel('story')->checkNeedConfirm($cases); + $cases = $this->testcase->appendData($cases); + + /* 获取用例的需求分组。 */ + /* Get story groups of cases. */ + $groupCases = array(); + if($groupBy == 'story') + { + foreach($cases as $case) $groupCases[$case->story][] = $case; + } + + /* 设置用例的需求分组的行占比。 */ + /* Set row span of story group in cases. */ + $story = null; + foreach($cases as $index => $case) + { + if($case->storyDeleted) + { + unset($cases[$index]); + continue; + } + $case->rowspan = 0; + if($story !== $case->story) + { + $story = $case->story; + if(!empty($groupCases[$case->story])) $case->rowspan = count($groupCases[$case->story]); + } + } + return $cases; + } + /** * 创建完 testcase 后的相关处理。 * Relevant processing after create testcase.