From 50d2efa3c03ec7d285094e49a0484b6e819537fc Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 18 Mar 2022 10:42:36 +0800 Subject: [PATCH] * Add auto test of bug. --- test/class/bug.class.php | 103 +++++++++++++++++++++++++++++++++ test/data/bug.yaml | 6 +- test/model/bug/batchupdate.php | 28 +++++++++ test/model/bug/update.php | 36 ++++++++++++ 4 files changed, 170 insertions(+), 3 deletions(-) create mode 100755 test/model/bug/batchupdate.php create mode 100755 test/model/bug/update.php diff --git a/test/class/bug.class.php b/test/class/bug.class.php index 50140ea335..3d36d024c5 100644 --- a/test/class/bug.class.php +++ b/test/class/bug.class.php @@ -785,4 +785,107 @@ class bugTest return $owner; } } + + /** + * Test update a bug. + * + * @param mixed $bugID + * @param array $param + * @access public + * @return void + */ + public function updateObject($bugID, $param = array()) + { + global $tester; + $object = $tester->dbh->query("SELECT * FROM " . TABLE_BUG ." WHERE id = $bugID")->fetch(); + + foreach($object as $field => $value) + { + if(in_array($field, array_keys($param))) + { + $_POST[$field] = $param[$field]; + } + else + { + $_POST[$field] = $value; + } + } + $_POST['closedDate'] = ''; + + + $change = $this->objectModel->update($bugID); + if($change == array()) $change = '没有数据更新'; + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $change; + } + } + + /** + * Test batch update tasks. + * + * @param array $param + * @param int $taskID + * @access public + * @return array + */ + public function batchUpdateObject($bugIDList, $title, $type, $bugID) + { + $titles = array('1' => 'BUG1', '2' => 'BUG2', '3' => 'BUG3'); + $types = array('1' => 'codeerror', '2' => 'config', '3' => 'install'); + $severities = array('1' => '1', '2' => '2', '3' => '3'); + $pris = array('1' => '1', '2' => '2', '3' => '3'); + $colors = array('1' => '#3da7f5', '2' => '#75c941', '3' => '#2dbdb2'); + $module = array('1' => '1821', '2' => '1822', '3' => '1823'); + $plan = array('1' => '1', '2' => '1', '3' => '1'); + $assignedTo = array('1' => 'admin', '2' => 'admin', '3' => 'admin'); + $deadline = array('1' => date('Y-m-d',strtotime('-1 month')), '2' => date('Y-m-d',strtotime('-1 month +1 day')), '3' => date('Y-m-d',strtotime('-1 month +2 day'))); + $os = array('1' => '', '2' => '', '3' => 'all'); + $browser = array('1' => '', '2' => '', '3' => ''); + $keyword = array('1' => '', '2' => '', '3' => ''); + $resolvedBy = array('1' => '', '2' => '', '3' => ''); + $resolution = array('1' => '', '2' => '', '3' => ''); + $duplicateBug = array('1' => '', '2' => '', '3' => ''); + + $titles[$bugID] = $title; + $types[$bugID] = $type; + + + $batchUpdateFields['bugIDList'] = $bugIDList; + $batchUpdateFields['types'] = $types; + $batchUpdateFields['severities'] = $severities; + $batchUpdateFields['pris'] = $pris; + $batchUpdateFields['titles'] = $titles; + $batchUpdateFields['colors'] = $colors; + $batchUpdateFields['modules'] = $module; + $batchUpdateFields['plans'] = $plan; + $batchUpdateFields['assignedTos'] = $assignedTo; + $batchUpdateFields['deadlines'] = $deadline; + $batchUpdateFields['os'] = $os; + $batchUpdateFields['browsers'] = $browser; + $batchUpdateFields['keywords'] = $keyword; + $batchUpdateFields['resolvedBys'] = $resolvedBy; + $batchUpdateFields['resolutions'] = $resolution; + $batchUpdateFields['duplicateBugs'] = $duplicateBug; + + foreach($batchUpdateFields as $field => $value) $_POST[$field] = $value; + + $object = $this->objectModel->batchUpdate(); + unset($_POST); + + if(dao::isError()) + { + return dao::getError(); + } + else + { + return $object[$bugID]; + } + } } diff --git a/test/data/bug.yaml b/test/data/bug.yaml index 707bad816f..19b8d373af 100644 --- a/test/data/bug.yaml +++ b/test/data/bug.yaml @@ -35,9 +35,9 @@ fields: - field: keywords range: [] - field: severity - range: 1-4:R + range: 1-4 - field: pri - range: 1-4:R + range: 1-4 - field: type range: [codeerror,config,install,security,performance,standard,automation,designdefect,others] - field: os @@ -97,7 +97,7 @@ fields: loop: 0 format: "YYYY-MM-DD" - field: closedBy - range: []{80},admin{20} + range: []{50},admin{30} - field: closedDate range: - field: duplicateBug diff --git a/test/model/bug/batchupdate.php b/test/model/bug/batchupdate.php new file mode 100755 index 0000000000..d949c30402 --- /dev/null +++ b/test/model/bug/batchupdate.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php +batchUpdate(); +cid=1 +pid=1 + +测试批量修改bug1 >> type,codeerror,config;title,BUG1,批量修改bug一 +测试批量修改bug2 >> type,config,install;title,BUG2,批量修改bug二 +测试批量修改bug3 >> type,install,security;title,BUG3,批量修改bug三 + +*/ + +$bugIDList = array('1', '2', '3'); + +$title = array('1' => '批量修改bug一', '2' => '批量修改bug二', '3' => '批量修改bug三'); +$type = array('1' => 'config', '2' => 'install', '3' => 'security'); + +$bug = new bugTest(); +r($bug->batchUpdateObject($bugIDList, $title[$bugIDList[0]], $type[$bugIDList[0]], $bugIDList[0])) && p('0:field,old,new;1:field,old,new') && e('type,codeerror,config;title,BUG1,批量修改bug一'); // 测试批量修改bug1 +r($bug->batchUpdateObject($bugIDList, $title[$bugIDList[1]], $type[$bugIDList[1]], $bugIDList[1])) && p('0:field,old,new;1:field,old,new') && e('type,config,install;title,BUG2,批量修改bug二'); // 测试批量修改bug2 +r($bug->batchUpdateObject($bugIDList, $title[$bugIDList[2]], $type[$bugIDList[2]], $bugIDList[2])) && p('0:field,old,new;1:field,old,new') && e('type,install,security;title,BUG3,批量修改bug三'); // 测试批量修改bug3 +system("./ztest init"); diff --git a/test/model/bug/update.php b/test/model/bug/update.php new file mode 100755 index 0000000000..7d3899c674 --- /dev/null +++ b/test/model/bug/update.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +update(); +cid=1 +pid=1 + +测试更新bug名称 >> title,BUG1,john +测试更新bug类型 >> type,codeerror,config +测试更新bug名称和类型 >> title,john,jack;type,config,install +测试不更改bug名称 >> 没有数据更新 +测试不更改bug类型 >> 没有数据更新 + + +*/ + + +$projectIdList = array('1', '2'); + +$t_uptitle = array('title' => 'john'); +$t_uptype = array('type' => 'config'); +$t_typetitle = array('title' => 'jack', 'type' => 'install'); +$t_untitle = array('title' => 'jack'); +$t_untype = array('type' => 'install'); + +$bug=new bugTest(); +r($bug->updateObject($projectIdList[0], $t_uptitle)) && p('0:field,old,new') && e('title,正常bug2,john'); // 测试更新bug名称 +r($bug->updateObject($projectIdList[0], $t_uptype)) && p('0:field,old,new') && e('type,codeerror,config'); // 测试更新bug类型 +r($bug->updateObject($projectIdList[0], $t_typetitle)) && p('0:field,old,new;1:field,old,new') && e('title,john,jack;type,config,install'); // 测试更新bug名称和类型 +r($bug->updateObject($projectIdList[0], $t_untitle)) && p() && e('没有数据更新'); // 测试不更改bug名称 +r($bug->updateObject($projectIdList[0], $t_untype)) && p() && e('没有数据更新'); // 测试不更改bug类型 +system("./ztest init");