Files
EasySoft-ZenTaoPMS/module/testcase/zen.php
T

84 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
/**
* The zen file of testcase module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Mengyi Liu <liumengyi@easycorp.ltd>
* @package testcase
* @link https://www.zentao.net
*/
class testcaseZen extends testcase
{
/**
* Assign testcase related variables.
*
* @param object $case
* @param string $from
* @param int $taskID
* @access protected
* @return void
*/
protected function assignCaseForView(object $case, string $from, int $taskID)
{
$case = $this->loadModel('story')->checkNeedConfirm($case);
if($from == 'testtask')
{
$run = $this->loadModel('testtask')->getRunByCase($taskID, $case->id);
$case->assignedTo = $run->assignedTo;
$case->lastRunner = $run->lastRunner;
$case->lastRunDate = $run->lastRunDate;
$case->lastRunResult = $run->lastRunResult;
$case->caseStatus = $case->status;
$case->status = $run->status;
$results = $this->testtask->getResults($run->id);
$result = array_shift($results);
if($result)
{
$case->xml = $result->xml;
$case->duration = $result->duration;
}
}
$case = $this->testcase->appendCaseFails($case, $from, $taskID);
$this->view->runID = $from == 'testcase' ? 0 : $run->id;
$this->view->case = $case;
$this->view->caseFails = $case->caseFails;
$this->view->modulePath = $this->tree->getParents($case->module);
$this->view->caseModule = empty($case->module) ? '' : $this->tree->getById($case->module);
}
/**
* 创建测试用例前检验表单数据是否正确。
* check from data for create case.
*
* @param object $case
* @access protected
* @return bool
*/
protected function checkCreateFormData(object $case): bool
{
$steps = $case->steps;
$expects = $case->expects;
foreach($expects as $key => $value)
{
if(!empty($value) and empty($steps[$key])) dao::$errors['message']["steps$key"] = sprintf($this->lang->testcase->stepsEmpty, $key);
}
if(dao::isError()) return false;
$param = '';
if(!empty($case->lib)) $param = "lib={$case->lib}";
if(!empty($case->product)) $param = "product={$case->product}";
$result = $this->loadModel('common')->removeDuplicate('case', $case, $param);
if($result and $result['stop'])
{
return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->duplicate, $this->lang->testcase->common), 'locate' => $this->createLink('testcase', 'view', "caseID={$result['duplicate']}")));
}
return true;
}
}