diff --git a/module/testcase/model.php b/module/testcase/model.php index 9b30e9d850..74997fc0fa 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -106,44 +106,6 @@ class testcaseModel extends model ->fetchAll('id'); } - /** - * Get project cases of a module. - * - * @param int $productID - * @param int|string $branch - * @param int $moduleIdList - * @param string $browseType - * @param string $auto no|unit - * @param string $caseType - * @param string $orderBy - * @param object $pager - * @access public - * @return array - */ - public function getModuleProjectCases($productID, $branch = 0, $moduleIdList = 0, $browseType = '', $auto = 'no', $caseType = '', $orderBy = 'id_desc', $pager = null) - { - $executions = $this->loadModel('execution')->getIdList($this->session->project); - array_push($executions, $this->session->project); - - return $this->dao->select('distinct t1.*, t2.*, t4.title as storyTitle')->from(TABLE_PROJECTCASE)->alias('t1') - ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') - ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t3.story=t2.story') - ->leftJoin(TABLE_STORY)->alias('t4')->on('t3.story=t4.id') - ->where('t1.project')->in($executions) - ->beginIF(!empty($productID))->andWhere('t2.product')->eq((int)$productID)->fi() - ->beginIF(!empty($productID) and $branch !== 'all')->andWhere('t2.branch')->eq($branch)->fi() - ->beginIF($moduleIdList)->andWhere('t2.module')->in($moduleIdList)->fi() - ->beginIF($browseType == 'all')->andWhere('t2.scene')->eq(0)->fi() - ->beginIF($browseType == 'wait')->andWhere('t2.status')->eq($browseType)->fi() - ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t1.auto')->eq($auto)->fi() - ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() - ->beginIF($caseType)->andWhere('t2.type')->eq($caseType)->fi() - ->andWhere('t2.deleted')->eq('0') - ->orderBy($orderBy) - ->page($pager, 't1.`case`') - ->fetchAll('id'); - } - /** * Get project cases. * diff --git a/module/testcase/tao.php b/module/testcase/tao.php index 0e8bcc2a57..2d4da30878 100644 --- a/module/testcase/tao.php +++ b/module/testcase/tao.php @@ -45,6 +45,45 @@ class testcaseTao extends testcaseModel ->fetchGroup('case'); } + /** + * 获取某个项目下某个模块的用例列表。 + * Get project cases of a module. + * + * @param int $productID + * @param int|string $branch + * @param int $moduleIdList + * @param string $browseType + * @param string $auto no|unit + * @param string $caseType + * @param string $orderBy + * @param object $pager + * @access protected + * @return array + */ + protected function getModuleProjectCases(int $productID, int|string $branch = 0, int|array $moduleIdList = 0, string $browseType = '', string $auto = 'no', string $caseType = '', string $orderBy = 'id_desc', object $pager = null): array + { + $executions = $this->loadModel('execution')->getIdList((int)$this->session->project); + array_push($executions, $this->session->project); + + return $this->dao->select('distinct t1.*, t2.*, t4.title AS storyTitle')->from(TABLE_PROJECTCASE)->alias('t1') + ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id') + ->leftJoin(TABLE_PROJECTSTORY)->alias('t3')->on('t3.story = t2.story') + ->leftJoin(TABLE_STORY)->alias('t4')->on('t3.story = t4.id') + ->where('t1.project')->in($executions) + ->beginIF(!empty($productID))->andWhere('t2.product')->eq($productID)->fi() + ->beginIF(!empty($productID) && $branch !== 'all')->andWhere('t2.branch')->eq($branch)->fi() + ->beginIF($moduleIdList)->andWhere('t2.module')->in($moduleIdList)->fi() + ->beginIF($browseType == 'all')->andWhere('t2.scene')->eq(0)->fi() + ->beginIF($browseType == 'wait')->andWhere('t2.status')->eq($browseType)->fi() + ->beginIF($auto == 'auto' || $auto == 'unit')->andWhere('t2.auto')->eq($auto)->fi() + ->beginIF($auto != 'auto' && $auto != 'unit')->andWhere('t2.auto')->ne('unit')->fi() + ->beginIF($caseType)->andWhere('t2.type')->eq($caseType)->fi() + ->andWhere('t2.deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager, 't1.`case`') + ->fetchAll('id'); + } + /** * 获取待确认的用例列表。 * Get need fonfirm list. diff --git a/module/testcase/test/model/getmoduleprojectcases.php b/module/testcase/test/model/getmoduleprojectcases.php deleted file mode 100755 index 80586302a6..0000000000 --- a/module/testcase/test/model/getmoduleprojectcases.php +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env php -getModuleProjectCases(); -cid=1 -pid=1 - -测试获取产品1的case >> 这个是测试用例1;这个是测试用例2;这个是测试用例3;这个是测试用例4 -测试获取产品1 module 1821 1822 的case >> 0 -测试获取产品2的case >> 这个是测试用例5;这个是测试用例6;这个是测试用例7;这个是测试用例8 -测试获取产品2 module 1825 2827 的case >> 0 -测试获取产品3的case >> 这个是测试用例9;这个是测试用例10;这个是测试用例11;这个是测试用例12 -测试获取产品3 module 1829 2832 的case >> 0 -测试获取产品4的case >> 这个是测试用例13;这个是测试用例14;这个是测试用例15;这个是测试用例16 -测试获取产品4 module 1834 2835 的case >> 0 -测试获取产品5的case >> 这个是测试用例17;这个是测试用例18;这个是测试用例19;这个是测试用例20 -测试获取产品5 module 1838 2840 的case >> 0 - -*/ -$productIDList = array(1, 2, 3, 4, 5); -$branch = 0; -$moduleIDList = array('1821,1822', '1825,1827', '1829,1832', '1834,2835', '1838,1840'); - -$testcase = new testcaseTest(); - -r($testcase->getModuleProjectCasesTest($productIDList[0])) && p('1:title;2:title;3:title;4:title') && e('这个是测试用例1;这个是测试用例2;这个是测试用例3;这个是测试用例4'); // 测试获取产品1的case -r($testcase->getModuleProjectCasesTest($productIDList[0], $branch, $moduleIDList[0])) && p() && e('0'); // 测试获取产品1 module 1821 1822 的case -r($testcase->getModuleProjectCasesTest($productIDList[1])) && p('5:title;6:title;7:title;8:title') && e('这个是测试用例5;这个是测试用例6;这个是测试用例7;这个是测试用例8'); // 测试获取产品2的case -r($testcase->getModuleProjectCasesTest($productIDList[1], $branch, $moduleIDList[1])) && p() && e('0'); // 测试获取产品2 module 1825 2827 的case -r($testcase->getModuleProjectCasesTest($productIDList[2])) && p('9:title;10:title;11:title;12:title') && e('这个是测试用例9;这个是测试用例10;这个是测试用例11;这个是测试用例12'); // 测试获取产品3的case -r($testcase->getModuleProjectCasesTest($productIDList[2], $branch, $moduleIDList[2])) && p() && e('0'); // 测试获取产品3 module 1829 2832 的case -r($testcase->getModuleProjectCasesTest($productIDList[3])) && p('13:title;14:title;15:title;16:title') && e('这个是测试用例13;这个是测试用例14;这个是测试用例15;这个是测试用例16'); // 测试获取产品4的case -r($testcase->getModuleProjectCasesTest($productIDList[3], $branch, $moduleIDList[3])) && p() && e('0'); // 测试获取产品4 module 1834 2835 的case -r($testcase->getModuleProjectCasesTest($productIDList[4])) && p('17:title;18:title;19:title;20:title') && e('这个是测试用例17;这个是测试用例18;这个是测试用例19;这个是测试用例20'); // 测试获取产品5的case -r($testcase->getModuleProjectCasesTest($productIDList[4], $branch, $moduleIDList[4])) && p() && e('0'); // 测试获取产品5 module 1838 2840 的case \ No newline at end of file diff --git a/module/testcase/test/tao/getmoduleprojectcases.php b/module/testcase/test/tao/getmoduleprojectcases.php new file mode 100755 index 0000000000..0e6d8cb4ac --- /dev/null +++ b/module/testcase/test/tao/getmoduleprojectcases.php @@ -0,0 +1,63 @@ +#!/usr/bin/env php +product->range('1-2'); + $caseData->module->range('1{5},2{5}'); + + $caseData->gen(10); + + $projectCase = zdTable('projectcase'); + $projectCase->project->range('1'); + $projectCase->product->range('1-2'); + $projectCase->case->range('1-10'); + + $projectCase->gen(10); +} + +initData(); + +/** + +title=测试 testcaseModel->getModuleProjectCases(); +timeout=0 +cid=1 + +- 测试获取产品1的case + - 第1条的title属性 @这个是测试用例1 + - 第3条的title属性 @这个是测试用例3 + - 第5条的title属性 @这个是测试用例5 + - 第7条的title属性 @这个是测试用例7 + - 第9条的title属性 @这个是测试用例9 +- 测试获取产品1,模块1的case + - 第1条的title属性 @这个是测试用例1 + - 第3条的title属性 @这个是测试用例3 + - 第5条的title属性 @这个是测试用例5 +- 测试获取产品2的case + - 第2条的title属性 @这个是测试用例2 + - 第4条的title属性 @这个是测试用例4 + - 第6条的title属性 @这个是测试用例6 + - 第8条的title属性 @这个是测试用例8 + - 第10条的title属性 @这个是测试用例10 +- 测试获取产品2,模块2的case + - 第6条的title属性 @这个是测试用例6 + - 第8条的title属性 @这个是测试用例8 + - 第10条的title属性 @这个是测试用例10 + +*/ + +$productIDList = array(1, 2); +$branch = 0; +$moduleIDList = array(array(1), array(2)); + +$testcase = new testcaseTest(); + +r($testcase->getModuleProjectCasesTest($productIDList[0])) && p('1:title;3:title;5:title;7:title;9:title') && e('这个是测试用例1;这个是测试用例3;这个是测试用例5;这个是测试用例7;这个是测试用例9'); // 测试获取产品1的case +r($testcase->getModuleProjectCasesTest($productIDList[0], $branch, $moduleIDList[0])) && p('1:title;3:title;5:title') && e('这个是测试用例1;这个是测试用例3;这个是测试用例5'); // 测试获取产品1,模块1的case +r($testcase->getModuleProjectCasesTest($productIDList[1])) && p('2:title;4:title;6:title;8:title;10:title') && e('这个是测试用例2;这个是测试用例4;这个是测试用例6;这个是测试用例8;这个是测试用例10'); // 测试获取产品2的case +r($testcase->getModuleProjectCasesTest($productIDList[1], $branch, $moduleIDList[1])) && p('6:title;8:title;10:title') && e('这个是测试用例6;这个是测试用例8;这个是测试用例10'); // 测试获取产品2,模块2的case \ No newline at end of file diff --git a/module/testcase/test/testcase.class.php b/module/testcase/test/testcase.class.php index 90311a981c..7fd7997cdc 100644 --- a/module/testcase/test/testcase.class.php +++ b/module/testcase/test/testcase.class.php @@ -107,21 +107,24 @@ class testcaseTest } /** + * 测试获取某个项目的某个模块的用例。 * Test get project cases of a module. * - * @param int $productID - * @param int $branch - * @param int $moduleIdList - * @param string $browseType - * @param string $auto - * @param string $caseType - * @param string $orderBy - * @param object $pager + * @param int $productID + * @param int|string $branch + * @param int|array $moduleIdList + * @param string $browseType + * @param string $auto + * @param string $caseType + * @param string $orderBy + * @param object $pager * @access public * @return array */ - public function getModuleProjectCasesTest($productID, $branch = 0, $moduleIdList = 0, $browseType = '', $auto = 'no', $caseType = '', $orderBy = 'id_desc', $pager = null) + public function getModuleProjectCasesTest(int $productID, int|string $branch = 0, int|array $moduleIdList = 0, string $browseType = '', string $auto = 'no', string $caseType = '', string $orderBy = 'id_desc', object $pager = null): array { + $_SESSION['project'] = 1; + $objects = $this->objectModel->getModuleProjectCases($productID, $branch, $moduleIdList, $browseType, $auto, $caseType, $orderBy, $pager); if(dao::isError()) return dao::getError();