* Refactor testcase::groupCase, and add testcaseZen::getGroupCases.

This commit is contained in:
liumengyi
2023-08-25 11:06:52 +08:00
parent 96700f95cf
commit 975357c2ba
3 changed files with 61 additions and 45 deletions
+12 -44
View File
@@ -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;
+1 -1
View File
@@ -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();
+48
View File
@@ -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.