* @package case * @version $Id: control.php 5112 2013-07-12 02:51:33Z chencongzhi520@gmail.com $ * @link http://www.zentao.net */ class testcase extends control { public $products = array(); /** * Construct function, load product, tree, user auto. * * @access public * @return void */ public function __construct($moduleName = '', $methodName = '') { parent::__construct($moduleName, $methodName); $this->loadModel('product'); $this->loadModel('tree'); $this->loadModel('user'); $this->view->products = $this->products = $this->product->getPairs('nocode'); if(empty($this->products)) die($this->locate($this->createLink('product', 'showErrorNone', "fromModule=testcase"))); } /** * Index page. * * @access public * @return void */ public function index() { $this->locate($this->createLink('testcase', 'browse')); } /** * Browse cases. * * @param int $productID * @param string $browseType * @param int $param * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function browse($productID = 0, $branch = '', $browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $this->loadModel('datatable'); /* Set browse type. */ $browseType = strtolower($browseType); /* Set browseType, productID, moduleID and queryID. */ $productID = $this->product->saveState($productID, $this->products); $branch = ($branch === '') ? (int)$this->cookie->preBranch : (int)$branch; setcookie('preProductID', $productID, $this->config->cookieLife, $this->config->webRoot); setcookie('preBranch', (int)$branch, $this->config->cookieLife, $this->config->webRoot); if($this->cookie->preProductID != $productID or $this->cookie->preBranch != $branch) { $_COOKIE['caseModule'] = 0; setcookie('caseModule', 0, $this->config->cookieLife, $this->config->webRoot); } if($browseType == 'bymodule') setcookie('caseModule', (int)$param, $this->config->cookieLife, $this->config->webRoot); if($browseType == 'bysuite') setcookie('caseSuite', (int)$param, $this->config->cookieLife, $this->config->webRoot); if($browseType != 'bymodule') $this->session->set('caseBrowseType', $browseType); $moduleID = ($browseType == 'bymodule') ? (int)$param : ($browseType == 'bysearch' ? 0 : ($this->cookie->caseModule ? $this->cookie->caseModule : 0)); $suiteID = ($browseType == 'bysuite') ? (int)$param : ($browseType == 'bymodule' ? ($this->cookie->caseSuite ? $this->cookie->caseSuite : 0) : 0); $queryID = ($browseType == 'bysearch') ? (int)$param : 0; /* Set menu, save session. */ $this->testcase->setMenu($this->products, $productID, $branch, $moduleID, $suiteID); $this->session->set('caseList', $this->app->getURI(true)); $this->session->set('productID', $productID); $this->session->set('moduleID', $moduleID); $this->session->set('browseType', $browseType); $this->session->set('orderBy', $orderBy); /* Load lang. */ $this->app->loadLang('testtask'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $sort = $this->loadModel('common')->appendOrder($orderBy); /* Get test cases. */ $cases = $this->testcase->getTestCases($productID, $branch, $browseType, $browseType == 'bysearch' ? $queryID : $suiteID, $moduleID, $sort, $pager); /* save session .*/ $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', $browseType != 'bysearch' ? false : true); /* Process case for check story changed. */ $cases = $this->loadModel('story')->checkNeedConfirm($cases); $cases = $this->testcase->appendData($cases); /* Build the search form. */ $actionURL = $this->createLink('testcase', 'browse', "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID"); $this->config->testcase->search['onMenuBar'] = 'yes'; $this->testcase->buildSearchForm($productID, $this->products, $queryID, $actionURL); $showModule = !empty($this->config->datatable->testcaseBrowse->showModule) ? $this->config->datatable->testcaseBrowse->showModule : ''; $this->view->modulePairs = $showModule ? $this->tree->getModulePairs($productID, 'case', $showModule) : array(); /* Assign. */ $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->common; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID&branch=$branch"), $this->products[$productID]); $this->view->position[] = $this->lang->testcase->common; $this->view->productID = $productID; $this->view->product = $this->product->getById($productID); $this->view->productName = $this->products[$productID]; $this->view->modules = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0, $branch); $this->view->moduleTree = $this->tree->getTreeMenu($productID, $viewType = 'case', $startModuleID = 0, array('treeModel', 'createCaseLink'), '', $branch); $this->view->moduleName = $moduleID ? $this->tree->getById($moduleID)->name : $this->lang->tree->all; $this->view->moduleID = $moduleID; $this->view->pager = $pager; $this->view->users = $this->user->getPairs('noletter'); $this->view->orderBy = $orderBy; $this->view->browseType = $browseType; $this->view->param = $param; $this->view->cases = $cases; $this->view->branch = $branch; $this->view->branches = $this->loadModel('branch')->getPairs($productID); $this->view->suiteList = $this->loadModel('testsuite')->getSuites($productID); $this->view->suiteID = $suiteID; $this->view->setShowModule = true; $this->display(); } /** * Group case. * * @param int $productID * @param string $groupBy * @access public * @return void */ public function groupCase($productID = 0, $branch = '', $groupBy = 'stroy') { $groupBy = empty($groupBy) ? 'stroy' : $groupBy; $productID = $this->product->saveState($productID, $this->products); if($branch === '') $branch = (int)$this->cookie->preBranch; $this->app->loadLang('testtask'); $this->testcase->setMenu($this->products, $productID, $branch); $this->session->set('caseList', $this->app->getURI(true)); $cases = $this->testcase->getModuleCases($productID, $branch, 0, $groupBy); $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', false); $cases = $this->testcase->appendData($cases); $groupCases = array(); $groupByList = array(); foreach($cases as $case) { if($groupBy == 'story') { $groupCases[$case->story][] = $case; $groupByList[$case->story] = $case->storyTitle; } } $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->common; $this->view->position[] = html::a($this->createLink('testcase', 'groupTask', "productID=$productID&groupBy=$groupBy"), $this->products[$productID]); $this->view->position[] = $this->lang->testcase->common; $this->view->productID = $productID; $this->view->productName = $this->products[$productID]; $this->view->users = $this->user->getPairs('noletter'); $this->view->browseType = 'group'; $this->view->groupBy = $groupBy; $this->view->orderBy = $groupBy; $this->view->groupByList = $groupByList; $this->view->cases = $groupCases; $this->view->suiteList = $this->loadModel('testsuite')->getSuites($productID); $this->view->suiteID = 0; $this->view->moduleID = 0; $this->view->branch = $branch; $this->display(); } /** * Create a test case. * * @param int $productID * @param int $moduleID * @param string $from * @param int $param * @access public * @return void */ public function create($productID, $branch = '', $moduleID = 0, $from = '', $param = 0, $storyID = 0) { $testcaseID = $from == 'testcase' ? $param : 0; $bugID = $from == 'bug' ? $param : 0; $this->loadModel('story'); if(!empty($_POST)) { $response['result'] = 'success'; $response['message'] = ''; $caseResult = $this->testcase->create($bugID); if(!$caseResult or dao::isError()) { $response['result'] = 'fail'; $response['message'] = dao::getError(); $this->send($response); } $caseID = $caseResult['id']; if($caseResult['status'] == 'exists') { $response['message'] = sprintf($this->lang->duplicate, $this->lang->testcase->common); $response['locate'] = $this->createLink('testcase', 'view', "caseID=$caseID"); $this->send($response); } $this->loadModel('action'); $this->action->create('case', $caseID, 'Opened'); /* If link from no head then reload. */ if(isonlybody()) { $response['locate'] = 'reload'; $response['target'] = 'parent'; $this->send($response); } $response['locate'] = $this->createLink('testcase', 'browse', "productID={$_POST['product']}&branch=" . (isset($_POST['branch']) ? $_POST['branch'] : '') . "&browseType=byModule&args={$_POST['module']}"); $this->send($response); } if(empty($this->products)) $this->locate($this->createLink('product', 'create')); /* Set productID and currentModuleID. */ $productID = $this->product->saveState($productID, $this->products); if($branch === '') $branch = (int)$this->cookie->preBranch; if($storyID and empty($moduleID)) { $story = $this->loadModel('story')->getByID($storyID); $moduleID = $story->module; } $currentModuleID = (int)$moduleID; /* Set menu. */ $this->testcase->setMenu($this->products, $productID, $branch); /* Init vars. */ $type = 'feature'; $stage = ''; $pri = 0; $caseTitle = ''; $precondition = ''; $keywords = ''; $steps = array(); $color = ''; /* If testcaseID large than 0, use this testcase as template. */ if($testcaseID > 0) { $testcase = $this->testcase->getById($testcaseID); $productID = $testcase->product; $type = $testcase->type ? $testcase->type : 'feature'; $stage = $testcase->stage; $pri = $testcase->pri; $storyID = $testcase->story; $caseTitle = $testcase->title; $precondition = $testcase->precondition; $keywords = $testcase->keywords; $steps = $testcase->steps; $color = $testcase->color; } /* If bugID large than 0, use this bug as template. */ if($bugID > 0) { $bug = $this->loadModel('bug')->getById($bugID); $type = $bug->type; $pri = $bug->pri ? $bug->pri : $bug->severity; $storyID = $bug->story; $caseTitle = $bug->title; $keywords = $bug->keywords; $steps = $this->testcase->createStepsFromBug($bug->steps); } /* Padding the steps to the default steps count. */ if(count($steps) < $this->config->testcase->defaultSteps) { $paddingCount = $this->config->testcase->defaultSteps - count($steps); $step = new stdclass(); $step->type = 'item'; $step->desc = ''; $step->expect = ''; for($i = 1; $i <= $paddingCount; $i ++) $steps[] = $step; } $title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->create; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID&branch=$branch"), $this->products[$productID]); $position[] = $this->lang->testcase->common; $position[] = $this->lang->testcase->create; /* Get the status of stories are not closed. */ $storyStatus = $this->lang->story->statusList; $modules = array(); if($currentModuleID) { $modules = $this->loadModel('tree')->getStoryModule($currentModuleID); $modules = $this->tree->getAllChildID($modules); } $stories = $this->story->getProductStoryPairs($productID, $branch, $modules, array_keys($storyStatus), 'id_desc', 50); /* Set custom. */ foreach(explode(',', $this->config->testcase->customCreateFields) as $field) $customFields[$field] = $this->lang->testcase->$field; $this->view->customFields = $customFields; $this->view->showFields = $this->config->testcase->custom->createFields; $this->view->title = $title; $this->view->position = $position; $this->view->productID = $productID; $this->view->productName = $this->products[$productID]; $this->view->moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0, $branch); $this->view->currentModuleID = $currentModuleID ? $currentModuleID : (isset($story->module) ? $story->module : 0); $this->view->stories = $stories; $this->view->caseTitle = $caseTitle; $this->view->color = $color; $this->view->type = $type; $this->view->stage = $stage; $this->view->pri = $pri; $this->view->storyID = $storyID; $this->view->precondition = $precondition; $this->view->keywords = $keywords; $this->view->steps = $steps; $this->view->users = $this->user->getPairs('noletter|noclosed|nodeleted'); $this->view->branch = $branch; $this->view->branches = $this->session->currentProductType != 'normal' ? $this->loadModel('branch')->getPairs($productID) : array(); $this->display(); } /** * Create a batch test case. * * @param int $productID * @param int $moduleID * @param int $storyID * @access public * @return void */ public function batchCreate($productID, $branch = '', $moduleID = 0, $storyID = 0) { $this->loadModel('story'); if(!empty($_POST)) { $caseID = $this->testcase->batchCreate($productID, $branch, $storyID); if(dao::isError()) die(js::error(dao::getError())); if(isonlybody()) die(js::closeModal('parent.parent', 'this')); die(js::locate($this->createLink('testcase', 'browse', "productID=$productID&branch=$branch&browseType=byModule¶m=$moduleID"), 'parent')); } if(empty($this->products)) $this->locate($this->createLink('product', 'create')); /* Set productID and currentModuleID. */ $productID = $this->product->saveState($productID, $this->products); if($branch === '') $branch = (int)$this->cookie->preBranch; if($storyID and empty($moduleID)) { $story = $this->loadModel('story')->getByID($storyID); $moduleID = $story->module; } $currentModuleID = (int)$moduleID; /* Set menu. */ $this->testcase->setMenu($this->products, $productID, $branch); /* Set story list. */ $story = $storyID ? $this->story->getByID($storyID) : ''; $storyList = $storyID ? array($storyID => $story->id . ':' . $story->title . '(' . $this->lang->story->pri . ':' . $story->pri . ',' . $this->lang->story->estimate . ':' . $story->estimate . ')') : array(''); /* Set module option menu. */ $moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0, $branch); $moduleOptionMenu['ditto'] = $this->lang->testcase->ditto; /* Set custom. */ $product = $this->product->getById($productID); foreach(explode(',', $this->config->testcase->customBatchCreateFields) as $field) { if($product->type != 'normal') $customFields[$product->type] = $this->lang->product->branchName[$product->type]; $customFields[$field] = $this->lang->testcase->$field; } $showFields = $this->config->testcase->custom->batchCreateFields; if($product->type == 'normal') { $showFields = str_replace(array(0 => ",branch,", 1 => ",platform,"), '', ",$showFields,"); $showFields = trim($showFields, ','); } $this->view->customFields = $customFields; $this->view->showFields = $showFields; $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->batchCreate; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID&branch=$branch"), $this->products[$productID]); $this->view->position[] = $this->lang->testcase->common; $this->view->position[] = $this->lang->testcase->batchCreate; $this->view->product = $product; $this->view->productID = $productID; $this->view->story = $story; $this->view->storyList = $storyList; $this->view->productName = $this->products[$productID]; $this->view->moduleOptionMenu = $moduleOptionMenu; $this->view->currentModuleID = $currentModuleID; $this->view->branch = $branch; $this->view->branches = $this->loadModel('branch')->getPairs($productID); $this->view->needReview = $this->testcase->forceNotReview() == true ? 0 : 1; $this->display(); } /** * Create bug. * * @param int $productID * @param string $extras * @access public * @return void */ public function createBug($productID, $branch = 0, $extras = '') { parse_str(str_replace(array(',', ' '), array('&', ''), $extras)); $this->loadModel('testtask'); $case = ''; if($runID) { $case = $this->testtask->getRunById($runID)->case; $results = $this->testtask->getResults($runID); } elseif($caseID) { $case = $this->testcase->getById($caseID); $results = $this->testtask->getResults(0, $caseID); } if(!$case) die(js::error($this->lang->notFound) . js::locate('back', 'parent')); $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->createBug; $this->view->runID = $runID; $this->view->case = $case; $this->view->caseID = $caseID; $this->view->version = $version; $this->display(); } /** * View a test case. * * @param int $caseID * @param int $version * @param string $from * @access public * @return void */ public function view($caseID, $version = 0, $from = 'testcase', $taskID = 0) { $case = $this->testcase->getById($caseID, $version); if(!$case) die(js::error($this->lang->notFound) . js::locate('back')); if($from == 'testtask') $run = $this->loadModel('testtask')->getRunByCase($taskID, $caseID); $isLibCase = ($case->lib and empty($case->product)); if($isLibCase) { $libraries = $this->loadModel('testsuite')->getLibraries(); $this->testsuite->setLibMenu($libraries, $case->lib); $this->lang->testcase->menu = $this->lang->testsuite->menu; $this->view->title = "CASE #$case->id $case->title - " . $libraries[$case->lib]; $this->view->position[] = html::a($this->createLink('testsuite', 'library', "libID=$case->lib"), $libraries[$case->lib]); $this->view->libName = $libraries[$case->lib]; } else { $productID = $case->product; $this->testcase->setMenu($this->products, $productID, $case->branch); $this->view->title = "CASE #$case->id $case->title - " . $this->products[$productID]; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->productName = $this->products[$productID]; $this->view->branchName = $this->session->currentProductType == 'normal' ? '' : $this->loadModel('branch')->getById($case->branch); } $caseFails = $this->dao->select('COUNT(*) AS count')->from(TABLE_TESTRESULT) ->where('caseResult')->eq('fail') ->andwhere('`case`')->eq($caseID) ->beginIF($from == 'testtask')->andwhere('`run`')->eq($taskID)->fi() ->fetch('count'); $case->caseFails = $caseFails; $this->view->position[] = $this->lang->testcase->common; $this->view->position[] = $this->lang->testcase->view; $this->view->case = $case; $this->view->from = $from; $this->view->taskID = $taskID; $this->view->version = $version ? $version : $case->version; $this->view->modulePath = $this->tree->getParents($case->module); $this->view->users = $this->user->getPairs('noletter'); $this->view->actions = $this->loadModel('action')->getList('case', $caseID); $this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('testcase', $caseID); $this->view->runID = $from == 'testcase' ? 0 : $run->id; $this->view->isLibCase = $isLibCase; $this->view->caseFails = $caseFails; $this->display(); } /** * Edit a case. * * @param int $caseID * @access public * @return void */ public function edit($caseID, $comment = false) { $this->loadModel('story'); if(!empty($_POST)) { $changes = array(); $files = array(); if($comment == false) { $changes = $this->testcase->update($caseID); if(dao::isError()) die(js::error(dao::getError())); $files = $this->loadModel('file')->saveUpload('testcase', $caseID); } if($this->post->comment != '' or !empty($changes) or !empty($files)) { $this->loadModel('action'); $action = !empty($changes) ? 'Edited' : 'Commented'; $fileAction = ''; if(!empty($files)) $fileAction = $this->lang->addFiles . join(',', $files) . "\n"; $actionID = $this->action->create('case', $caseID, $action, $fileAction . $this->post->comment); $this->action->logHistory($actionID, $changes); } die(js::locate($this->createLink('testcase', 'view', "caseID=$caseID"), 'parent')); } $case = $this->testcase->getById($caseID); if(empty($case->steps)) { $step = new stdclass(); $step->type = 'step'; $step->desc = ''; $step->expect = ''; $case->steps[] = $step; } $isLibCase = ($case->lib and empty($case->product)); if($isLibCase) { $libraries = $this->loadModel('testsuite')->getLibraries(); $this->testsuite->setLibMenu($libraries, $case->lib); $this->lang->testcase->menu = $this->lang->testsuite->menu; if($this->config->global->flow == 'onlyTest') $this->lang->menugroup->testcase = 'caselib'; $title = "CASE #$case->id $case->title - " . $libraries[$case->lib]; $position[] = html::a($this->createLink('testsuite', 'library', "libID=$case->lib"), $libraries[$case->lib]); $this->view->libID = $case->lib; $this->view->libName = $libraries[$case->lib]; $this->view->libraries = $libraries; $this->view->moduleOptionMenu = $this->tree->getOptionMenu($case->lib, $viewType = 'caselib', $startModuleID = 0); } else { $productID = $case->product; $title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->edit; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); /* Set menu. */ $this->testcase->setMenu($this->products, $productID, $case->branch); $moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0, $case->branch); if($case->lib and $case->fromCaseID) { $libName = $this->loadModel('testsuite')->getById($case->lib)->name; $libModules = $this->tree->getOptionMenu($case->lib, 'caselib'); foreach($libModules as $moduleID => $moduleName) { if($moduleID == 0) continue; $moduleOptionMenu[$moduleID] = $libName . $moduleName; } } $this->view->productID = $productID; $this->view->branches = $this->session->currentProductType == 'normal' ? array() : $this->loadModel('branch')->getPairs($productID); $this->view->productName = $this->products[$productID]; $this->view->moduleOptionMenu = $moduleOptionMenu; $this->view->stories = $this->story->getProductStoryPairs($productID, $case->branch); } if($this->testcase->forceNotReview()) unset($this->lang->testcase->statusList['wait']); $position[] = $this->lang->testcase->common; $position[] = $this->lang->testcase->edit; $this->view->title = $title; $this->view->position = $position; $this->view->currentModuleID = $case->module; $this->view->users = $this->user->getPairs('noletter'); $this->view->case = $case; $this->view->actions = $this->loadModel('action')->getList('case', $caseID); $this->view->isLibCase = $isLibCase; $this->display(); } /** * Batch edit case. * * @param int $productID * @access public * @return void */ public function batchEdit($productID = 0, $branch = 0, $type = 'case') { if($this->post->titles) { $allChanges = $this->testcase->batchUpdate(); if($allChanges) { foreach($allChanges as $caseID => $changes ) { if(empty($changes)) continue; $actionID = $this->loadModel('action')->create('case', $caseID, 'Edited'); $this->action->logHistory($actionID, $changes); } } die(js::locate($this->session->caseList, 'parent')); } $caseIDList = $this->post->caseIDList ? $this->post->caseIDList : die(js::locate($this->session->caseList)); $caseIDList = array_unique($caseIDList); /* Get the edited cases. */ $cases = $this->testcase->getByList($caseIDList); $branchProduct = false; /* The cases of a product. */ if($productID) { if($type == 'lib') { $libID = $productID; $libraries = $this->loadModel('testsuite')->getLibraries(); $this->testsuite->setLibMenu($libraries, $libID); $this->lang->testcase->menu = $this->lang->testsuite->menu; /* Set modules. */ $modules = $this->tree->getOptionMenu($libID, $viewType = 'caselib', $startModuleID = 0, $branch); $modules = array('ditto' => $this->lang->testcase->ditto) + $modules; $this->view->modules = $modules; $this->view->title = $libraries[$libID] . $this->lang->colon . $this->lang->testcase->batchEdit; $this->view->position[] = html::a($this->createLink('testsuite', 'library', "libID=$libID"), $libraries[$libID]); } else { $product = $this->product->getByID($productID); $this->testcase->setMenu($this->products, $productID, $branch); if($product->type != 'normal') $branchProduct = true; /* Set modules. */ $modules = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0, $branch); $modules = array('ditto' => $this->lang->testcase->ditto) + $modules; $this->view->branches = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($product->id); $this->view->modules = $modules; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->title = $product->name . $this->lang->colon . $this->lang->testcase->batchEdit; } } /* The cases of my. */ else { $this->lang->testcase->menu = $this->lang->my->menu; $this->lang->set('menugroup.testcase', 'my'); $this->lang->testcase->menuOrder = $this->lang->my->menuOrder; $this->loadModel('my')->setMenu(); $this->view->position[] = html::a($this->server->http_referer, $this->lang->my->testCase); $this->view->title = $this->lang->testcase->batchEdit; /* Set modules. */ $productIdList = array(); foreach($cases as $case) $productIdList[$case->product] = $case->product; $products = $this->product->getByIdList($productIdList); foreach($products as $product) { if($product->type != 'normal') { $branchProduct = true; break; } } } if(!$this->testcase->forceNotReview()) unset($this->lang->testcase->statusList['wait']); /* Judge whether the editedTasks is too large and set session. */ $countInputVars = count($cases) * (count(explode(',', $this->config->testcase->custom->batchEditFields)) + 3); $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars); if($showSuhosinInfo) $this->view->suhosinInfo = extension_loaded('suhosin') ? sprintf($this->lang->suhosinInfo, $countInputVars) : sprintf($this->lang->maxVarsInfo, $countInputVars); $this->loadModel('story'); $stories = $this->story->getProductStoryPairs($productID, $branch); $this->view->stories = array('' => '', 'ditto' => $this->lang->testcase->ditto) + $stories; /* Set custom. */ foreach(explode(',', $this->config->testcase->customBatchEditFields) as $field) $customFields[$field] = $this->lang->testcase->$field; $this->view->customFields = $customFields; $this->view->showFields = $this->config->testcase->custom->batchEditFields; /* Assign. */ $this->view->position[] = $this->lang->testcase->common; $this->view->position[] = $this->lang->testcase->batchEdit; $this->view->caseIDList = $caseIDList; $this->view->productID = $productID; $this->view->branchProduct = $branchProduct; $this->view->priList = array('ditto' => $this->lang->testcase->ditto) + $this->lang->testcase->priList; $this->view->typeList = array('' => '', 'ditto' => $this->lang->testcase->ditto) + $this->lang->testcase->typeList; $this->view->cases = $cases; $this->display(); } /** * Review case. * * @param int $caseID * @access public * @return void */ public function review($caseID) { if($_POST) { $this->testcase->review($caseID); if(dao::isError()) die(js::error(dao::getError())); $result = $this->post->result; $this->loadModel('action')->create('case', $caseID, 'Reviewed', $this->post->comment, ucfirst($result)); die(js::reload('parent.parent')); } $this->view->users = $this->user->getPairs('noletter|noclosed|nodeleted'); $this->view->case = $this->testcase->getById($caseID); $this->view->actions = $this->loadModel('action')->getList('case', $caseID); $this->display(); } /** * Batch review case. * * @param string $result * @access public * @return void */ public function batchReview($result) { $caseIdList = $this->post->caseIDList ? $this->post->caseIDList : die(js::locate($this->session->caseList, 'parent')); $caseIDList = array_unique($caseIDList); $actions = $this->testcase->batchReview($caseIdList, $result); if(dao::isError()) die(js::error(dao::getError())); die(js::locate($this->session->caseList, 'parent')); } /** * Delete a test case * * @param int $caseID * @param string $confirm yes|noe * @access public * @return void */ public function delete($caseID, $confirm = 'no') { if($confirm == 'no') { die(js::confirm($this->lang->testcase->confirmDelete, inlink('delete', "caseID=$caseID&confirm=yes"))); } else { $this->testcase->delete(TABLE_CASE, $caseID); /* if ajax request, send result. */ if($this->server->ajax) { if(dao::isError()) { $response['result'] = 'fail'; $response['message'] = dao::getError(); } else { $response['result'] = 'success'; $response['message'] = ''; } $this->send($response); } die(js::locate($this->session->caseList, 'parent')); } } /** * Batch delete cases. * * @param int $productID * @access public * @return void */ public function batchDelete($productID = 0) { $caseIDList = $this->post->caseIDList ? $this->post->caseIDList : die(js::locate($this->session->caseList)); $caseIDList = array_unique($caseIDList); foreach($caseIDList as $caseID) $this->testcase->delete(TABLE_CASE, $caseID); die(js::locate($this->session->caseList)); } /** * Batch change branch. * * @param int $branchID * @access public * @return void */ public function batchChangeBranch($branchID) { if($this->post->caseIDList) { $caseIDList = $this->post->caseIDList; $caseIDList = array_unique($caseIDList); unset($_POST['caseIDList']); $allChanges = $this->testcase->batchChangeBranch($caseIDList, $branchID); if(dao::isError()) die(js::error(dao::getError())); foreach($allChanges as $caseID => $changes) { $this->loadModel('action'); $actionID = $this->action->create('case', $caseID, 'Edited'); $this->action->logHistory($actionID, $changes); } } die(js::locate($this->session->caseList, 'parent')); } /** * Batch change the module of case. * * @param int $moduleID * @access public * @return void */ public function batchChangeModule($moduleID) { if($this->post->caseIDList) { $caseIDList = $this->post->caseIDList; $caseIDList = array_unique($caseIDList); unset($_POST['caseIDList']); $allChanges = $this->testcase->batchChangeModule($caseIDList, $moduleID); if(dao::isError()) die(js::error(dao::getError())); foreach($allChanges as $caseID => $changes) { $this->loadModel('action'); $actionID = $this->action->create('case', $caseID, 'Edited'); $this->action->logHistory($actionID, $changes); } } die(js::locate($this->session->caseList, 'parent')); } /** * Batch review case. * * @param string $result * @access public * @return void */ public function batchCaseTypeChange($result) { $caseIdList = $this->post->caseIDList ? $this->post->caseIDList : die(js::locate($this->session->caseList, 'parent')); $caseIDList = array_unique($caseIDList); $this->testcase->batchCaseTypeChange($caseIdList, $result); if(dao::isError()) die(js::error(dao::getError())); die(js::locate($this->session->caseList, 'parent')); } /** * Link related cases. * * @param int $caseID * @param string $browseType * @param int $param * @access public * @return void */ public function linkCases($caseID, $browseType = '', $param = 0) { /* Link cases. */ if(!empty($_POST)) { $this->testcase->linkCases($caseID); if(isonlybody()) die(js::closeModal('parent.parent', '', "function(){parent.parent.loadLinkCases('$caseID')}")); die(js::locate($this->createLink('testcase', 'edit', "caseID=$caseID"), 'parent')); } /* Get case and queryID. */ $case = $this->testcase->getById($caseID); $queryID = ($browseType == 'bySearch') ? (int)$param : 0; /* Set menu. */ $this->testcase->setMenu($this->products, $case->product, $case->branch); /* Build the search form. */ $actionURL = $this->createLink('testcase', 'linkCases', "caseID=$caseID&browseType=bySearch&queryID=myQueryID", '', true); $this->testcase->buildSearchForm($case->product, $this->products, $queryID, $actionURL); /* Get cases to link. */ $cases2Link = $this->testcase->getCases2Link($caseID, $browseType, $queryID); /* Assign. */ $this->view->title = $case->title . $this->lang->colon . $this->lang->testcase->linkCases; $this->view->position[] = html::a($this->createLink('product', 'view', "productID=$case->product"), $this->products[$case->product]); $this->view->position[] = html::a($this->createLink('testcase', 'view', "caseID=$caseID"), $case->title); $this->view->position[] = $this->lang->testcase->linkCases; $this->view->case = $case; $this->view->cases2Link = $cases2Link; $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->display(); } /** * AJAX: get linkCases. * * @param int $caseID * @access public * @return string */ public function ajaxGetLinkCases($caseID) { /* Get linkCases. */ $cases = $this->testcase->getLinkCases($caseID); /* Build linkCase list. */ $output = ''; foreach($cases as $caseId => $caseTitle) { $output .= '