* Refactor the getStatus function.

This commit is contained in:
daitingting
2023-09-01 09:39:53 +00:00
parent 2bd31e6fca
commit 3b2115ae80
2 changed files with 92 additions and 86 deletions
-83
View File
@@ -2316,89 +2316,6 @@ class testcaseModel extends model
}
}
/**
* Get status for different method.
*
* @param string $methodName
* @param object $case
* @access public
* @return mixed string | bool | array
*/
public function getStatus($methodName, $case = null)
{
if($methodName == 'create')
{
if($this->forceNotReview() || !$this->post->needReview) return 'normal';
return 'wait';
}
if($methodName == 'review')
{
$status = zget($case, 'status', '');
if($this->post->result == 'pass') return 'normal';
return $status;
}
if($methodName == 'update')
{
if(!empty($_POST['lastEditedDate']) and $case->lastEditedDate != $this->post->lastEditedDate)
{
dao::$errors[] = $this->lang->error->editedByOther;
return false;
}
$status = $this->post->status ? $this->post->status : $case->status;
$stepChanged = false;
$steps = array();
/* ---------------- Judge steps changed or not.-------------------- */
/* Remove the empty setps in post. */
if($this->post->steps)
{
$data = fixer::input('post')->get();
foreach($data->steps as $key => $desc)
{
$desc = trim($desc);
$stepType = isset($data->stepType[$key]) ? $data->stepType[$key] : 'step';
if(!empty($desc)) $steps[] = array('desc' => $desc, 'type' => $stepType, 'expect' => trim(zget($data->expects, $key, '')));
}
/* If step count changed, case changed. */
if(count($case->steps) != count($steps))
{
$stepChanged = true;
}
else
{
/* Compare every step. */
$i = 0;
foreach($case->steps as $key => $oldStep)
{
if(trim($oldStep->desc) != trim($steps[$i]['desc']) or trim($oldStep->expect) != $steps[$i]['expect'] or trim($oldStep->type) != $steps[$i]['type'])
{
$stepChanged = true;
break;
}
$i++;
}
}
}
if(!$this->forceNotReview() and $stepChanged) $status = 'wait';
if(!empty($_POST['title']) and $case->title != $this->post->title) $stepChanged = true;
if(!empty($_POST['precondition']) and $case->precondition != $this->post->precondition) $stepChanged = true;
return array($stepChanged, $status);
}
return '';
}
/**
* processDatas
*