diff --git a/module/testcase/config.php b/module/testcase/config.php index b27df21fa6..b0703f016b 100644 --- a/module/testcase/config.php +++ b/module/testcase/config.php @@ -1,4 +1,26 @@ testcase->defaultSteps = 3; +$config->testcase->batchCreate = 10; + +$config->testcase->create = new stdclass(); +$config->testcase->edit = new stdclass(); +$config->testcase->create->requiredFields = 'title,type'; +$config->testcase->edit->requiredFields = 'title,type'; + +$config->testcase->batchEdit = new stdclass(); +$config->testcase->batchEdit->columns = 7; + +$config->testcase->editor = new stdclass(); +$config->testcase->editor->edit = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->testcase->editor->view = array('id' => 'comment', 'tools' => 'simpleTools'); + +$config->testcase->exportFields = ' + id, product, module, story, + title, precondition, stepDesc, stepExpect, keywords, + pri, type, stage, status, frequency, + openedBy, openedDate, lastEditedBy, lastEditedDate, + version,linkCase'; + global $lang; $config->testcase->search['module'] = 'testcase'; $config->testcase->search['fields']['title'] = $lang->testcase->title; @@ -31,22 +53,3 @@ $config->testcase->search['params']['stage'] = array('operator' => 'inclu $config->testcase->search['params']['openedDate'] = array('operator' => '>=', 'control' => 'input', 'values' => '', 'class' => 'date'); $config->testcase->search['params']['lastEditedDate'] = array('operator' => '>=', 'control' => 'input', 'values' => '', 'class' => 'date'); - -$config->testcase->defaultSteps = 3; -$config->testcase->batchCreate = 10; - -$config->testcase->create = new stdclass(); -$config->testcase->edit = new stdclass(); -$config->testcase->create->requiredFields = 'title,type'; -$config->testcase->edit->requiredFields = 'title,type'; - -$config->testcase->editor = new stdclass(); -$config->testcase->editor->edit = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->testcase->editor->view = array('id' => 'comment', 'tools' => 'simpleTools'); - -$config->testcase->exportFields = ' - id, product, module, story, - title, precondition, stepDesc, stepExpect, keywords, - pri, type, stage, status, frequency, - openedBy, openedDate, lastEditedBy, lastEditedDate, - version,linkCase'; diff --git a/module/testcase/control.php b/module/testcase/control.php index 79b0d5149c..380c2be55f 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -418,69 +418,54 @@ class testcase extends control /** * 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 = '') + public function batchEdit($productID = 0) { - if($from == 'testcaseBrowse' or $from == 'testtaskCases') + if($this->post->titles) { - /* 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)->where('id')->in($caseIDList)->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->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->display(); - } - elseif($from == 'testcaseBatchEdit') - { - if(!empty($_POST)) + $allChanges = $this->testcase->batchUpdate(); + if($allChanges) { - $allChanges = $this->testcase->batchUpdate(); - if($allChanges) + foreach($allChanges as $caseID => $changes ) { - foreach($allChanges as $caseID => $changes ) - { - $actionID = $this->loadModel('action')->create('case', $caseID, 'Edited'); - $this->action->logHistory($actionID, $changes); - } + $actionID = $this->loadModel('action')->create('case', $caseID, 'Edited'); + $this->action->logHistory($actionID, $changes); } } + die(js::locate($this->session->caseList, 'parent')); } - } + /* Init vars. */ + $caseIDList = $this->post->caseIDList ? $this->post->caseIDList : die(js::locate($this->session->caseList, 'parent')); + $product = $this->product->getByID($productID); + + /* Get all cases. */ + $cases = $this->dao->select('*')->from(TABLE_CASE)->where('id')->in($caseIDList)->fetchAll('id'); + + /* Set product menu. */ + $this->testcase->setMenu($this->products, $productID); + + /* Judge whether the editedTasks is too large and set session. */ + $showSuhosinInfo = false; + $showSuhosinInfo = $this->loadModel('common')->judgeSuhosinSetting(count($cases), $this->config->testcase->batchEdit->columns); + $this->app->session->set('showSuhosinInfo', $showSuhosinInfo); + if($showSuhosinInfo) $this->view->suhosinInfo = $this->lang->suhosinInfo; + + /* Assign. */ + $this->view->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; + $this->view->moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0); + $this->view->caseIDList = $caseIDList; + $this->view->productID = $productID; + $this->view->cases = $cases; + + $this->display(); + } /** * Delete a test case diff --git a/module/testcase/model.php b/module/testcase/model.php index 97e76c6b9b..9c47789959 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -275,48 +275,45 @@ class testcaseModel extends model $cases = array(); $allChanges = array(); $now = helper::now(); - $caseIDList = $this->post->caseIDList ? $this->post->caseIDList : array(); + $caseIDList = $this->post->caseIDList; /* 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) { - /* 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]); + $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); + $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); } - - /* Update cases. */ - foreach($cases as $caseID => $case) + else { - $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))); - } + die(js::error('case#' . $caseID . dao::getError(true))); } } diff --git a/module/testcase/view/batchedit.html.php b/module/testcase/view/batchedit.html.php index 38f13aea15..d90af9c300 100644 --- a/module/testcase/view/batchedit.html.php +++ b/module/testcase/view/batchedit.html.php @@ -11,7 +11,7 @@ */ ?> -
diff --git a/module/testcase/view/browse.html.php b/module/testcase/view/browse.html.php index 0863f89380..1a5fd42e0f 100644 --- a/module/testcase/view/browse.html.php +++ b/module/testcase/view/browse.html.php @@ -50,7 +50,7 @@ js::set('moduleID' , $moduleID);