. * * @copyright Copyright: 2009 Chunsheng Wang * @author Chunsheng Wang * @package case * @version $Id$ * @link http://www.zentao.cn */ class testcase extends control { private $products = array(); /* 构造函数,加载story, release, tree等模块。*/ public function __construct() { parent::__construct(); $this->loadModel('product'); $this->loadModel('tree'); $this->loadModel('user'); $this->products = $this->product->getPairs(); $this->assign('products', $this->products); } /* case首页。*/ public function index() { $this->locate($this->createLink('testcase', 'browse')); } /* 浏览一个产品下面的case。*/ public function browse($productID = 0, $type = 'byModule', $param = 0, $orderBy = 'id|desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { if(empty($this->products)) $this->locate($this->createLink('product', 'create')); $productID = (int)$productID; if($productID == 0) $productID = key($this->products); $currentModuleID = ($type == 'byModule') ? (int)$param : 0; if($currentModuleID == 0) { $currentModuleName = $this->lang->testcase->allCases; } else { $currentModule = $this->tree->getById($currentModuleID); $currentModuleName = sprintf($this->lang->testcase->moduleCases, $currentModule->name); } if($type == "byModule") { $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $childModuleIds = $this->tree->getAllChildId($currentModuleID); $cases = $this->testcase->getModuleCases($productID, $childModuleIds, $orderBy, $pager); } $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->common; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $position[] = $this->lang->testcase->common; $this->assign('header', $header); $this->assign('position', $position); $this->assign('productID', $productID); $this->assign('productName', $this->products[$productID]); $this->assign('moduleTree', $this->tree->getTreeMenu($productID, $viewType = 'case', $rooteModuleID = 0, array('treeModel', 'createCaseLink'))); $this->assign('type', $type); $this->assign('cases', $cases); $this->assign('pager', $pager->get()); $this->assign('users', $this->user->getPairs($this->app->company->id, 'noletter')); $this->assign('currentModuleID', $currentModuleID); $this->assign('currentModuleName', $currentModuleName); $this->display(); } /* 创建case。*/ public function create($productID, $moduleID = 0) { $this->loadModel('story'); if(!empty($_POST)) { $caseID = $this->testcase->create(); if(dao::isError()) die(js::error(dao::getError())); $this->loadModel('action'); $this->action->create('case', $caseID, 'Opened'); die(js::locate($this->createLink('testcase', 'browse', "productID=$_POST[productID]&type=byModule¶m=$_POST[moduleID]"), 'parent')); } if(empty($this->products)) $this->locate($this->createLink('product', 'create')); $productID = common::saveProductState($productID, key($this->products)); $currentModuleID = (int)$moduleID; $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->create; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $position[] = $this->lang->testcase->create; $users = $this->user->getPairs($this->app->company->id); $this->assign('header', $header); $this->assign('position', $position); $this->assign('productID', $productID); $this->assign('users', $users); $this->assign('productName', $this->products[$productID]); $this->assign('moduleOptionMenu', $this->tree->getOptionMenu($productID, $viewType = 'case', $rooteModuleID = 0)); $this->assign('currentModuleID', $currentModuleID); $this->assign('stories', $this->story->getProductStoryPairs($productID)); $this->display(); } /* 查看一个case。*/ public function view($caseID) { $this->loadModel('action'); $case = $this->testcase->getById($caseID); $productID = $case->product; $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->view; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $position[] = $this->lang->testcase->view; $users = $this->user->getPairs($this->app->company->id, 'noletter'); $actions = $this->action->getList('case', $caseID); $this->assign('header', $header); $this->assign('position', $position); $this->assign('case', $case); $this->assign('actions', $actions); $this->assign('productName', $this->products[$productID]); $this->assign('modulePath', $this->tree->getParents($case->module)); $this->display(); } /* 编辑一个Bug。*/ public function edit($caseID) { $this->loadModel('story'); /* 更新case信息。*/ if(!empty($_POST)) { $changes = $this->testcase->update($caseID); if(dao::isError()) die(js::error(dao::getError())); if($this->post->comment != '' or !empty($changes)) { $this->loadModel('action'); $action = !empty($changes) ? 'Edited' : 'Commented'; $actionID = $this->action->create('case', $caseID, $action, $this->post->comment); $this->action->logHistory($actionID, $changes); } die(js::locate($this->createLink('testcase', 'view', "caseID=$caseID"), 'parent')); } /* 生成表单。*/ $case = $this->testcase->getById($caseID); $productID = $case->product; $currentModuleID = $case->module; $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->edit; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $position[] = $this->lang->testcase->edit; $users = $this->user->getPairs($this->app->company->id); $this->assign('header', $header); $this->assign('position', $position); $this->assign('productID', $productID); $this->assign('productName', $this->products[$productID]); $this->assign('moduleOptionMenu', $this->tree->getOptionMenu($productID, $viewType = 'case', $rooteModuleID = 0)); $this->assign('currentModuleID', $currentModuleID); $this->assign('users', $users); $this->assign('stories', $this->story->getProductStoryPairs($productID)); $this->assign('header', $header); $this->assign('position', $position); $this->assign('case', $case); $this->display(); } public function delete($id) { $header['title'] = $this->lang->page->delete; $this->assign('header', $header); $this->display(); } }