diff --git a/db/update4.0.beta1.sql b/db/update4.0.beta1.sql index af6faa0047..f89fedbe1f 100644 --- a/db/update4.0.beta1.sql +++ b/db/update4.0.beta1.sql @@ -3,5 +3,10 @@ INSERT INTO `zt_groupPriv` (`company`, `group`, `module`, `method`) VALUES (1, 2, 'bug', 'batchEdit'), (1, 3, 'bug', 'batchEdit'), (1, 4, 'bug', 'batchEdit'), -(1, 5, 'bug', 'batchEdit'); +(1, 5, 'bug', 'batchEdit'), +(1, 1, 'testcase', 'batchEdit'), +(1, 2, 'testcase', 'batchEdit'), +(1, 3, 'testcase', 'batchEdit'), +(1, 4, 'testcase', 'batchEdit'), +(1, 5, 'testcase', 'batchEdit'); diff --git a/module/common/lang/en.php b/module/common/lang/en.php index fab3870662..168397d35b 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -185,7 +185,7 @@ $lang->bug->menu->testtask = array('link' => 'Test Task|testtask|browse|productI $lang->testcase->menu->product = '%s'; $lang->testcase->menu->bug = array('link' => 'Bug|bug|browse|productID=%s'); -$lang->testcase->menu->testcase = array('link' => 'Test Case|testcase|browse|productID=%s', 'alias' => 'view,create,batchcreate,edit', 'subModule' => 'tree'); +$lang->testcase->menu->testcase = array('link' => 'Test Case|testcase|browse|productID=%s', 'alias' => 'view,create,batchcreate,edit,batchedit', 'subModule' => 'tree'); $lang->testcase->menu->testtask = array('link' => 'Test Task|testtask|browse|productID=%s', 'alias' => 'view,create,edit,linkcase,cases'); $lang->testtask->menu = $lang->testcase->menu; diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 552b5e7078..8bd664e280 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -185,7 +185,7 @@ $lang->bug->menu->testtask = array('link' => '测试任务|testtask|browse|produ $lang->testcase->menu->product = '%s'; $lang->testcase->menu->bug = array('link' => '缺陷管理|bug|browse|productID=%s'); -$lang->testcase->menu->testcase = array('link' => '用例管理|testcase|browse|productID=%s', 'alias' => 'view,create,batchcreate,edit', 'subModule' => 'tree'); +$lang->testcase->menu->testcase = array('link' => '用例管理|testcase|browse|productID=%s', 'alias' => 'view,create,batchcreate,edit,batchedit', 'subModule' => 'tree'); $lang->testcase->menu->testtask = array('link' => '测试任务|testtask|browse|productID=%s', 'alias' => 'view,create,edit,linkcase,cases'); $lang->testtask->menu = $lang->testcase->menu; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index c334d486ee..b2c96f748d 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -365,6 +365,7 @@ $lang->resource->testcase->create = 'create'; $lang->resource->testcase->batchCreate = 'batchCreate'; $lang->resource->testcase->view = 'view'; $lang->resource->testcase->edit = 'edit'; +$lang->resource->testcase->batchEdit = 'batchEdit'; $lang->resource->testcase->delete = 'delete'; $lang->resource->testcase->export = 'export'; $lang->resource->testcase->confirmStoryChange = 'confirmStoryChange'; diff --git a/module/testcase/control.php b/module/testcase/control.php index b48bdc092f..1a4e5ca338 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -398,6 +398,74 @@ class testcase extends control $this->display(); } + /** + * Batch edit case. + * + * @param string $from example:testcaseBrowse,testtaskCases,testcaseBatchEdit + * @param int $productID + * @param string $orderBy + * @access public + * @return void + */ + public function batchEdit($from = '', $productID = 0, $orderBy = '') + { + if($from == 'testcaseBrowse' or $from == 'testtaskCases') + { + /* Init vars. */ + $orderBy = $orderBy ? $orderBy : 'id_desc'; + $caseIDList = $this->post->caseIDList ? $this->post->caseIDList : array(); + $product = $this->product->getByID($productID); + $editedCases = array(); + $columns = 7; + $showSuhosinInfo = false; + + /* Get all cases. */ + $allCases = $this->dao->select('*')->from(TABLE_CASE)->alias('t1')->where($this->session->testcaseQueryCondition)->orderBy($orderBy)->fetchAll('id'); + + /* Set product menu. */ + $this->testcase->setMenu($this->products, $productID); + + /* Initialize the cases whose need to edited. */ + foreach($allCases as $case) if(in_array($case->id, $caseIDList)) $editedCases[$case->id] = $case; + + /* Judge whether the editedTasks is too large. */ + $showSuhosinInfo = $this->loadModel('common')->judgeSuhosinSetting(count($editedCases), $columns); + + /* Set the sessions. */ + $this->app->session->set('showSuhosinInfo', $showSuhosinInfo); + + /* Assign. */ + $this->view->header['title'] = $product->name . $this->lang->colon . $this->lang->testcase->batchEdit; + $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); + $this->view->position[] = $this->lang->testcase->common; + $this->view->position[] = $this->lang->testcase->batchEdit; + + if($showSuhosinInfo) $this->view->suhosinInfo = $this->lang->suhosinInfo; + $this->view->moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0); + $this->view->productID = $productID; + $this->view->editedCases = $editedCases; + $this->view->users = $this->user->getPairs('noletter'); + + $this->display(); + } + elseif($from == 'testcaseBatchEdit') + { + if(!empty($_POST)) + { + $allChanges = $this->testcase->batchUpdate(); + if($allChanges) + { + foreach($allChanges as $caseID => $changes ) + { + $actionID = $this->loadModel('action')->create('case', $caseID, 'Edited'); + $this->action->logHistory($actionID, $changes); + } + } + } + die(js::locate($this->session->caseList, 'parent')); + } + } + /** * Delete a test case * diff --git a/module/testcase/lang/en.php b/module/testcase/lang/en.php index 532dde5735..9ac585f2d2 100644 --- a/module/testcase/lang/en.php +++ b/module/testcase/lang/en.php @@ -54,6 +54,7 @@ $lang->testcase->batchCreate = "Batch create"; $lang->testcase->delete = "Delete"; $lang->testcase->view = "Info"; $lang->testcase->edit = "Edit"; +$lang->testcase->batchEdit = "Batch edit"; $lang->testcase->delete = "Delete"; $lang->testcase->browse = "Browse"; $lang->testcase->import = "Import"; diff --git a/module/testcase/lang/zh-cn.php b/module/testcase/lang/zh-cn.php index b907e01f4e..abb5106b66 100644 --- a/module/testcase/lang/zh-cn.php +++ b/module/testcase/lang/zh-cn.php @@ -54,6 +54,7 @@ $lang->testcase->batchCreate = "批量添加"; $lang->testcase->delete = "删除用例"; $lang->testcase->view = "用例详情"; $lang->testcase->edit = "编辑"; +$lang->testcase->batchEdit = "批量编辑 "; $lang->testcase->delete = "删除"; $lang->testcase->browse = "用例列表"; $lang->testcase->import = "导入用例"; diff --git a/module/testcase/model.php b/module/testcase/model.php index 39d2ccee38..3854a2d095 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -250,6 +250,66 @@ class testcaseModel extends model } } + /** + * Batch update testcases. + * + * @access public + * @return array + */ + public function batchUpdate() + { + $cases = array(); + $allChanges = array(); + $now = helper::now(); + $caseIDList = $this->post->caseIDList ? $this->post->caseIDList : array(); + + /* Adjust whether the post data is complete, if not, remove the last element of $caseIDList. */ + if($this->session->showSuhosinInfo) array_pop($caseIDList); + + if(!empty($caseIDList)) + { + /* Initialize cases from the post data.*/ + foreach($caseIDList as $caseID) + { + $case->lastEditedBy = $this->app->user->account; + $caee->lastEditedDate = $now; + $case->pri = $this->post->pris[$caseID]; + $case->status = $this->post->statuses[$caseID]; + $case->module = $this->post->modules[$caseID]; + $case->title = htmlspecialchars($this->post->titles[$caseID]); + $case->type = $this->post->types[$caseID]; + $case->stage = implode(',', $this->post->stages[$caseID]); + + $cases[$caseID] = $case; + unset($case); + } + + /* Update cases. */ + foreach($cases as $caseID => $case) + { + $oldCase = $this->getByID($caseID); + $this->dao->update(TABLE_CASE)->data($case) + ->autoCheck() + ->batchCheck($this->config->testcase->edit->requiredFields, 'notempty') + ->where('id')->eq($caseID) + ->exec(); + + if(!dao::isError()) + { + unset($oldCase->steps); + $allChanges[$caseID] = common::createChanges($oldCase, $case); + } + else + { + die(js::error('case#' . $caseID . dao::getError(true))); + } + } + } + + return $allChanges; + } + + /** * Join steps to a string, thus can diff them. * diff --git a/module/testcase/view/batchedit.html.php b/module/testcase/view/batchedit.html.php new file mode 100644 index 0000000000..798bfb9556 --- /dev/null +++ b/module/testcase/view/batchedit.html.php @@ -0,0 +1,57 @@ + + * @package testcase + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+ diff --git a/module/testcase/view/browse.html.php b/module/testcase/view/browse.html.php index d0d9968ad7..55b6bd3fbc 100644 --- a/module/testcase/view/browse.html.php +++ b/module/testcase/view/browse.html.php @@ -74,7 +74,10 @@ var moduleID = '';