diff --git a/module/testtask/control.php b/module/testtask/control.php index 1fcae3d374..fbb3322147 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -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}"))); } diff --git a/module/testtask/js/linkcase.ui.js b/module/testtask/js/linkcase.ui.js index 71e484365a..b8507ab15b 100644 --- a/module/testtask/js/linkcase.ui.js +++ b/module/testtask/js/linkcase.ui.js @@ -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 = ""; for(i = 1; i <= testcase.version; i++) { html += ""; diff --git a/module/testtask/model.php b/module/testtask/model.php index 6ccec49dbb..4a67fd2499 100755 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -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();