* Refactor testtask::browse.

This commit is contained in:
liumengyi
2023-09-22 15:14:26 +08:00
parent 01f4b9e36f
commit 32ee67bf6f
8 changed files with 173 additions and 34 deletions
+13
View File
@@ -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();
}
}
+16
View File
@@ -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);
}
}
@@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/execution.class.php';
zdTable('project')->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 的名称
+12 -34
View File
@@ -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();
}
+51
View File
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* The zen file of testreport module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Mengyi Liu <liumengyi@easycorp.ltd>
* @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;
}
}
+13
View File
@@ -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();
}
}
@@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/testtask.class.php';
zdTable('testtask')->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 的名称
+16
View File
@@ -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);
}
}