* Add auto test of bug.
This commit is contained in:
162
test/class/bug.class.php
Normal file
162
test/class/bug.class.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
class bugTest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $tester;
|
||||
$this->objectModel = $tester->loadModel('bug');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create a bug.
|
||||
*
|
||||
* @param array $param
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function createObject($param = array())
|
||||
{
|
||||
$createFields['title'] = '测试创建bug';
|
||||
$createFields['type'] = 'codeerror';
|
||||
$createFields['product'] = 1;
|
||||
$createFields['execution'] = 101;
|
||||
$createFields['openedBuild'] = 'trunk';
|
||||
$createFields['pri'] = 3;
|
||||
$createFields['severity'] = 3;
|
||||
$createFields['status'] = 'active';
|
||||
$createFields['deadline'] = '2021-03-19';
|
||||
$createFields['openedBy'] = 'admin';
|
||||
$createFields['openedDate'] = '2021-03-19';
|
||||
|
||||
foreach($createFields as $field => $defaultValue) $_POST[$field] = $defaultValue;
|
||||
|
||||
foreach($param as $key => $value) $_POST[$key] = $value;
|
||||
|
||||
$object = $this->objectModel->create();
|
||||
$objectID = $object['id'];
|
||||
unset($_POST);
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = $this->objectModel->getByID($objectID);
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
public function batchCreateObject($productID, $param = array())
|
||||
{
|
||||
$modules = array('0', '0', '0');
|
||||
$executions = array('101', '101', '0');
|
||||
$openedBuilds = array('', '', '');
|
||||
$title = array('', '', '');
|
||||
$deadlines = array('0000-00-00', '0000-00-00', '0000-00-00');
|
||||
$stepses = array('', '', '');
|
||||
$types = array('', '', '');
|
||||
$severities = array(3, 3, 3);
|
||||
$oses = array('', '', '');
|
||||
$browsers = array('', '', '');
|
||||
$pris = array(3, 3, 3);
|
||||
$color = array('', '', '');
|
||||
$keywords = array('', '', '');
|
||||
|
||||
$createFields['modules'] = $modules;
|
||||
$createFields['executions'] = $executions;
|
||||
$createFields['openedBuilds'] = $openedBuilds;
|
||||
$createFields['title'] = $title;
|
||||
$createFields['deadlines'] = $deadlines;
|
||||
$createFields['stepses'] = $stepses;
|
||||
$createFields['types'] = $types;
|
||||
$createFields['severities'] = $severities;
|
||||
$createFields['oses'] = $oses;
|
||||
$createFields['browsers'] = $browsers;
|
||||
$createFields['pris'] = $pris;
|
||||
$createFields['color'] = $color;
|
||||
$createFields['keywords'] = $keywords;
|
||||
|
||||
foreach($createFields as $field => $defaultValue) $_POST[$field] = $defaultValue;
|
||||
|
||||
foreach($param as $key => $value) $_POST[$key] = $value;
|
||||
|
||||
$object = $this->objectModel->batchCreate($productID);
|
||||
|
||||
$bug = array();
|
||||
if(is_array($object))
|
||||
{
|
||||
foreach($object as $bugID => $actionID)
|
||||
{
|
||||
$bug[] = $this->objectModel->getByID($bugID);
|
||||
}
|
||||
}
|
||||
|
||||
unset($_POST);
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return empty($bug) ? $object : $bug;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create bug from gitlab issue.
|
||||
*
|
||||
* @param array $bug
|
||||
* @param int $executionID
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function createBugFromGitlabIssueTest($bug, $executionID)
|
||||
{
|
||||
$objectID = $this->objectModel->createBugFromGitlabIssue($bug, $executionID);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = $objectID ? $this->objectModel->getById($objectID) : 0;
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get bugs.
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getBugsTest($product, $branch, $browseType, $module)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
/* Load pager. */
|
||||
$tester->app->loadClass('pager', $static = true);
|
||||
$pager = new pager(0, 20 ,1);
|
||||
|
||||
$projectID = 0;
|
||||
$sort = 'id_desc';
|
||||
$queryID = 0;
|
||||
$executions = $tester->loadModel('execution')->getPairs($projectID, 'all', 'empty|withdelete');
|
||||
|
||||
$bugs = $this->objectModel->getBugs($product, $executions, $branch, $browseType, $module, $queryID, $sort, $pager, $projectID);
|
||||
|
||||
$title = '';
|
||||
foreach($bugs as $bug) $title .= ',' . $bug->title;
|
||||
$title = trim($title, ',');
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class taskTest
|
||||
*/
|
||||
public function createObject($param = array(), $executionID = '')
|
||||
{
|
||||
$assignedTo = array('');
|
||||
$assignedTo = array('');
|
||||
$createFields = array('module' => '', 'story' => '', 'name' => '', 'type' => '', 'assignedTo' => $assignedTo,
|
||||
'pri' => 3, 'estimate' => '', 'estStarted' => '2021-01-10', 'deadline' => '2021-03-19', 'desc' => '');
|
||||
|
||||
|
||||
48
test/model/bug/batchcreate.php
Executable file
48
test/model/bug/batchcreate.php
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/bug.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=bugModel->batchCreate();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
测试正常批量创建bug1 >> 批量bug一,trunk,3,codeerror,3,3,1,101
|
||||
测试正常批量创建bug2 >> 批量bug五,trunk,codeerror,3,3,1,101
|
||||
测试正常批量创建bug3 >> 批量bug九,1,config,3,3,1,0
|
||||
测试短时间内重复批量创建bug >> 0
|
||||
测试异常创建bug >> <html><meta charset='utf-8'/><style>body{background:white}</style><script>alert('『影响版本』不能为空。')
|
||||
|
||||
|
||||
*/
|
||||
|
||||
$productID = 1;
|
||||
|
||||
$title = array('批量bug一','批量bug二','批量bug三');
|
||||
$openedBuild = array(array('trunk', '3'), array('trunk'), array('1'));
|
||||
$type = array('codeerror','ditto','config');
|
||||
$severity = array('3','2','1');
|
||||
$normal_create1 = array('title' => $title, 'types' => $type, 'openedBuilds' => $openedBuild, 'severity' => $severity);
|
||||
|
||||
$title = array('批量bug四','批量bug五','批量bug六');
|
||||
$normal_create2 = array('title' => $title, 'types' => $type, 'openedBuilds' => $openedBuild, 'severity' => $severity);
|
||||
|
||||
|
||||
$title = array('批量bug七','批量bug八','批量bug九');
|
||||
$normal_create3 = array('title' => $title, 'types' => $type, 'openedBuilds' => $openedBuild, 'severity' => $severity);
|
||||
|
||||
$title = array('异常一','异常二','异常三');
|
||||
$openedBuild = array(array('trunk'), array(''), array('1'));
|
||||
$exception_create = array('title' => $title, 'openedBuilds' => $openedBuild);
|
||||
|
||||
$bug = new bugTest();
|
||||
r($bug->batchCreateObject($productID, $normal_create1)) && p('0:title,openedBuild,type,severity,pri,product,execution') && e('批量bug一,trunk,3,codeerror,3,3,1,101'); // 测试正常批量创建bug1
|
||||
r($bug->batchCreateObject($productID, $normal_create2)) && p('1:title,openedBuild,type,severity,pri,product,execution') && e('批量bug五,trunk,codeerror,3,3,1,101'); // 测试正常批量创建bug2
|
||||
r($bug->batchCreateObject($productID, $normal_create3)) && p('2:title,openedBuild,type,severity,pri,product,execution') && e('批量bug九,1,config,3,3,1,0'); // 测试正常批量创建bug3
|
||||
r($bug->batchCreateObject($productID, $normal_create1)) && p() && e('0'); // 测试短时间内重复批量创建bug
|
||||
r($bug->batchCreateObject($productID, $exception_create)) && p() && e("<html><meta charset='utf-8'/><style>body{background:white}</style><script>alert('『影响版本』不能为空。')"); // 测试异常创建bug
|
||||
|
||||
system("./ztest init");
|
||||
55
test/model/bug/create.php
Executable file
55
test/model/bug/create.php
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/bug.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=bugModel->create();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
测试正常的创建代码错误bug >> 代码错误bug一
|
||||
测试正常的创建配置相关bug >> 1
|
||||
测试正常的创建安装部署bug >> 101
|
||||
测试正常的创建安全相关bug >> security
|
||||
测试正常的创建性能问题bug >> 3
|
||||
测试正常的创建标准规范bug >> active
|
||||
测试正常的创建测试脚本bug >> admin
|
||||
测试正常的创建设计缺陷bug >> 3
|
||||
测试正常的创建其他bug >> 2021-03-19
|
||||
测试不输入名称创建bug >> 『Bug标题』不能为空。
|
||||
测试不输入影响版本创建bug >> 『影响版本』不能为空。
|
||||
测试指派人bug >> user92
|
||||
|
||||
*/
|
||||
|
||||
$b_codeerror = array('title' => '代码错误bug一', 'type' => 'codeerror');
|
||||
$b_config = array('title' => '配置相关bug一', 'type' => 'config');
|
||||
$b_install = array('title' => '安装部署bug一', 'type' => 'install');
|
||||
$b_security = array('title' => '安全相关bug一', 'type' => 'security');
|
||||
$b_performance = array('title' => '性能问题bug一', 'type' => 'performance');
|
||||
$b_standard = array('title' => '标准规范bug一', 'type' => 'standard');
|
||||
$b_automation = array('title' => '测试脚本bug一', 'type' => 'automation');
|
||||
$b_designdefect = array('title' => '设计缺陷bug一', 'type' => 'designdefect');
|
||||
$b_others = array('title' => '其他bug一', 'type' => 'others');
|
||||
$b_notitle = array('title' => '', 'type' => 'codeerror');
|
||||
$b_nobuild = array('title' => '没有影响版本', 'type' => 'codeerror', 'openedBuild' => '');
|
||||
$b_assign = array('title' => '指派人user92', 'type' => 'codeerror', 'assignedTo' => 'user92');
|
||||
|
||||
$bug=new bugTest();
|
||||
r($bug->createObject($b_codeerror)) && p('title') && e('代码错误bug一'); // 测试正常的创建代码错误bug
|
||||
r($bug->createObject($b_config)) && p('product') && e('1'); // 测试正常的创建配置相关bug
|
||||
r($bug->createObject($b_install)) && p('execution') && e('101'); // 测试正常的创建安装部署bug
|
||||
r($bug->createObject($b_security)) && p('type') && e('security'); // 测试正常的创建安全相关bug
|
||||
r($bug->createObject($b_performance)) && p('pri') && e('3'); // 测试正常的创建性能问题bug
|
||||
r($bug->createObject($b_standard)) && p('status') && e('active'); // 测试正常的创建标准规范bug
|
||||
r($bug->createObject($b_automation)) && p('openedBy') && e('admin'); // 测试正常的创建测试脚本bug
|
||||
r($bug->createObject($b_designdefect)) && p('severity') && e('3'); // 测试正常的创建设计缺陷bug
|
||||
r($bug->createObject($b_others)) && p('deadline') && e('2021-03-19'); // 测试正常的创建其他bug
|
||||
r($bug->createObject($b_notitle)) && p('title:0') && e('『Bug标题』不能为空。'); // 测试不输入名称创建bug
|
||||
r($bug->createObject($b_nobuild)) && p('openedBuild:0') && e('『影响版本』不能为空。'); // 测试不输入影响版本创建bug
|
||||
r($bug->createObject($b_assign)) && p('assignedTo') && e('user92'); // 测试指派人bug
|
||||
|
||||
system("./ztest init");
|
||||
53
test/model/bug/createbugfromgitlabissue.php
Executable file
53
test/model/bug/createbugfromgitlabissue.php
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/bug.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=bugModel->createBugFromGitlabIssue ();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
测试正常的创建来源于gitlab issue的bug title >> 问题1
|
||||
测试短时间内重复创建来源于gitlab issue的bug >> 0
|
||||
测试正常的创建来源于gitlab issue的bug execution >> 101
|
||||
测试正常的创建来源于gitlab issue的bug pri >> 3
|
||||
测试正常的创建来源于gitlab issue的bug severity >> 3
|
||||
测试创建没有标题 来源于gitlab issue的异常bug >> 『Bug标题』不能为空。
|
||||
|
||||
*/
|
||||
|
||||
$executionID = 101;
|
||||
|
||||
$bug1 = new stdclass();
|
||||
$bug1->title = '问题1';
|
||||
$bug1->execution = $executionID;
|
||||
|
||||
|
||||
$bug2 = new stdclass();
|
||||
$bug2->title = '问题2';
|
||||
$bug2->execution = $executionID;
|
||||
|
||||
$bug3 = new stdclass();
|
||||
$bug3->title = '问题3';
|
||||
$bug3->execution = $executionID;
|
||||
|
||||
$bug4 = new stdclass();
|
||||
$bug4->title = '问题4';
|
||||
$bug4->execution = $executionID;
|
||||
|
||||
$bug5 = new stdclass();
|
||||
$bug5->title = '';
|
||||
$bug5->execution = $executionID;
|
||||
|
||||
$bug=new bugTest();
|
||||
r($bug->createBugFromGitlabIssueTest($bug1, $executionID)) && p('title') && e('问题1'); // 测试正常的创建来源于gitlab issue的bug title
|
||||
r($bug->createBugFromGitlabIssueTest($bug1, $executionID)) && p('task') && e('0'); // 测试短时间内重复创建来源于gitlab issue的bug
|
||||
r($bug->createBugFromGitlabIssueTest($bug2, $executionID)) && p('execution') && e($executionID); // 测试正常的创建来源于gitlab issue的bug execution
|
||||
r($bug->createBugFromGitlabIssueTest($bug3, $executionID)) && p('pri') && e('3'); // 测试正常的创建来源于gitlab issue的bug pri
|
||||
r($bug->createBugFromGitlabIssueTest($bug4, $executionID)) && p('severity') && e('3'); // 测试正常的创建来源于gitlab issue的bug severity
|
||||
r($bug->createBugFromGitlabIssueTest($bug5, $executionID)) && p('title:0') && e('『Bug标题』不能为空。'); // 测试创建没有标题 来源于gitlab issue的异常bug
|
||||
|
||||
system("./ztest init");
|
||||
46
test/model/bug/getbugs.php
Executable file
46
test/model/bug/getbugs.php
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/bug.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=bugModel->getBugs();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
查询正常产品 没有分支 查看全部 没有模块的全部bug的标题拼接1 >> BUG3,BUG2,BUG1
|
||||
查询正常产品 不存在的分支主干 查看全部 没有模块的全部bug的标题拼接 >> BUG3,BUG2,BUG1
|
||||
查询正常产品 没有分支 查看未关闭 没有模块的全部bug的标题拼接 >> BUG3,BUG2,BUG1
|
||||
查询正常产品 没有分支 查看全部 模块1821的全部bug的标题拼接 >> 0
|
||||
查询正常产品 没有分支 查看全部 模块不存在的全部bug的标题拼接 >> BUG3,BUG2,BUG1
|
||||
查询多分支产品 没有分支 查看全部 没有模块的全部bug的标题拼接59 >> BUG177,bug176,缺陷!@()(){}|+=%^&*$#测试bug名称到底可以有多长!@#¥%&*'":.<>。?/();175
|
||||
查询多分支产品 主干 查看全部 没有模块的全部bug的标题拼接 >> BUG177,bug176,缺陷!@()(){}|+=%^&*$#测试bug名称到底可以有多长!@#¥%&*'":.<>。?/();175
|
||||
查询多分支产品 分支37 查看全部 没有模块的全部bug的标题拼接 >> 0
|
||||
查询多分支产品 没有分支 查看未关闭 没有模块的全部bug的标题拼接 >> BUG177,bug176,缺陷!@()(){}|+=%^&*$#测试bug名称到底可以有多长!@#¥%&*'":.<>。?/();175
|
||||
查询多分支产品 没有分支 查看全部 模块2053的全部bug的标题拼接 >> 0
|
||||
查询不存在的产品的全部bug的标题拼接 >> 0
|
||||
|
||||
*/
|
||||
|
||||
$productIDList = array('1', '59', '1000001');
|
||||
$branchList = array('0', 'trunk', '37', '1000001');
|
||||
$browseTypeList = array('all', 'unclosed');
|
||||
$moduleIDList = array('0', '1821', '2053', '1000001');
|
||||
|
||||
$bug=new bugTest();
|
||||
|
||||
r($bug->getBugsTest($productIDList[0], $branchList[0], $browseTypeList[0], $moduleIDList[0])) && p('title') && e('BUG3,BUG2,BUG1'); // 查询正常产品 没有分支 查看全部 没有模块的全部bug的标题拼接1
|
||||
r($bug->getBugsTest($productIDList[0], $branchList[1], $browseTypeList[0], $moduleIDList[0])) && p('title') && e('BUG3,BUG2,BUG1'); // 查询正常产品 不存在的分支主干 查看全部 没有模块的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[0], $branchList[0], $browseTypeList[1], $moduleIDList[0])) && p('title') && e('BUG3,BUG2,BUG1'); // 查询正常产品 没有分支 查看未关闭 没有模块的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[0], $branchList[0], $browseTypeList[0], $moduleIDList[1])) && p('title') && e('0'); // 查询正常产品 没有分支 查看全部 模块1821的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[0], $branchList[0], $browseTypeList[0], $moduleIDList[3])) && p('title') && e('BUG3,BUG2,BUG1'); // 查询正常产品 没有分支 查看全部 模块不存在的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[1], $branchList[0], $browseTypeList[0], $moduleIDList[0])) && p('title') && e('BUG177,bug176,缺陷!@()(){}|+=%^&*$#测试bug名称到底可以有多长!@#¥%&*\'":.<>。?/();175'); // 查询多分支产品 没有分支 查看全部 没有模块的全部bug的标题拼接59
|
||||
r($bug->getBugsTest($productIDList[1], $branchList[1], $browseTypeList[0], $moduleIDList[0])) && p('title') && e('BUG177,bug176,缺陷!@()(){}|+=%^&*$#测试bug名称到底可以有多长!@#¥%&*\'":.<>。?/();175'); // 查询多分支产品 主干 查看全部 没有模块的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[1], $branchList[2], $browseTypeList[0], $moduleIDList[0])) && p('title') && e('0'); // 查询多分支产品 分支37 查看全部 没有模块的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[1], $branchList[0], $browseTypeList[1], $moduleIDList[0])) && p('title') && e('BUG177,bug176,缺陷!@()(){}|+=%^&*$#测试bug名称到底可以有多长!@#¥%&*\'":.<>。?/();175'); // 查询多分支产品 没有分支 查看未关闭 没有模块的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[1], $branchList[0], $browseTypeList[0], $moduleIDList[2])) && p('title') && e('0'); // 查询多分支产品 没有分支 查看全部 模块2053的全部bug的标题拼接
|
||||
r($bug->getBugsTest($productIDList[2], $branchList[0], $browseTypeList[0], $moduleIDList[0])) && p('title') && e('0'); // 查询不存在的产品的全部bug的标题拼接
|
||||
|
||||
system("./ztest init");
|
||||
@@ -37,6 +37,9 @@ switch($argv[1])
|
||||
case 'user':
|
||||
ztfRun('model/user');
|
||||
break;
|
||||
case 'bug':
|
||||
ztfRun('model/bug');
|
||||
break;
|
||||
case 'model':
|
||||
ztfRun('model');
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user