* Refactor testcaseModel::getScenesName, add its unit test, and add default value for function.
This commit is contained in:
+15
-29
@@ -120,7 +120,7 @@ class testcaseModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getExecutionCases(string $browseType = 'all', int $executionID, int $productID = 0, int|string $branchID = 0, int $moduleID = 0, string $orderBy = 'id_desc', object $pager = null): array
|
||||
public function getExecutionCases(string $browseType = 'all', int $executionID = 0, int $productID = 0, int|string $branchID = 0, int $moduleID = 0, string $orderBy = 'id_desc', object $pager = null): array
|
||||
{
|
||||
if($browseType == 'needconfirm')
|
||||
{
|
||||
@@ -2306,46 +2306,32 @@ class testcaseModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景的名称。
|
||||
* Get scene name.
|
||||
*
|
||||
* @param array $moduleIdList
|
||||
* @param bool $allPath
|
||||
* @param bool $branchPath
|
||||
* @param array $sceneIDList
|
||||
* @param bool $fullPath
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getScenesName($moduleIdList, $allPath = true, $branchPath = false)
|
||||
public function getScenesName(array $sceneIDList, bool $fullPath = true): array
|
||||
{
|
||||
if(!$allPath) return $this->dao->select('id, title')->from(VIEW_SCENECASE)->where('id')->in($moduleIdList)->andWhere('deleted')->eq(0)->fetchPairs('id', 'title');
|
||||
if(!$fullPath) return $this->dao->select('id, title')->from(TABLE_SCENE)->where('deleted')->eq('0')->andWhere('id')->in($sceneIDList)->fetchPairs();
|
||||
|
||||
$modules = $this->dao->select('id, title, path, branch')->from(VIEW_SCENECASE)->where('id')->in($moduleIdList)->andWhere('deleted')->eq(0)->fetchAll('path');
|
||||
$allModules = $this->dao->select('id, title')->from(VIEW_SCENECASE)->where('id')->in(join(array_keys($modules)))->andWhere('deleted')->eq(0)->fetchPairs('id', 'title');
|
||||
$scenes = $this->dao->select('id, title, path')->from(TABLE_SCENE)->where('deleted')->eq('0')->andWhere('id')->in($sceneIDList)->fetchAll('path');
|
||||
$allScenes = $this->dao->select('id, title')->from(TABLE_SCENE)->where('deleted')->eq('0')->andWhere('id')->in(implode(',', array_keys($scenes)))->fetchPairs();
|
||||
|
||||
$branchIDList = array();
|
||||
$modulePairs = array();
|
||||
foreach($modules as $module)
|
||||
$scenePairs = array();
|
||||
foreach($scenes as $scene)
|
||||
{
|
||||
$paths = explode(',', trim($module->path, ','));
|
||||
$moduleName = '';
|
||||
foreach($paths as $path) $moduleName .= '/' . $allModules[$path];
|
||||
$modulePairs[$module->id] = $moduleName;
|
||||
$title = '';
|
||||
$path = explode(',', trim($scene->path, ','));
|
||||
foreach($path as $sceneID) $title .= '/' . $allScenes[$sceneID];
|
||||
|
||||
if($module->branch) $branchIDList[$module->branch] = $module->branch;
|
||||
$scenePairs[$scene->id] = $title;
|
||||
}
|
||||
|
||||
if(!$branchPath) return $modulePairs;
|
||||
|
||||
$branchs = $this->dao->select('id, title')->from(VIEW_SCENECASE)->where('id')->in($branchIDList)->andWhere('deleted')->eq(0)->fetchALL('id');
|
||||
foreach($modules as $module)
|
||||
{
|
||||
if(isset($modulePairs[$module->id]))
|
||||
{
|
||||
$branchName = isset($branchs[$module->branch]) ? '/' . $branchs[$module->branch]->name : '';
|
||||
$modulePairs[$module->id] = $branchName . $modulePairs[$module->id];
|
||||
}
|
||||
}
|
||||
|
||||
return $modulePairs;
|
||||
return $scenePairs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/testcase.class.php';
|
||||
|
||||
zdTable('scene')->config('treescene')->gen('20');
|
||||
zdTable('user')->gen('1');
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testcaseModel->getScenesName();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$scenes = $tester->dao->update(TABLE_SCENE)->set("path= replace(`path`,',0,', ',')")->exec();
|
||||
$scenes = $tester->dao->update(TABLE_SCENE)->set("path= replace(`path`,',0,', ',')")->exec();
|
||||
|
||||
$sceneList = array(array(1,2,3), array(9,10,14), array(15,16,17), array(18,19,20));
|
||||
$fullPath = array(true, false);
|
||||
|
||||
$testcase = new testcaseTest();
|
||||
|
||||
r($testcase->getScenesNameTest($sceneList[0])) && p('1,2,3') && e('/这个是测试场景1,/这个是测试场景2,/这个是测试场景3'); // 获取场景 1 2 3 的名称
|
||||
r($testcase->getScenesNameTest($sceneList[1])) && p('9,10,14') && e('/这个是测试场景9,/这个是测试场景10,/这个是测试场景11/这个是测试场景12/这个是测试场景13/这个是测试场景14'); // 获取场景 9 10 14 的名称
|
||||
r($testcase->getScenesNameTest($sceneList[2])) && p('15,16,17') && e('/这个是测试场景11/这个是测试场景15,/这个是测试场景16,/这个是测试场景16/这个是测试场景17'); // 获取场景 15 16 17 的名称
|
||||
r($testcase->getScenesNameTest($sceneList[3])) && p('18,19,20') && e('/这个是测试场景18,/这个是测试场景18/这个是测试场景19,/这个是测试场景18/这个是测试场景19/这个是测试场景20'); // 获取场景 18 19 20 的名称
|
||||
|
||||
r($testcase->getScenesNameTest($sceneList[0], $fullPath[0])) && p('1,2,3') && e('/这个是测试场景1,/这个是测试场景2,/这个是测试场景3'); // 获取场景 1 2 3 的 全 名称
|
||||
r($testcase->getScenesNameTest($sceneList[1], $fullPath[0])) && p('9,10,14') && e('/这个是测试场景9,/这个是测试场景10,/这个是测试场景11/这个是测试场景12/这个是测试场景13/这个是测试场景14'); // 获取场景 9 10 14 的 全 名称
|
||||
r($testcase->getScenesNameTest($sceneList[2], $fullPath[0])) && p('15,16,17') && e('/这个是测试场景11/这个是测试场景15,/这个是测试场景16,/这个是测试场景16/这个是测试场景17'); // 获取场景 15 16 17 的 全 名称
|
||||
r($testcase->getScenesNameTest($sceneList[3], $fullPath[0])) && p('18,19,20') && e('/这个是测试场景18,/这个是测试场景18/这个是测试场景19,/这个是测试场景18/这个是测试场景19/这个是测试场景20'); // 获取场景 18 19 20 的 全 名称
|
||||
|
||||
r($testcase->getScenesNameTest($sceneList[0], $fullPath[1])) && p('1,2,3') && e('这个是测试场景1,这个是测试场景2,这个是测试场景3'); // 获取场景 1 2 3 的 非全 名称
|
||||
r($testcase->getScenesNameTest($sceneList[1], $fullPath[1])) && p('9,10,14') && e('这个是测试场景9,这个是测试场景10,这个是测试场景14'); // 获取场景 9 10 14 的 非全 名称
|
||||
r($testcase->getScenesNameTest($sceneList[2], $fullPath[1])) && p('15,16,17') && e('这个是测试场景15,这个是测试场景16,这个是测试场景17'); // 获取场景 15 16 17 的 非全 名称
|
||||
r($testcase->getScenesNameTest($sceneList[3], $fullPath[1])) && p('18,19,20') && e('这个是测试场景18,这个是测试场景19,这个是测试场景20'); // 获取场景 18 19 20 的 非全 名称
|
||||
@@ -141,7 +141,7 @@ class testcaseTest
|
||||
* @access public
|
||||
* @return array|int
|
||||
*/
|
||||
public function getExecutionCasesTest(string $browseType = '', int $executionID): array|int
|
||||
public function getExecutionCasesTest(string $browseType = '', int $executionID = 0): array|int
|
||||
{
|
||||
$objects = $this->objectModel->getExecutionCases($browseType, $executionID);
|
||||
|
||||
@@ -1346,4 +1346,19 @@ class testcaseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return implode(',', $idList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取所有的子场景 id。
|
||||
* Test get all children id.
|
||||
*
|
||||
* @param array $sceneIdList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getScenesNameTest(array $sceneIdList, bool $fullPath = true): array
|
||||
{
|
||||
$return = $this->objectModel->getScenesName($sceneIdList, $fullPath);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ fields:
|
||||
- field: path
|
||||
fields:
|
||||
- field: path1
|
||||
range: 1-11,11{4},15,16,18,18{3}
|
||||
range: 1-11,11{4},16{2},18,18{3}
|
||||
prefix: ","
|
||||
postfix: ","
|
||||
- field: path2
|
||||
|
||||
Reference in New Issue
Block a user