* testtask: refactor the linkCase method.
This commit is contained in:
@@ -737,8 +737,10 @@ class testtask extends control
|
||||
{
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$this->testtask->linkCase($taskID, $type);
|
||||
$runs = form::batchData($this->config->testtask->form->linkCase)->get();
|
||||
$this->testtask->linkCase($taskID, $type, $runs);
|
||||
if(dao::isError()) return $this->send(array('result' => 'success', 'message' => dao::getError()));
|
||||
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('cases', "taskID={$taskID}")));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ $(document).off('click', '.batch-btn').on('click', '.batch-btn', function()
|
||||
const form = new FormData();
|
||||
checkedList.forEach((id) =>
|
||||
{
|
||||
form.append('cases[]', id);
|
||||
form.append('versions[' + id + ']', $('#versions' + id).val());
|
||||
form.append('case[]', id);
|
||||
form.append('version[]', $('#version' + id).val());
|
||||
});
|
||||
|
||||
if($(this).hasClass('ajax-btn'))
|
||||
@@ -48,7 +48,7 @@ window.renderCell = function(result, info)
|
||||
if(info.col.name == 'version' && result[0])
|
||||
{
|
||||
const testcase = info.row.data;
|
||||
let html = "<select name='versions[" + testcase.id + "]' id='versions" + testcase.id + "' class='form-control' style='width:60px'>";
|
||||
let html = "<select name='version[" + testcase.id + "]' id='version" + testcase.id + "' class='form-control' style='width:60px'>";
|
||||
for(i = 1; i <= testcase.version; i++)
|
||||
{
|
||||
html += "<option value='" + i + "'>" + i + "</option>";
|
||||
|
||||
+14
-16
@@ -792,30 +792,27 @@ class testtaskModel extends model
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $type
|
||||
* @param array $runs
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function linkCase(int $taskID, string $type, array $cases): bool
|
||||
public function linkCase(int $taskID, string $type, array $runs): bool
|
||||
{
|
||||
if(!$cases) return false;
|
||||
if(!$runs) return false;
|
||||
|
||||
$postData = fixer::input('post')->get();
|
||||
|
||||
$users = array();
|
||||
if($type == 'build' && !empty($postData)) $users = $this->dao->select('`case`, assignedTo')->from(TABLE_TESTRUN)->where('`case`')->in($postData)->fetchPairs();
|
||||
|
||||
$run = new stdclass();
|
||||
$run->task = $taskID;
|
||||
$run->status = 'normal';
|
||||
$users = array();
|
||||
$caseIdList = array_unique(array_filter(array_map(function($run){return $run->case;}, $runs)));
|
||||
if($type == 'build' && $caseIdList) $users = $this->dao->select('`case`, assignedTo')->from(TABLE_TESTRUN)->where('`case`')->in($caseIdList)->fetchPairs();
|
||||
|
||||
$case = new stdclass();
|
||||
$case->product = $this->session->product;
|
||||
$case->version = 1;
|
||||
foreach($cases as $caseID)
|
||||
|
||||
foreach($runs as $run)
|
||||
{
|
||||
$run->case = $caseID;
|
||||
$run->version = $postData->versions[$caseID];
|
||||
$run->assignedTo = zget($users, $caseID, '');
|
||||
$run->task = $taskID;
|
||||
$run->status = 'normal';
|
||||
$run->assignedTo = zget($users, $run->case, '');
|
||||
$this->dao->replace(TABLE_TESTRUN)->data($run)->exec();
|
||||
|
||||
/* 在项目或执行下关联用例到测试单时把用例关联到项目或执行。*/
|
||||
@@ -826,11 +823,12 @@ class testtaskModel extends model
|
||||
$lastOrder = $this->dao->select('MAX(`order`) AS order')->from(TABLE_PROJECTCASE)->where('project')->eq($projectID)->fetch('order');
|
||||
|
||||
$case->project = $projectID;
|
||||
$case->case = $caseID;
|
||||
$case->case = $run->case;
|
||||
$case->order = ++$lastOrder;
|
||||
$this->dao->replace(TABLE_PROJECTCASE)->data($case)->exec();
|
||||
}
|
||||
$this->loadModel('action')->create('case', $caseID, 'linked2testtask', '', $taskID);
|
||||
|
||||
$this->loadModel('action')->create('case', $run->case, 'linked2testtask', '', $taskID);
|
||||
}
|
||||
|
||||
return !dao::isError();
|
||||
|
||||
Reference in New Issue
Block a user