* Refactor getByStatus function.

This commit is contained in:
daitingting
2023-09-13 01:38:56 +00:00
parent ef12fe5868
commit 0f09511c19
3 changed files with 77 additions and 61 deletions
+22 -15
View File
@@ -381,36 +381,43 @@ class testcaseModel extends model
}
/**
* Get cases by type
* 根据状态获取用例。
* Get cases by status.
*
* @param int $productID
* @param int $branch
* @param string $type all|needconfirm
* @param string $status all|normal|blocked|investigate
* @param int $moduleID
* @param string $orderBy
* @param object $pager
* @param string $auto no|unit|skip
* @param int $productID
* @param int|string $branch
* @param string $type all|needconfirm
* @param string $status all|normal|blocked|investigate
* @param int $moduleID
* @param string $auto no|unit|skip
* @param string $orderBy
* @param object $pager
* @access public
* @return array
*/
public function getByStatus($productID = 0, $branch = 0, $type = 'all', $status = 'all', $moduleID = 0, $orderBy = 'id_desc', $pager = null, $auto = 'no')
public function getByStatus(int $productID = 0, int|string $branch = 0, string $type = 'all', string $status = 'all', int $moduleID = 0, string $auto = 'no', string $orderBy = 'id_desc', object $pager = null): array
{
$modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0';
$cases = $this->dao->select('t1.*, t2.title as storyTitle')->from(TABLE_CASE)->alias('t1')
$cases = $this->dao->select('t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1')
->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id')
->beginIF($productID)->where('t1.product')->eq((int) $productID)->fi()
->beginIF($productID == 0)->where('t1.product')->in($this->app->user->view->products)->fi()
->where('1=1')
->beginIF($productID)->andWhere('t1.product')->eq((int) $productID)->fi()
->beginIF(!$productID)->andWhere('t1.product')->in($this->app->user->view->products)->fi()
->beginIF($branch)->andWhere('t1.branch')->eq($branch)->fi()
->beginIF($modules)->andWhere('t1.module')->in($modules)->fi()
->beginIF($type == 'needconfirm')->andWhere("t2.status = 'active'")->andWhere('t2.version > t1.storyVersion')->fi()
->beginIF($type == 'needconfirm')
->andWhere('t2.status')->eq('active')
->andWhere('t2.version > t1.storyVersion')
->fi()
->beginIF($status != 'all')->andWhere('t1.status')->eq($status)->fi()
->beginIF($auto == 'unit')->andWhere('t1.auto')->eq('unit')->fi()
->beginIF($auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi()
->andWhere('t1.deleted')->eq('0')
->orderBy($orderBy)->page($pager)
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
return $this->appendData($cases);
}
+41 -33
View File
@@ -4,28 +4,36 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/testcase.class.php';
su('admin');
function initData()
{
$caseData = zdTable('case');
$caseData->gen(10);
}
initData();
/**
title=测试 testcaseModel->getByStatus();
timeout=0
cid=1
pid=1
测试查询所有产品 所有状态的case >> 400
测试查询产品1 所有状态的case >> 4
测试查询产品2 所有状态的case >> 4
测试查询所有产品 type needconfirm 的case >> 100
测试查询所有产品 状态 wait 的case >> 100
测试查询所有产品 状态 normal 的case >> 100
测试查询所有产品 状态 blocked 的case >> 100
测试查询所有产品 状态 investigate 的case >> 100
测试查询产品1 状态 wait 的case >> 1
测试查询产品1 状态 normal 的case >> 1
测试查询产品1 状态 blocked 的case >> 1
测试查询产品1 状态 investigate 的case >> 1
测试查询产品2 状态 wait 的case >> 1
测试查询产品2 状态 normal 的case >> 1
测试查询产品2 状态 blocked 的case >> 1
测试查询产品2 状态 investigate 的case >> 1
- 测试查询所有产品 所有状态的case @10
- 测试查询产品1 所有状态的case @4
- 测试查询产品2 所有状态的case @4
- 测试查询所有产品 type needconfirm 的case @3
- 测试查询所有产品 状态 wait 的case @3
- 测试查询所有产品 状态 normal 的case @3
- 测试查询所有产品 状态 blocked 的case @2
- 测试查询所有产品 状态 investigate 的case @2
- 测试查询产品1 状态 wait 的case @1
- 测试查询产品1 状态 normal 的case @1
- 测试查询产品1 状态 blocked 的case @1
- 测试查询产品1 状态 investigate 的case @1
- 测试查询产品2 状态 wait 的case @1
- 测试查询产品2 状态 normal 的case @1
- 测试查询产品2 状态 blocked 的case @1
- 测试查询产品2 状态 investigate 的case @1
*/
$productIDList = array('0', '1', '2');
@@ -35,19 +43,19 @@ $statusList = array('wait', 'normal', 'blocked', 'investigate');
$testcase = new testcaseTest();
r($testcase->getByStatusTest()) && p() && e('400'); // 测试查询所有产品 所有状态的case
r($testcase->getByStatusTest($productIDList[1])) && p() && e('4'); // 测试查询产品1 所有状态的case
r($testcase->getByStatusTest($productIDList[2])) && p() && e('4'); // 测试查询产品2 所有状态的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[1], $statusList[0])) && p() && e('100'); // 测试查询所有产品 type needconfirm 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[0])) && p() && e('100'); // 测试查询所有产品 状态 wait 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[1])) && p() && e('100'); // 测试查询所有产品 状态 normal 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[2])) && p() && e('100'); // 测试查询所有产品 状态 blocked 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[3])) && p() && e('100'); // 测试查询所有产品 状态 investigate 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[0])) && p() && e('1'); // 测试查询产品1 状态 wait 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[1])) && p() && e('1'); // 测试查询产品1 状态 normal 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[2])) && p() && e('1'); // 测试查询产品1 状态 blocked 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[3])) && p() && e('1'); // 测试查询产品1 状态 investigate 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[0])) && p() && e('1'); // 测试查询产品2 状态 wait 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[1])) && p() && e('1'); // 测试查询产品2 状态 normal 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[2])) && p() && e('1'); // 测试查询产品2 状态 blocked 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[3])) && p() && e('1'); // 测试查询产品2 状态 investigate 的case
r($testcase->getByStatusTest()) && p() && e('10'); // 测试查询所有产品 所有状态的case
r($testcase->getByStatusTest($productIDList[1])) && p() && e('4'); // 测试查询产品1 所有状态的case
r($testcase->getByStatusTest($productIDList[2])) && p() && e('4'); // 测试查询产品2 所有状态的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[1], $statusList[0])) && p() && e('3'); // 测试查询所有产品 type needconfirm 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[0])) && p() && e('3'); // 测试查询所有产品 状态 wait 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[1])) && p() && e('3'); // 测试查询所有产品 状态 normal 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[2])) && p() && e('2'); // 测试查询所有产品 状态 blocked 的case
r($testcase->getByStatusTest($productIDList[0], $branch, $typeList[0], $statusList[3])) && p() && e('2'); // 测试查询所有产品 状态 investigate 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[0])) && p() && e('1'); // 测试查询产品1 状态 wait 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[1])) && p() && e('1'); // 测试查询产品1 状态 normal 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[2])) && p() && e('1'); // 测试查询产品1 状态 blocked 的case
r($testcase->getByStatusTest($productIDList[1], $branch, $typeList[0], $statusList[3])) && p() && e('1'); // 测试查询产品1 状态 investigate 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[0])) && p() && e('1'); // 测试查询产品2 状态 wait 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[1])) && p() && e('1'); // 测试查询产品2 状态 normal 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[2])) && p() && e('1'); // 测试查询产品2 状态 blocked 的case
r($testcase->getByStatusTest($productIDList[2], $branch, $typeList[0], $statusList[3])) && p() && e('1'); // 测试查询产品2 状态 investigate 的case
+14 -13
View File
@@ -265,24 +265,25 @@ class testcaseTest
}
/**
* Test get cases by type.
* 测试根据状态获取用例。
* Test get cases by status.
*
* @param int $productID
* @param int $branch
* @param string $type
* @param string $status
* @param int $moduleID
* @param string $orderBy
* @param object $pager
* @param string $auto
* @param int $productID
* @param int|string $branch
* @param string $type
* @param string $status
* @param int $moduleID
* @param string $orderBy
* @param object $pager
* @param string $auto
* @access public
* @return int
* @return int|bool
*/
public function getByStatusTest($productID = 0, $branch = 0, $type = 'all', $status = 'all', $moduleID = 0, $orderBy = 'id_desc', $pager = null, $auto = 'no')
public function getByStatusTest(int $productID = 0, int|string $branch = 0, string $type = 'all', string $status = 'all', int $moduleID = 0, string $auto = 'no', string $orderBy = 'id_desc', object $pager = null): int|bool
{
$objects = $this->objectModel->getByStatus($productID, $branch, $type, $status, $moduleID, $orderBy, $pager, $auto);
$objects = $this->objectModel->getByStatus($productID, $branch, $type, $status, $moduleID, $auto, $orderBy, $pager);
if(dao::isError()) return dao::getError();
if(dao::isError()) return false;
return count($objects);
}