* Test unlinkCaseFromTesttask.

This commit is contained in:
daitingting
2023-09-15 02:45:19 +00:00
parent 130f4def9e
commit 52ac0252a6
4 changed files with 60 additions and 4 deletions
+2 -2
View File
@@ -608,7 +608,7 @@ class testcaseModel extends model
if(isset($oldCase->toBugs) && isset($case->linkBug)) $this->testcaseTao->linkBugs($oldCase->id, array_keys($oldCase->toBugs), $case);
if($case->branch && !empty($testtasks)) $this->testcaseTao->unlinkCaseFromTesttask($oldCase->id, $testtasks);
if($case->branch && !empty($testtasks)) $this->testcaseTao->unlinkCaseFromTesttask($oldCase->id, $case->branch, $testtasks);
$this->loadModel('file')->processFile4Object('testcase', $oldCase, $case);
@@ -644,7 +644,7 @@ class testcaseModel extends model
$changes = common::createChanges($oldCase, $case);
if(!empty($changes))
{
$actionID = $this->loadModel('action')->create('case', $caseID, 'Reviewed', $case->comment, ucfirst($case->result));
$actionID = $this->loadModel('action')->create('case', $oldCase->id, 'Reviewed', $case->comment, ucfirst($case->result));
$this->action->logHistory($actionID, $changes);
}
return true;
+4 -2
View File
@@ -495,17 +495,19 @@ class testcaseTao extends testcaseModel
* @access protected
* @return bool
*/
protected function unlinkCaseFromTesttask($caseID, $testtasks): bool
protected function unlinkCaseFromTesttask(int $caseID, int $branch, array $testtasks): bool
{
$this->loadModel('action');
foreach($testtasks as $taskID => $testtask)
{
if($testtask->branch != $case->branch && $taskID)
if($testtask->branch != $branch && $taskID)
{
$this->dao->delete()->from(TABLE_TESTRUN)->where('task')->eq($taskID)->andWhere('`case`')->eq($caseID)->exec();
$this->action->create('case' ,$caseID, 'unlinkedfromtesttask', '', $taskID);
}
}
return !dao::isError();
}
/**
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/testcase.class.php';
su('admin');
zdTable('testrun')->gen(10);
/**
title=测试 testcaseTao->unlinkCaseFromTesttask();
timeout=0
cid=1
- 测试取消测试单与用例的关联。 @0
*/
$caseID = 1;
$branch = 1;
$testcase = new testcaseTest();
r($testcase->unlinkCaseFromTesttaskTest($caseID, $branch)) && p() && e(0); //测试取消测试单与用例的关联。
+31
View File
@@ -879,6 +879,37 @@ class testcaseTest
return $bugs;
}
/**
* 测试测试单取消关联用例。
* Test unlink case from testtask.
*
* @param int $caseID
* @param int $branch
* @param array $testtasks
* @access public
* @return bool|int
*/
public function unlinkCaseFromTesttaskTest(int $caseID, int $branch): bool|int
{
global $tester;
$testtasks = $tester->loadModel('testtask')->getGroupByCases($caseID);
$testtasks = empty($testtasks[$caseID]) ? array() : $testtasks[$caseID];
foreach($testtasks as $testtaskID => $testtask)
{
if($testtask->branch == $branch) unset($testtasks[$testtaskID]);
}
if(empty($testtasks)) return true;
$this->objectModel->unlinkCaseFromTesttask($caseID, $branch, $testtasks);
if(dao::isError()) return false;
return $tester->dao->select('count(*) AS count')->from(TABLE_TESTRUN)->where('`case`')->eq($caseID)->andWhere('task')->in(array_keys($testtasks))->fetch('count');
}
/**
* Test get status for different method.
*