* Refactor testsuiteModel::getCanImportCases, and add its unit test.
This commit is contained in:
@@ -308,20 +308,17 @@ class testsuiteModel extends model
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->session->testsuiteQuery == false) $this->session->set('testsuiteQuery', ' 1 = 1');
|
||||
if($this->session->testsuiteQuery === false) $this->session->set('testsuiteQuery', ' 1 = 1');
|
||||
}
|
||||
|
||||
$query = $this->session->testsuiteQuery;
|
||||
$allLib = "`lib` = 'all'";
|
||||
$withAllLib = strpos($query, $allLib) !== false;
|
||||
if($withAllLib) $query = str_replace($allLib, 1, $query);
|
||||
if(!$withAllLib) $query .= " AND `lib` = '$libID'";
|
||||
$query = strpos($query, $allLib) !== false ? str_replace($allLib, '1 = 1', $query) : "{$query} AND `lib` = '{$libID}'";
|
||||
}
|
||||
|
||||
|
||||
$this->loadModel('branch');
|
||||
$product = $this->loadModel('product')->getById($productID);
|
||||
$branches = $product->type != 'normal' ? array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active') : array(0);
|
||||
$product = $this->loadModel('product')->getById($productID);
|
||||
$branches = $branch === 'all' && $product->type != 'normal' ? array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active') : array($product->type == 'normal' ? 0 : $branch => '');
|
||||
$canImport = array();
|
||||
foreach($branches as $branchID => $branchName) $canImport += $this->getCanImportModules($productID, $libID, $branchID);
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/testsuite.class.php';
|
||||
|
||||
zdTable('product')->gen(45);
|
||||
zdTable('branch')->gen(20);
|
||||
zdTable('case')->config('case')->gen(50);
|
||||
zdTable('module')->config('module')->gen(50);
|
||||
zdTable('userquery')->config('userquery')->gen(1);
|
||||
zdTable('user')->gen(1);
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testsuiteModel->getCanImportCases();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
|
||||
*/
|
||||
|
||||
$productIdList = array(1, 41);
|
||||
$libIdList = array(0, 1);
|
||||
$branchList = array('all', 1);
|
||||
$orderByList = array('id_desc', 'id_asc');
|
||||
$browseTypeList = array('', 'bysearch');
|
||||
$queryIdList = array(0, 1);
|
||||
$testsuiteQuery = array(false, "`lib` = 'all'");
|
||||
|
||||
$testsuite = new testsuiteTest();
|
||||
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[0], $orderByList[0])) && p() && e('29,27,25,23,21'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[1], $branchList[0], $orderByList[0])) && p() && e('30,28,26,24,22'); // 测试获取产品 1 用例库 1 分支 all 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[1], $orderByList[0])) && p() && e('29,27,25,23,21'); // 测试获取产品 1 用例库 0 分支 1 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[1], $branchList[1], $orderByList[0])) && p() && e('30,28,26,24,22'); // 测试获取产品 1 用例库 1 分支 1 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[0], $orderByList[1])) && p() && e('21,23,25,27,29'); // 测试获取产品 1 用例库 0 分支 all 排序 id_asc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[1], $branchList[1], $orderByList[1])) && p() && e('22,24,26,28,30'); // 测试获取产品 1 用例库 1 分支 1 排序 id_asc 可以导入的用例
|
||||
|
||||
r($testsuite->getCanImportCasesTest($productIdList[1], $libIdList[0], $branchList[0], $orderByList[0])) && p() && e('29,27,25,23,21'); // 测试获取产品 41 用例库 0 分支 all 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[1], $libIdList[1], $branchList[0], $orderByList[0])) && p() && e('30,28,26,24,22'); // 测试获取产品 41 用例库 1 分支 all 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[1], $libIdList[0], $branchList[1], $orderByList[0])) && p() && e('29,27,25,23,21'); // 测试获取产品 41 用例库 0 分支 1 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[1], $libIdList[1], $branchList[1], $orderByList[0])) && p() && e('30,28,26,24,22'); // 测试获取产品 41 用例库 1 分支 1 排序 id_desc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[1], $libIdList[0], $branchList[0], $orderByList[1])) && p() && e('21,23,25,27,29'); // 测试获取产品 41 用例库 0 分支 all 排序 id_asc 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[1], $libIdList[1], $branchList[1], $orderByList[1])) && p() && e('22,24,26,28,30'); // 测试获取产品 41 用例库 1 分支 1 排序 id_asc 可以导入的用例
|
||||
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[0], $orderByList[0], $browseTypeList[1], $queryIdList[0], $testsuiteQuery[0])) && p() && e('29,27,25,23,21'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 0 testsuiteQuery false 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[0], $orderByList[0], $browseTypeList[1], $queryIdList[1], $testsuiteQuery[0])) && p() && e('0'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 1 testsuiteQuery false 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[0], $orderByList[0], $browseTypeList[1], $queryIdList[0], $testsuiteQuery[1])) && p() && e('29,27,25,23,21'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 0 testsuiteQuery "`lib` = 'all'" 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[0], $orderByList[0], $browseTypeList[1], $queryIdList[1], $testsuiteQuery[1])) && p() && e('0'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 1 testsuiteQuery "`lib` = 'all'" 可以导入的用例
|
||||
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[1], $orderByList[0], $browseTypeList[1], $queryIdList[0], $testsuiteQuery[0])) && p() && e('29,27,25,23,21'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 0 testsuiteQuery false 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[1], $orderByList[0], $browseTypeList[1], $queryIdList[1], $testsuiteQuery[0])) && p() && e('0'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 1 testsuiteQuery false 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[1], $orderByList[0], $browseTypeList[1], $queryIdList[0], $testsuiteQuery[1])) && p() && e('29,27,25,23,21'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 0 testsuiteQuery "`lib` = 'all'" 可以导入的用例
|
||||
r($testsuite->getCanImportCasesTest($productIdList[0], $libIdList[0], $branchList[1], $orderByList[0], $browseTypeList[1], $queryIdList[1], $testsuiteQuery[1])) && p() && e('0'); // 测试获取产品 1 用例库 0 分支 all 排序 id_desc browseType bysearch queryID 1 testsuiteQuery "`lib` = 'all'" 可以导入的用例
|
||||
@@ -130,7 +130,7 @@ class testsuiteTest
|
||||
$suite->name = $name;
|
||||
$suite->desc = $desc;
|
||||
$suite->type = $type;
|
||||
|
||||
|
||||
if(!empty($uid))
|
||||
{
|
||||
global $tester;
|
||||
@@ -140,13 +140,13 @@ class testsuiteTest
|
||||
$objects = $this->objectModel->update($suite, $uid);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
|
||||
foreach($objects as &$object)
|
||||
{
|
||||
if($object['field'] == 'desc') $object['result'] = $object['new'] == $desc;
|
||||
}
|
||||
|
||||
return $objects;
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,12 +185,12 @@ class testsuiteTest
|
||||
$objects = $this->objectModel->getLinkedCases($suiteID, $orderBy, $pager, $append);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
|
||||
if(!$append)
|
||||
{
|
||||
foreach($objects as $object) $object->results = 'a';
|
||||
}
|
||||
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
@@ -280,4 +280,30 @@ class testsuiteTest
|
||||
{
|
||||
return $this->objectModel->deleteCaseBySuiteID($cases, $suiteID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取可以导入的用例。
|
||||
* Test get can import cases.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param int $libID
|
||||
* @param int|string $branch
|
||||
* @param string $orderBy
|
||||
* @param string $browseType
|
||||
* @param int $queryID
|
||||
* @param bool|string $testsuiteQuery
|
||||
* @access public
|
||||
* @return string|array
|
||||
*/
|
||||
public function getCanImportCasesTest(int $productID, int $libID, int|string $branch, string $orderBy = 'id_desc', string $browseType = '', int $queryID = 0, bool|string $testsuiteQuery = false): string|array
|
||||
{
|
||||
global $tester;
|
||||
$tester->session->set('testsuiteQuery', $testsuiteQuery);
|
||||
|
||||
$objects = $this->objectModel->getCanImportCases($productID, $libID, $branch, $orderBy, null, $browseType, $queryID);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return implode(',', array_keys($objects));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
title: table zt_testcase
|
||||
desc: "测试用例"
|
||||
author: Mengyi Liu
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: product
|
||||
range: 1{10},41{10},0{10}
|
||||
- field: branch
|
||||
range: 0{10},1{5},0{15}
|
||||
- field: module
|
||||
range: 0{5},1{5},0{5},12{5},0{5},23{5}
|
||||
- field: lib
|
||||
range: 0,1
|
||||
- field: fromCaseID
|
||||
range: 21-25,0{2 5}
|
||||
@@ -0,0 +1,11 @@
|
||||
title: table zt_module
|
||||
desc: "模块"
|
||||
author: Mengyi Liu
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: root
|
||||
range: 1{10},41{10},0{10}
|
||||
- field: branch
|
||||
range: 0{10},1{5},0{15}
|
||||
- field: type
|
||||
range: case
|
||||
@@ -0,0 +1,7 @@
|
||||
title: table zt_userquery
|
||||
desc: "用户查询"
|
||||
author: Mengyi Liu
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: sql
|
||||
range: "(1=1 AND `product` = '1')"
|
||||
Reference in New Issue
Block a user