From 98e923c438b9890aee4e1b9a11aebd6932ea234e Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Thu, 18 Nov 2010 02:23:01 +0000 Subject: [PATCH] * rewrite the comment of testcase module. --- module/testcase/control.php | 97 ++++++++++++++++++++++++++++--------- module/testcase/model.php | 75 ++++++++++++++++++++-------- 2 files changed, 130 insertions(+), 42 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index 9a0ab6480e..75dc8acda2 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -13,7 +13,12 @@ class testcase extends control { private $products = array(); - /* 构造函数,加载story, release, tree等模块。*/ + /** + * Construct function, load product, tree, user auto. + * + * @access public + * @return void + */ public function __construct() { parent::__construct(); @@ -23,35 +28,53 @@ class testcase extends control $this->view->products = $this->products = $this->product->getPairs(); } - /* case首页。*/ + /** + * Index page. + * + * @access public + * @return void + */ public function index() { $this->locate($this->createLink('testcase', 'browse')); } - /* 浏览一个产品下面的case。*/ + /** + * 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, $browseType = 'byModule', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - /* 设置浏览模式,产品ID和模块ID。 */ + /* Set browseType, productID, moduleID and queryID. */ $browseType = strtolower($browseType); $productID = $this->product->saveState($productID, key($this->products)); $moduleID = ($browseType == 'bymodule') ? (int)$param : 0; $queryID = ($browseType == 'bysearch') ? (int)$param : 0; - /* 设置菜单,登记session。*/ + /* Set menu, save session. */ $this->testcase->setMenu($this->products, $productID); $this->session->set('caseList', $this->app->getURI(true)); - /* 加载分页类。*/ + /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); - /* 如果是按照模块查找,或者列出所有。*/ + /* By module or all cases. */ if($browseType == 'bymodule' or $browseType == 'all') { $childModuleIds = $this->tree->getAllChildId($moduleID); $this->view->cases = $this->testcase->getModuleCases($productID, $childModuleIds, $orderBy, $pager); } + /* Cases need confirmed. */ elseif($browseType == 'needconfirm') { $this->view->cases = $this->dao->select('t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1')->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') @@ -61,6 +84,7 @@ class testcase extends control ->orderBy($orderBy) ->fetchAll(); } + /* By search. */ elseif($browseType == 'bysearch') { if($queryID) @@ -81,21 +105,21 @@ class testcase extends control if($this->session->testcaseQuery == false) $this->session->set('testcaseQuery', ' 1 = 1'); } - $caseQuery = str_replace("`product` = 'all'", '1', $this->session->testcaseQuery); // 如果指定了搜索所有的产品,去掉这个查询条件。 + $caseQuery = str_replace("`product` = 'all'", '1', $this->session->testcaseQuery); // If product is all, change it to 1=1. $this->view->cases = $this->dao->select('*')->from(TABLE_CASE)->where($caseQuery) ->andWhere('product')->eq($productID) ->andWhere('deleted')->eq(0) ->orderBy($orderBy)->page($pager)->fetchAll(); } - /* 构造搜索表单。*/ + /* Build the search form. */ $this->config->testcase->search['params']['product']['values']= array($productID => $this->products[$productID], 'all' => $this->lang->testcase->allProduct); $this->config->testcase->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($productID, $viewType = 'case'); $this->config->testcase->search['actionURL'] = $this->createLink('testcase', 'browse', "productID=$productID&browseType=bySearch&queryID=myQueryID"); $this->config->testcase->search['queryID'] = $queryID; $this->view->searchForm = $this->fetch('search', 'buildForm', $this->config->testcase->search); - /* 赋值。*/ + /* Assign. */ $this->view->header->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->common; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->position[] = $this->lang->testcase->common; @@ -112,7 +136,14 @@ class testcase extends control $this->display(); } - /* 创建case。*/ + /** + * Create a test case. + * + * @param int $productID + * @param int $moduleID + * @access public + * @return void + */ public function create($productID, $moduleID = 0) { $this->loadModel('story'); @@ -126,10 +157,11 @@ class testcase extends control } if(empty($this->products)) $this->locate($this->createLink('product', 'create')); + /* Set productID and currentModuleID. */ $productID = $this->product->saveState($productID, key($this->products)); $currentModuleID = (int)$moduleID; - /* 设置菜单。*/ + /* Set menu. */ $this->testcase->setMenu($this->products, $productID); $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->create; @@ -149,22 +181,26 @@ class testcase extends control $this->display(); } - /* 查看一个case。*/ + /** + * View a test case. + * + * @param int $caseID + * @param int $version + * @access public + * @return void + */ public function view($caseID, $version = 0) { - /* 获取case和产品信息,并设置菜单。*/ $case = $this->testcase->getById($caseID, $version); if(!$case) die(js::error($this->lang->notFound) . js::locate('back')); $productID = $case->product; $this->testcase->setMenu($this->products, $productID); - /* 导航信息。*/ $this->view->header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->view; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->position[] = $this->lang->testcase->view; - /* 赋值。*/ $this->view->case = $case; $this->view->productName = $this->products[$productID]; $this->view->modulePath = $this->tree->getParents($case->module); @@ -174,12 +210,17 @@ class testcase extends control $this->display(); } - /* 编辑一个case。*/ + /** + * Edit a case. + * + * @param int $caseID + * @access public + * @return void + */ public function edit($caseID) { $this->loadModel('story'); - /* 更新case信息。*/ if(!empty($_POST)) { $changes = $this->testcase->update($caseID); @@ -197,7 +238,6 @@ class testcase extends control die(js::locate($this->createLink('testcase', 'view', "caseID=$caseID"), 'parent')); } - /* 生成表单。*/ $case = $this->testcase->getById($caseID); if(empty($case->steps)) { @@ -211,7 +251,7 @@ class testcase extends control $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $position[] = $this->lang->testcase->edit; - /* 设置菜单。*/ + /* Set menu. */ $this->testcase->setMenu($this->products, $productID); $users = $this->user->getPairs(); @@ -232,7 +272,14 @@ class testcase extends control $this->display(); } - /* 删除用例。*/ + /** + * 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') @@ -246,7 +293,13 @@ class testcase extends control } } - /* 确认需求变动。*/ + /** + * Confirm story changes. + * + * @param int $caseID + * @access public + * @return void + */ public function confirmStoryChange($caseID) { $case = $this->testcase->getById($caseID); diff --git a/module/testcase/model.php b/module/testcase/model.php index 4c2024512f..9f251cd989 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -13,24 +13,30 @@ lang->testcase->menu as $key => $menu) { - if($key == 'product') - { - common::setMenuVars($this->lang->testcase->menu, 'product', $selectHtml . $this->lang->arrow); - } - else - { - common::setMenuVars($this->lang->testcase->menu, $key, $productID); - } + $replace = ($key == 'product') ? $selectHtml : $productID; + common::setMenuVars($this->lang->testcase->menu, $key, $replace); } } - /* 创建一个Case。*/ + /** + * Create a case. + * + * @access public + * @return void + */ function create() { $now = helper::now(); @@ -63,7 +69,16 @@ class testcaseModel extends model } } - /* 获得某一个产品,某一个模块下面的所有case。*/ + /** + * Get cases of a module. + * + * @param int $productID + * @param int $moduleIds + * @param string $orderBy + * @param object $pager + * @access public + * @return array + */ public function getModuleCases($productID, $moduleIds = 0, $orderBy = 'id_desc', $pager = null) { return $this->dao->select('*')->from(TABLE_CASE) @@ -73,7 +88,14 @@ class testcaseModel extends model ->orderBy($orderBy)->page($pager)->fetchAll(); } - /* 获取一个case的详细信息。*/ + /** + * Get case info by ID. + * + * @param int $caseID + * @param int $version + * @access public + * @return object|bool + */ public function getById($caseID, $version = 0) { $case = $this->dao->findById($caseID)->from(TABLE_CASE)->fetch(); @@ -93,7 +115,13 @@ class testcaseModel extends model return $case; } - /* 更新case信息。*/ + /** + * Update a case. + * + * @param int $caseID + * @access public + * @return void + */ public function update($caseID) { $oldCase = $this->getById($caseID); @@ -101,22 +129,23 @@ class testcaseModel extends model $stepChanged = false; $steps = array(); - //---------------- 判断步骤是否发生了变化。-------------------- */ - /* 先去除post变量中空的步骤。 */ + //---------------- Judge steps changed or not.-------------------- */ + + /* Remove the empty setps in post. */ foreach($this->post->steps as $key => $desc) { $desc = trim($desc); if(!empty($desc)) $steps[] = array('desc' => $desc, 'expect' => trim($this->post->expects[$key])); } - /* 如果步骤的数量不同,发生了变化。*/ + /* If step count changed, case changed. */ if(count($oldCase->steps) != count($steps)) { $stepChanged = true; } else { - /* 比较每一个步骤是否有不同。*/ + /* Compare every step. */ foreach($oldCase->steps as $key => $oldStep) { if(trim($oldStep->desc) != trim($steps[$key]['desc']) or trim($oldStep->expect) != $steps[$key]['expect']) @@ -128,7 +157,7 @@ class testcaseModel extends model } $version = $stepChanged ? $oldCase->version + 1 : $oldCase->version; - $case = fixer::input('post') + $case = fixer::input('post') ->add('lastEditedBy', $this->app->user->account) ->add('lastEditedDate', $now) ->add('version', $version) @@ -154,7 +183,7 @@ class testcaseModel extends model } } - /* 将步骤合并为字符串,以计算diff。*/ + /* Join the steps to diff. */ if($stepChanged) { $oldCase->steps = $this->joinStep($oldCase->steps); @@ -168,7 +197,13 @@ class testcaseModel extends model } } - /* 合并步骤。*/ + /** + * Join steps to a string, thus can diff them. + * + * @param array $steps + * @access private + * @return string + */ private function joinStep($steps) { $retrun = '';