diff --git a/module/testtask/test/model/unlinkcase.php b/module/testtask/test/model/unlinkcase.php new file mode 100755 index 0000000000..7f82392876 --- /dev/null +++ b/module/testtask/test/model/unlinkcase.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php +gen(4); +zdTable('case')->config('case')->gen(4); +zdTable('projectcase')->config('projectcase')->gen(16); +zdTable('projectstory')->config('projectstory')->gen(8); + +su('admin'); + +/** + +title=测试 testtaskModel->unlinkCase(); +cid=1 +pid=1 + +*/ + +$testtask = new testtaskTest(); + +r($testtask->unlinkCaseTest(1)) && p('run;cases;action:objectType|objectID|action|extra', '|') && e('0;1,2,3,4,1,2,3,4,2,3,4,2,3,4;case|1|unlinkedfromtesttask|1'); // 从测试单 1 中移除用例 1,同时从项目 3 和项目 4 中移除用例1。 +r($testtask->unlinkCaseTest(2)) && p('run;cases;action:objectType|objectID|action|extra', '|') && e('0;1,2,3,4,1,2,3,4,3,4,3,4;case|2|unlinkedfromtesttask|1'); // 从测试单 1 中移除用例 2,同时从项目 3 和项目 4 中移除用例2。 +r($testtask->unlinkCaseTest(3)) && p('run;cases;action:objectType|objectID|action|extra', '|') && e('0;1,2,4,1,2,4,3,4,3,4;case|3|unlinkedfromtesttask|1'); // 从测试单 1 中移除用例 3,同时从项目 1 和项目 2 中移除用例3。 +r($testtask->unlinkCaseTest(4)) && p('run;cases;action:objectType|objectID|action|extra', '|') && e('0;1,2,1,2,3,4,3,4;case|4|unlinkedfromtesttask|1'); // 从测试单 1 中移除用例 4,同时从项目 1 和项目 2 中移除用例4。 + +r($testtask->unlinkCaseTest(5)) && p() && e(0); // 测试轮次不存在返回 false。 diff --git a/module/testtask/test/model/yaml/unlinkcase/case.yaml b/module/testtask/test/model/yaml/unlinkcase/case.yaml new file mode 100644 index 0000000000..3c4635272e --- /dev/null +++ b/module/testtask/test/model/yaml/unlinkcase/case.yaml @@ -0,0 +1,6 @@ +title: table zt_case +author: Gang Liu +version: "1.0" +fields: + - field: story + range: 1-4 diff --git a/module/testtask/test/model/yaml/unlinkcase/projectcase.yaml b/module/testtask/test/model/yaml/unlinkcase/projectcase.yaml new file mode 100644 index 0000000000..68dc05f210 --- /dev/null +++ b/module/testtask/test/model/yaml/unlinkcase/projectcase.yaml @@ -0,0 +1,8 @@ +title: table zt_projectcase +author: Gang Liu +version: "1.0" +fields: + - field: project + range: 1{4},2{4},3{4},4{4} + - field: case + range: 1-4{4!} diff --git a/module/testtask/test/model/yaml/unlinkcase/projectstory.yaml b/module/testtask/test/model/yaml/unlinkcase/projectstory.yaml new file mode 100644 index 0000000000..e5d737bbd9 --- /dev/null +++ b/module/testtask/test/model/yaml/unlinkcase/projectstory.yaml @@ -0,0 +1,8 @@ +title: table zt_projectstory +author: Gang Liu +version: "1.0" +fields: + - field: project + range: "1,1,2,2,3,3,4,4" + - field: story + range: "1,2,1,2,3,4,3,4" diff --git a/module/testtask/test/testtask.class.php b/module/testtask/test/testtask.class.php index 051759664c..444e27bd66 100644 --- a/module/testtask/test/testtask.class.php +++ b/module/testtask/test/testtask.class.php @@ -144,21 +144,15 @@ class testtaskTest */ public function unlinkCaseTest(int $runID): bool|array { - $run = $this->dao->select('t1.task,t1.`case`,t2.story')->from(TABLE_TESTRUN)->alias('t1') - ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') - ->where('t1.id')->eq($runID) - ->fetch(); - $linkedProjects = $this->dao->select('project')->from(TABLE_PROJECTSTORY)->where('story')->eq($run->story)->fetchPairs(); - $result = $this->objectModel->unlinkCase($runID); if(dao::isError()) return dao::getError(); if(!$result) return $result; - $run = $this->objectModel->dao->select('*')->from(TABLE_TESTRUN)->where('id')->eq($runID)->fetch(); - $cases = $this->objectModel->dao->select('`case`')->from(TABLE_PROJECTCASE)->where('project')->in($projects)->fetchPairs(); - $action = $this->objectModel->dao->select('*')->from(TABLE_ACTION)->where('objectType')->eq('case')->andWhere('objectID')->eq($run->case)->andWhere('extra')->eq($run->task)->orderBy('id_desc')->limit(1)->fetch(); + $run = $this->objectModel->dao->select('COUNT(*) AS count')->from(TABLE_TESTRUN)->where('id')->eq($runID)->fetch('count'); + $cases = $this->objectModel->dao->select('project, `case`')->from(TABLE_PROJECTCASE)->fetchAll(); + $action = $this->objectModel->dao->select('*')->from(TABLE_ACTION)->orderBy('id_desc')->limit(1)->fetch(); - return array('run' => $run, 'cases' => implode(',', $cases), 'action' => $action); + return array('run' => $run, 'cases' => implode(',', array_column($cases, 'case')), 'action' => $action); }