diff --git a/module/company/view/browse.html.php b/module/company/view/browse.html.php index c520efe63d..0826dd1668 100644 --- a/module/company/view/browse.html.php +++ b/module/company/view/browse.html.php @@ -54,7 +54,7 @@ include '../../common/view/tablesorter.html.php'; - id;?> + id) . $user->id;?> account", $user->realname)) echo $user->realname;?> account;?> user->roleList[$user->role];?> @@ -74,7 +74,17 @@ include '../../common/view/tablesorter.html.php'; - show()?> + + + +show(); +?> + + + diff --git a/module/testcase/js/browse.js b/module/testcase/js/browse.js index 35110b2c15..d08d71b613 100644 --- a/module/testcase/js/browse.js +++ b/module/testcase/js/browse.js @@ -20,6 +20,11 @@ function browseBySearch(active) $('#bymoduleTab').removeClass('active'); } +function changeAction(url) +{ + $('#batchForm').attr('action', url); +} + $(document).ready(function() { $("a.runcase").colorbox({width:900, height:600, iframe:true, transition:'none'}); diff --git a/module/testcase/view/browse.html.php b/module/testcase/view/browse.html.php index f69d0050dc..c7ef260825 100644 --- a/module/testcase/view/browse.html.php +++ b/module/testcase/view/browse.html.php @@ -18,7 +18,6 @@ var browseType = ''; var moduleID = ''; -
';
'>
-
'>
@@ -52,6 +50,7 @@ var moduleID = ''; recTotal}&recPerPage={$pager->recPerPage}"; ?> + '> @@ -108,8 +107,10 @@ var moduleID = '';
- testcase->batchEdit); + testcase->batchEdit, "onclick='changeAction(\"" . inLink('batchEdit', "from=testcaseBrowse&productID=$productID&orderBy=$orderBy") . "\")'"); + if(common::hasPriv('testtask', 'batchRun')) echo html::submitButton($lang->testtask->batchRun, "onclick='changeAction(\"" . $this->createLink('testtask', 'batchRun', "productID=$productID&orderBy=$orderBy") . "\")'"); ?>
show();?> diff --git a/module/testtask/control.php b/module/testtask/control.php index 8c151aacc2..d4cfd0e04b 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -448,6 +448,53 @@ class testtask extends control die($this->display()); } + /** + * Batch run case. + * + * @param int $productID + * @param string $orderBy + * @param string $from + * @access public + * @return void + */ + public function batchRun($productID, $orderBy = 'id_desc', $from = 'testcase') + { + if(isset($_POST['caseIDList'])) + { + if($from == 'testcase') $this->view->cases = $this->dao->select('*')->from(TABLE_CASE)->where('id')->in($this->post->caseIDList)->orderBy($orderBy)->fetchAll('id'); + if($from == 'testtask') + { + $this->view->cases = $this->dao->select('t1.*,t2.lastRunResult')->from(TABLE_CASE)->alias('t1') + ->leftJoin(TABLE_TESTRUN)->alias('t2')->on('t1.id = t2.case') + ->where('t1.id')->in($this->post->caseIDList) + ->orderBy($orderBy) + ->fetchAll('id'); + } + } + else + { + $this->testtask->batchRun($from); + $method = $from == 'testcase' ? 'browse' : 'cases'; + die(js::locate($this->createLink($from, $method, "productID=$productID"), 'parent')); + } + $this->app->loadLang('testcase'); + $this->testtask->setMenu($this->products, $productID); + + $resultList = $this->lang->testcase->resultList; + unset($resultList['n/a']); + + $steps = $this->dao->select('t1.*')->from(TABLE_CASESTEP)->alias('t1') + ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') + ->where('t2.id')->in($this->post->caseIDList) + ->andWhere('t1.version=t2.version') + ->fetchGroup('case', 'id'); + + $this->view->moduleOptionMenu = $this->loadModel('tree')->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0); + $this->view->resultList = $resultList; + $this->view->steps = $steps; + $this->display(); + } + /** * View test results of a test run. * diff --git a/module/testtask/lang/en.php b/module/testtask/lang/en.php index fdaa02fbec..9af6d39cd8 100644 --- a/module/testtask/lang/en.php +++ b/module/testtask/lang/en.php @@ -20,6 +20,7 @@ $lang->testtask->linkCaseAB = "Link"; $lang->testtask->unlinkCase = "Del"; $lang->testtask->batchAssign = "Batch Assign"; $lang->testtask->runCase = "Run"; +$lang->testtask->batchRun = "Batch Run"; $lang->testtask->results = "Result"; $lang->testtask->createBug = "Bug(+)"; $lang->testtask->assign = 'Assign'; diff --git a/module/testtask/lang/zh-cn.php b/module/testtask/lang/zh-cn.php index 535c1947ab..27162d16f0 100644 --- a/module/testtask/lang/zh-cn.php +++ b/module/testtask/lang/zh-cn.php @@ -20,6 +20,7 @@ $lang->testtask->linkCaseAB = "关联"; $lang->testtask->unlinkCase = "移除"; $lang->testtask->batchAssign = "批量指派"; $lang->testtask->runCase = "执行"; +$lang->testtask->batchRun = "批量执行"; $lang->testtask->results = "结果"; $lang->testtask->createBug = "提Bug"; $lang->testtask->assign = '指派'; diff --git a/module/testtask/model.php b/module/testtask/model.php index 682179a04f..72142b57ee 100644 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -302,6 +302,73 @@ class testtaskModel extends model } } + /** + * Batch run case + * + * @param string $runCaseType + * @access public + * @return void + */ + public function batchRun($runCaseType = 'testcase') + { + $this->post->a(); + $runs = array(); + $caseIdList = array_keys($this->post->results); + if($runCaseType == 'testtask') $runs = $this->dao->select('id, `case`')->from(TABLE_TESTRUN)->where('`case`')->in($caseIdList)->fetchPairs('case', 'id'); + + $stepGroups = $this->dao->select('t1.*')->from(TABLE_CASESTEP)->alias('t1') + ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id') + ->where('t1.case')->in($caseIdList) + ->andWhere('t1.version=t2.version') + ->fetchGroup('case', 'id'); + + $now = helper::now(); + foreach($this->post->results as $caseID => $result) + { + $runID = isset($runs[$caseID]) ? $runs[$caseID] : 0; + $dbSteps = $stepGroups[$caseID]; + $postSteps = $this->post->steps[$caseID]; + $postReals = $this->post->reals[$caseID]; + + $caseResult = $result ? $result : 'pass'; + $stepResults = array(); + foreach($dbSteps as $stepID => $step) + { + $step = array(); + $step['result'] = $caseResult == 'pass' ? $caseResult : $postSteps[$stepID]; + $step['real'] = $caseResult == 'pass' ? '' : $postReals[$stepID]; + $stepResults[$stepID] = $step; + } + + $result = new stdClass(); + $result->run = $runID; + $result->case = $caseID; + $result->version = $this->post->version[$caseID]; + $result->caseResult = $caseResult; + $result->stepResults = serialize($stepResults); + $result->lastRunner = $this->app->user->account; + $result->date = $now; + $this->dao->insert(TABLE_TESTRESULT)->data($result)->autoCheck()->exec(); + $this->dao->update(TABLE_CASE)->set('lastRunner')->eq($this->app->user->account)->set('lastRunDate')->eq($now)->set('lastRunResult')->eq($caseResult)->where('id')->eq($caseID)->exec(); + + if($runID) + { + /* Update testRun's status. */ + if(!dao::isError()) + { + $runStatus = $caseResult == 'blocked' ? 'blocked' : 'done'; + $this->dao->update(TABLE_TESTRUN) + ->set('lastRunResult')->eq($caseResult) + ->set('status')->eq($runStatus) + ->set('lastRunner')->eq($this->app->user->account) + ->set('lastRunDate')->eq($now) + ->where('id')->eq($runID) + ->exec(); + } + } + } + } + /** * Get results by runID or caseID * diff --git a/module/testtask/view/batchrun.html.php b/module/testtask/view/batchrun.html.php new file mode 100644 index 0000000000..4dac475d69 --- /dev/null +++ b/module/testtask/view/batchrun.html.php @@ -0,0 +1,69 @@ + + * @package testcase + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + + + + + + + + + + + + $case):?> + + + + + + + + + + +
testtask->common . $lang->colon . $lang->testtask->batchRun;?>
idAB;?>priAB;?>testcase->module;?>testcase->title;?>testcase->result?>testcase->stepDesc . '/' . $lang->testcase->stepExpect?>
id . html::hidden("version[$case->id]", $case->version)?>testcase->priList[$case->pri]?>module]?>title?>id]", $resultList, 'pass', "onchange='showAction(this.value,\".action$caseID\")'")?> + + + $step):?> + + + + + + + +
desc'>" . $i . "、" . $step->desc . ''?>expect'>" . $lang->testcase->stepExpect . ":" . $step->expect . ''?>
+
+ + + diff --git a/module/testtask/view/cases.html.php b/module/testtask/view/cases.html.php index a823044293..5ee90a90f1 100644 --- a/module/testtask/view/cases.html.php +++ b/module/testtask/view/cases.html.php @@ -95,7 +95,8 @@ var moduleID = ''; - id");?>';casesform.submit();"> + id");?>';casesform.submit();"> + ';casesform.submit();"> show();?>