From 5f71cc3502d7bc7d366f7b30129cd79d7a27b406 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Fri, 13 Nov 2009 08:16:11 +0000 Subject: [PATCH] + rewrite the feature of test case. --- module/bug/view/view.html.php | 2 +- module/common/lang/zh-cn.php | 2 +- module/testcase/control.php | 46 ++++++++++++++++----- module/testcase/lang/zh-cn.php | 14 ++++--- module/testcase/model.php | 56 ++++++++++++++------------ module/testcase/view/browse.html.php | 14 ++++--- module/testcase/view/create.html.php | 48 ++++++++++++---------- module/testcase/view/edit.html.php | 60 ++++++++++++++++++---------- module/testcase/view/view.html.php | 45 +++++++++++---------- 9 files changed, 174 insertions(+), 113 deletions(-) diff --git a/module/bug/view/view.html.php b/module/bug/view/view.html.php index 03378ed759..db28ff49bf 100644 --- a/module/bug/view/view.html.php +++ b/module/bug/view/view.html.php @@ -214,7 +214,7 @@
bug->legendSteps;?> -
steps);?>
+
steps);?>
bug->legendHistory;?> diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index aa2e472b9e..3358294189 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -61,7 +61,7 @@ $lang->submenu->project ->item1 = '新增项目|project|create'; $lang->submenu->project ->item2 = '浏览项目|project|browse'; $lang->submenu->qa->item1 = '缺陷管理|bug|index'; -//$lang->submenu->qa->item2 = '用例管理|testcase|index'; +$lang->submenu->qa->item2 = '用例管理|testcase|index'; $lang->submenu->my->item1 = '我的TODO|my|todo'; $lang->submenu->my->item2 = '我的任务|my|task'; diff --git a/module/testcase/control.php b/module/testcase/control.php index d2cdde8d32..cca7c7b2b3 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -43,7 +43,7 @@ class testcase extends control } /* 浏览一个产品下面的case。*/ - public function browse($productID = 0, $type = 'byModule', $param = 0) + 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')); @@ -63,8 +63,10 @@ class testcase extends control 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); + $cases = $this->testcase->getModuleCases($productID, $childModuleIds, $orderBy, $pager); } $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->case->common; @@ -78,6 +80,8 @@ class testcase extends control $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); @@ -87,17 +91,18 @@ class testcase extends control /* 创建case。*/ public function create($productID, $moduleID = 0) { + $this->loadModel('story'); if(!empty($_POST)) { - $_POST['pri'] = str_replace('item', '', $_POST['pri']); - $this->testcase->create(); + $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 = (int)$productID; - if($productID == 0) $productID = key($this->products); + $productID = common::saveProductState($productID, key($this->products)); $currentModuleID = (int)$moduleID; $header['title'] = $this->products[$productID] . $this->lang->colon . $this->lang->case->create; @@ -108,10 +113,11 @@ class testcase extends control $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('users', $users); + $this->assign('stories', $this->story->getProductStoryPairs($productID)); $this->display(); } @@ -119,15 +125,22 @@ class testcase extends control /* 查看一个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->case->view; $position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $position[] = $this->lang->case->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('case', $case); + $this->assign('actions', $actions); + $this->assign('productName', $this->products[$productID]); + $this->assign('modulePath', $this->tree->getParents($case->module)); $this->display(); } @@ -135,10 +148,20 @@ class testcase extends control /* 编辑一个Bug。*/ public function edit($caseID) { + $this->loadModel('story'); + /* 更新case信息。*/ if(!empty($_POST)) { - $this->testcase->update($caseID); + $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')); } @@ -157,7 +180,8 @@ class testcase extends control $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('users', $users); + $this->assign('stories', $this->story->getProductStoryPairs($productID)); $this->assign('header', $header); $this->assign('position', $position); diff --git a/module/testcase/lang/zh-cn.php b/module/testcase/lang/zh-cn.php index 23048107c9..959023fd1b 100644 --- a/module/testcase/lang/zh-cn.php +++ b/module/testcase/lang/zh-cn.php @@ -35,10 +35,11 @@ $lang->case->openedByMe = '由我创建'; $lang->case->allCases = '所有Case'; $lang->case->moduleCases = '%s'; -$lang->case->labProductAndModule = '所属产品::模块'; -$lang->case->labTypeAndPri = '类型::优先级'; +$lang->case->labProductAndModule = '产品模块'; +$lang->case->labTypeAndPri = '类型&优先级'; $lang->case->labSystemBrowserAndHardware = '系统::浏览器'; $lang->case->labAssignAndMail = '指派给::抄送给'; +$lang->case->labStory = '相关需求'; $lang->case->legendRelated = '相关信息'; $lang->case->legendBasicInfo = '基本信息'; @@ -52,6 +53,7 @@ $lang->case->legendCases = '相关用例'; $lang->case->legendSteps = '用例步骤'; $lang->case->legendAction = '操作'; $lang->case->legendHistory = '历史记录'; +$lang->case->legendComment = '备注'; $lang->case->buttonEdit = '编辑'; $lang->case->buttonActivate = '激活'; @@ -85,11 +87,11 @@ $lang->case->browserList->opera9 = 'opera9'; $lang->case->browserList->oprea10 = '其他'; /* Define the types. */ -$lang->case->typeList->feature = '功能测试'; -$lang->case->typeList->performance = '性能测试'; +$lang->case->typeList['feature'] = '功能测试'; +$lang->case->typeList['performance'] = '性能测试'; -$lang->case->statusList->normal = 'normal'; -$lang->case->statusList->blocked = 'blocked'; +$lang->case->statusList['normal'] = '正常'; +$lang->case->statusList['blocked'] = 'Blocked'; $lang->case->resolutionList->bydesign = 'By Design'; $lang->case->resolutionList->duplicate = 'Duplicate'; diff --git a/module/testcase/model.php b/module/testcase/model.php index a5c0c122fc..c2703236db 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -25,48 +25,52 @@ app->user->account; - $openedDate = time(); - $sql = "INSERT INTO " . TABLE_CASE . " (product, module, type, pri, title, steps, openedBy, openedDate) - VALUES('$productID', '$moduleID', '$type', '$pri', '$title', '$steps', '$openedBy', '$openedDate' )"; - $this->dbh->exec($sql); + $now = date('Y-m-d H:i:s'); + $case = fixer::input('post') + ->add('openedBy', $this->app->user->account) + ->add('openedDate', $now) + ->add('status', 'normal') + ->setDefault('story', 0) + ->stripTags('title') + ->specialChars('steps') + ->get(); + $this->dao->insert(TABLE_CASE)->data($case)->autoCheck()->check('title', 'notempty')->exec(); + return $this->dao->lastInsertID(); } /* 获得某一个产品,某一个模块下面的所有case。*/ - public function getModuleCases($productID, $moduleIds = 0) + public function getModuleCases($productID, $moduleIds = 0, $orderBy = 'id|desc', $pager = null) { - $where = " WHERE `product` = '$productID'"; - $where .= !empty($moduleIds) ? " AND module " . helper::dbin($moduleIds) : ''; - $sql = "SELECT * FROM " . TABLE_CASE . $where; - $stmt = $this->dbh->query($sql); - return $stmt->fetchAll(); + $sql = $this->dao->select('*')->from(TABLE_CASE)->where('product')->eq((int)$productID); + if(!empty($moduleIds)) $sql->andWhere('module')->in($moduleIds); + return $sql->orderBy($orderBy)->page($pager)->fetchAll(); } /* 获取一个case的详细信息。*/ public function getById($caseID) { - return $this->dbh->query("SELECT * FROM " . TABLE_CASE . " WHERE id = '$caseID'")->fetch(); + $case = $this->dao->findById($caseID)->from(TABLE_CASE)->fetch(); + foreach($case as $key => $value) if(strpos($key, 'Date') !== false and !(int)substr($value, 0, 4)) $case->$key = ''; + return $case; } /* 更新case信息。*/ public function update($caseID) { - extract($_POST); - $pri = str_replace('item', '', $pri); - $sql = "UPDATE " . TABLE_CASE . " SET - title = '$title', product='$productID', module = '$moduleID', - type='$type', pri = '$pri', status = '$status', steps = '$steps' - WHERE id ='$caseID' LIMIT 1 "; - return $this->dbh->exec($sql); + $oldCase = $this->getById($caseID); + $now = date('Y-m-d H:i:s'); + $case = fixer::input('post') + ->add('lastEditedBy', $this->app->user->account) + ->add('lastEditedDate', $now) + ->setDefault('story', 0) + ->stripTags('title') + ->specialChars('steps') + ->remove('comment') + ->get(); + $this->dao->update(TABLE_CASE)->data($case)->autoCheck()->check('title', 'notempty')->where('id')->eq((int)$caseID)->exec(); + if(!dao::isError()) return common::createChanges($oldCase, $case); } } diff --git a/module/testcase/view/browse.html.php b/module/testcase/view/browse.html.php index ed5c36306f..b3dacb9cc5 100644 --- a/module/testcase/view/browse.html.php +++ b/module/testcase/view/browse.html.php @@ -42,6 +42,7 @@ function selectProduct(productID)
+ createLink('testcase', 'browse', "productId=$productID"), $lang->case->allCases);?> createLink('tree', 'browse', "productID=$productID&view=case"), $lang->tree->manageCase);?>
@@ -68,6 +69,9 @@ $("#{$type}Tab").addClass('active'); EOT; ?> +
+ createLink('testcase', 'create', "productID=$productID&moduleID=$currentModuleID"), $lang->case->create);?> +
@@ -81,16 +85,16 @@ EOT; - + - - - + + +
createLink('testcase', 'view', "testcaseID=$case->id"), $case->id);?>createLink('testcase', 'view', "testcaseID=$case->id"), sprintf('%03d', $case->id));?> pri?> title;?>type;?>openedBy;?>status;?>case->typeList[$case->type];?>openedBy];?>case->statusList[$case->status];?>
-
createLink('testcase', 'create', "productID=$productID&moduleID=$currentModuleID"), $lang->case->create);?>
+
diff --git a/module/testcase/view/create.html.php b/module/testcase/view/create.html.php index 3d6e7ad4a9..ce6bcb0f17 100644 --- a/module/testcase/view/create.html.php +++ b/module/testcase/view/create.html.php @@ -23,13 +23,29 @@ */ ?> +
@@ -38,27 +54,13 @@ function loadModuleMenu(productID) case->labProductAndModule;?> - - + + - - - case->labTypeAndPri;?> - - case->typeList, '', 'class=select-2');?> - case->priList, '', 'class=select-2');?> - + case->title;?> @@ -67,12 +69,16 @@ function loadModuleMenu(productID) case->steps;?> + + + case->labTypeAndPri;?> + + case->typeList, '', 'class=select-2');?> + case->priList, '', 'class=select-2');?> + - - - - +
diff --git a/module/testcase/view/edit.html.php b/module/testcase/view/edit.html.php index d803197b91..8ecc05236c 100644 --- a/module/testcase/view/edit.html.php +++ b/module/testcase/view/edit.html.php @@ -23,19 +23,40 @@ */ ?> + +
+
CASE #id . $lang->colon;?> - title, 'class=text-5');?> -
+ title, 'class=text-1');?> +
+
@@ -49,11 +70,10 @@ function loadModuleMenu(productID) case->labProductAndModule;?> - - + + - case->type;?> case->typeList, $case->type, 'class=select-2');?> @@ -68,11 +88,12 @@ function loadModuleMenu(productID) case->story;?> - story;?> + story, 'class=select-3');?>
+ @@ -113,11 +135,12 @@ function loadModuleMenu(productID) - + @@ -127,25 +150,22 @@ function loadModuleMenu(productID)
case->legendSteps;?>
- + +
+
+
+ case->legendComment;?> +
+
-
case->legendAction;?>
- - + + "' />
- -
- case->legendHistory;?> - - - -
-
- diff --git a/module/testcase/view/view.html.php b/module/testcase/view/view.html.php index f8c466c524..098db9bf75 100644 --- a/module/testcase/view/view.html.php +++ b/module/testcase/view/view.html.php @@ -29,11 +29,8 @@ CASE #id . $lang->colon . $case->title;?>
createLink('testcase', 'edit', "caseID=$case->id"), $lang->case->buttonEdit); - //echo html::a($this->createLink('case', 'resolve', "caseID=$case->id"), $lang->case->buttonResolve); - //echo html::a($this->createLink('case', 'close', "caseID=$case->id"), $lang->case->buttonClose); - //echo html::a($this->createLink('case', 'activate', "caseID=$case->id"), $lang->case->buttonActivate); - echo html::a($this->createLink('testcase', 'browse', "productID=$case->product"), $lang->case->buttonToList); + if(common::hasPriv('testcase', 'edit')) echo html::a($this->createLink('testcase', 'edit', "caseID=$case->id"), $lang->case->buttonEdit); + if(common::hasPriv('testcase', 'browse')) echo html::a($this->createLink('testcase', 'browse', "productID=$case->product"), $lang->case->buttonToList); ?>
@@ -48,11 +45,21 @@ - + - + @@ -60,7 +67,7 @@ - + @@ -70,6 +77,7 @@
case->labProductAndModule;?>product;?> + arrow; + foreach($modulePath as $key => $module) + { + echo $module->name; + if(isset($modulePath[$key + 1])) echo $lang->arrow; + } + ?> +
case->type;?>type;?>case->typeList[$case->type];?>
case->pri;?>
case->status;?>status;?>case->statusList[$case->status];?>
case->story;?>
+ @@ -111,10 +120,12 @@ + @@ -125,29 +136,19 @@ case->legendAction;?>
createLink('testcase', 'edit', "caseID=$case->id"), $lang->case->buttonEdit); - //echo html::a($this->createLink('case', 'resolve', "caseID=$case->id"), $lang->case->buttonResolve); - //echo html::a($this->createLink('case', 'close', "caseID=$case->id"), $lang->case->buttonClose); - //echo html::a($this->createLink('case', 'activate', "caseID=$case->id"), $lang->case->buttonActivate); - echo html::a($this->createLink('testcase', 'browse', "productID=$case->product"), $lang->case->buttonToList); + if(common::hasPriv('testcase', 'edit')) echo html::a($this->createLink('testcase', 'edit', "caseID=$case->id"), $lang->case->buttonEdit); + if(common::hasPriv('testcase', 'browse')) echo html::a($this->createLink('testcase', 'browse', "productID=$case->product"), $lang->case->buttonToList); ?>
case->legendSteps;?> -
+
steps);?>
- -
- case->legendHistory;?> - - - -
-
+