* Add gitlab module unit tests.
This commit is contained in:
@@ -69,9 +69,50 @@ class gitlabTest
|
||||
return $this->gitlab->getUserAccountIdPairs($gitlabID);
|
||||
}
|
||||
|
||||
public function getUserIDByZentaoAccountTest(int $gitlab, string $zentaoAccount)
|
||||
public function getUserIDByZentaoAccountTest(int $gitlabID, string $zentaoAccount)
|
||||
{
|
||||
return $this->gitlab->getUserIDByZentaoAccount($gitlab, $zentaoAccount);
|
||||
return $this->gitlab->getUserIDByZentaoAccount($gitlabID, $zentaoAccount);
|
||||
}
|
||||
|
||||
public function getProjectPairsTest(int $gitlabID)
|
||||
{
|
||||
return $this->gitlab->getProjectPairs($gitlabID);
|
||||
}
|
||||
|
||||
public function getMatchedUsersTest(int $gitlabID, array $gitlabUsers = array(), array $zentaoUsers = array())
|
||||
{
|
||||
return $this->gitlab->getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers);
|
||||
}
|
||||
|
||||
public function getRelationByObjectTest(string $objectType, int $objectID)
|
||||
{
|
||||
return $this->gitlab->getRelationByObject($objectType, $objectID);
|
||||
}
|
||||
|
||||
public function getIssueListByObjectsTest(string $objectType, array $objects)
|
||||
{
|
||||
return $this->gitlab->getIssueListByObjects($objectType, $objects);
|
||||
}
|
||||
|
||||
public function getProjectNameTest(int $gitlabID, int $projectID)
|
||||
{
|
||||
return $this->gitlab->getProjectName($gitlabID, $projectID);
|
||||
}
|
||||
|
||||
public function getBranchesTest(int $gitlabID, int $projectID)
|
||||
{
|
||||
return $this->gitlab->getBranches($gitlabID, $projectID);
|
||||
}
|
||||
|
||||
public function getReferenceOptionsTest(int $gitlabID, int $projectID)
|
||||
{
|
||||
return $this->gitlab->getReferenceOptions($gitlabID, $projectID);
|
||||
}
|
||||
|
||||
public function setProjectTest(int $gitlabID, int $projectID, object $project)
|
||||
{
|
||||
$this->gitlab->setProject($gitlabID, $projectID, $project);
|
||||
return $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +197,20 @@ class gitlabTest
|
||||
return $this->gitlab->apiGetSingleTag($gitlabID, $projectID, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api get signle project.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @param string $tag
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetSingleProjectTest(int $gitlabID, int $projectID, bool $useUser = true)
|
||||
{
|
||||
return $this->gitlab->apiGetSingleProject($gitlabID, $projectID, $useUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get gitlab menu.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->apiGetSingleProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 查询正确的project信息属性name @testHtml
|
||||
- 使用不存在的gitlabID查询project信息 @0
|
||||
- 使用不存在的projectID查询project信息属性message @404 Project Not Found
|
||||
- 用普通用户查询有权限正确的project信息属性id @2
|
||||
- 用普通用户查询无权限正确的project信息属性message @404 Project Not Found
|
||||
- 第三个参数为fales普通用户查询无权限正确的project信息属性name @privateTest
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$project1 = $gitlab->apiGetSingleProjectTest(1, 2);
|
||||
$project2 = $gitlab->apiGetSingleProjectTest(0, 2);
|
||||
$project3 = $gitlab->apiGetSingleProjectTest(1, 0);
|
||||
$project4 = $gitlab->apiGetSingleProjectTest(1, 2);
|
||||
|
||||
r($project1) && p('name') && e('testHtml'); // 查询正确的project信息
|
||||
r($project2) && p() && e('0'); // 使用不存在的gitlabID查询project信息
|
||||
r($project3) && p('message') && e('404 Project Not Found'); // 使用不存在的projectID查询project信息
|
||||
|
||||
su('user6');
|
||||
$project5 = $gitlab->apiGetSingleProjectTest(1, 2, true);
|
||||
$project6 = $gitlab->apiGetSingleProjectTest(1, 4, true);
|
||||
$project7 = $gitlab->apiGetSingleProjectTest(1, 5, false);
|
||||
r($project5) && p('id') && e('2'); // 用普通用户查询有权限正确的project信息
|
||||
r($project6) && p('message') && e('404 Project Not Found'); // 用普通用户查询无权限正确的project信息
|
||||
r($project7) && p('name') && e('privateTest'); // 第三个参数为fales普通用户查询无权限正确的project信息
|
||||
@@ -49,4 +49,4 @@ r($gitlab->checkUserAccess($gitlabID, $projectID, $project)) && p() && e('1'); /
|
||||
$projectID = 9;
|
||||
r($gitlab->checkUserAccess($gitlabID, $projectID, null, array(), 'maintainer')) && p() && e('0'); //切换普通用户,使用当前用户是开发者的项目ID判断权限是否有维护者权限
|
||||
|
||||
r($gitlab->checkUserAccess($gitlabID, $projectID, $project, array(), 'maintainer')) && p() && e('1'); //切换普通用户,使用当前用户是拥有者的项目ID判断权限是否有维护者权限
|
||||
r($gitlab->checkUserAccess($gitlabID, $projectID, $project, array(), 'maintainer')) && p() && e('1'); //切换普通用户,使用当前用户是拥有者的项目ID判断权限是否有维护者权限
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getBranches();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab服务器1空项目id 1的项目分支。 @0
|
||||
- 获取gitlab服务器1项目id 2的项目分支。 @branch1
|
||||
- 获取gitlab服务器1项目id 2的项目分支数量。 @1
|
||||
- 获取不存在gitlab服务器项目id 1的项目分支。 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$projectIds = array(1, 2);
|
||||
$branches = $gitlab->getBranchesTest($gitlabID = 1, $projectIds[1]);
|
||||
|
||||
r($gitlab->getBranchesTest($gitlabID = 1, $projectIds[0])) && p('0') && e('0'); // 获取gitlab服务器1空项目id 1的项目分支。
|
||||
r($branches) && p('0') && e('branch1'); // 获取gitlab服务器1项目id 2的项目分支。
|
||||
r(count($branches) > 2) && p() && e('1'); // 获取gitlab服务器1项目id 2的项目分支数量。
|
||||
r($gitlab->getBranchesTest($gitlabID = 10, $projectIds[0])) && p('0') && e('0'); // 获取不存在gitlab服务器项目id 1的项目分支。
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getIssueListByObjects();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取任务18对应的issueID。
|
||||
- 第18条的issueID属性 @4
|
||||
- 第19条的issueID属性 @1
|
||||
- 获取bug5对应的issueID。第5条的issueID属性 @3
|
||||
- 获取需求8对应的issueID。第8条的issueID属性 @2
|
||||
|
||||
*/
|
||||
|
||||
zdTable('relation')->config('relation')->gen(4);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$taskIds = array(18, 19);
|
||||
$bugIds = array(5);
|
||||
$storyIds = array(8);
|
||||
|
||||
r($gitlab->getIssueListByObjectsTest('task', $taskIds)) && p('18:issueID;19:issueID') && e('4,1'); // 获取任务18对应的issueID。
|
||||
r($gitlab->getIssueListByObjectsTest('bug', $bugIds)) && p('5:issueID') && e('3'); // 获取bug5对应的issueID。
|
||||
r($gitlab->getIssueListByObjectsTest('story', $storyIds)) && p('8:issueID') && e('2'); // 获取需求8对应的issueID。
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getMatchedUsers();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab服务器1匹配的用户列表。
|
||||
- 第1条的account属性 @root
|
||||
- 第1条的zentaoAccount属性 @user3
|
||||
- 获取gitlab服务器1匹配的用户数量。 @2
|
||||
- 当gitlab用户为空时获取gitlab服务器1匹配的用户数量。 @0
|
||||
- 当禅道用户为空时获取gitlab服务器1匹配的用户数量。
|
||||
- 第4条的account属性 @user6
|
||||
- 第4条的zentaoAccount属性 @user6
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('oauth')->gen(5);
|
||||
zdTable('user')->gen(10);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$gitlabID = 1;
|
||||
$gitlabUsers = $gitlab->gitlab->apiGetUsers($gitlabID);
|
||||
$zentaoUsers = $gitlab->gitlab->dao->select('account,email,realname')->from(TABLE_USER)->where('deleted')->eq('0')->fetchAll('account');
|
||||
$matchedUsers = $gitlab->getMatchedUsersTest($gitlabID, $gitlabUsers, $zentaoUsers);
|
||||
r($matchedUsers) && p('1:account,zentaoAccount') && e('root,user3'); // 获取gitlab服务器1匹配的用户列表。
|
||||
r(count($matchedUsers)) && p('') && e('2'); // 获取gitlab服务器1匹配的用户数量。
|
||||
r($gitlab->getMatchedUsersTest($gitlabID, array(), $zentaoUsers)) && p('') && e('0'); // 当gitlab用户为空时获取gitlab服务器1匹配的用户数量。
|
||||
r($gitlab->getMatchedUsersTest($gitlabID, $gitlabUsers, array())) && p('4:account,zentaoAccount') && e('user6,user6'); // 当禅道用户为空时获取gitlab服务器1匹配的用户数量。
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getProjectName();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab服务器1项目id 1的项目名称。 @Monitoring
|
||||
- 获取gitlab服务器1项目id 2的项目名称。 @testHtml
|
||||
- 获取不存在gitlab服务器项目id 1的项目名称。 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$projectIds = array(1, 2);
|
||||
|
||||
r($gitlab->getProjectNameTest($gitlabID = 1, $projectIds[0])) && p() && e('Monitoring'); // 获取gitlab服务器1项目id 1的项目名称。
|
||||
r($gitlab->getProjectNameTest($gitlabID = 1, $projectIds[1])) && p() && e('testHtml'); // 获取gitlab服务器1项目id 2的项目名称。
|
||||
r($gitlab->getProjectNameTest($gitlabID = 10, $projectIds[0])) && p() && e('0'); // 获取不存在gitlab服务器项目id 1的项目名称。
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getProjectPairs();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab服务器1的项目1的名称。属性1 @GitLab Instance / Monitoring
|
||||
- 获取gitlab服务器1的项目2的名称。属性2 @GitLab Instance / testHtml
|
||||
- 获取GitLab服务器不存在的项目名称。属性1 @0
|
||||
|
||||
*/
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
r($gitlab->getProjectPairsTest($gitlabID = 1)) && p('1') && e('GitLab Instance / Monitoring'); // 获取gitlab服务器1的项目1的名称。
|
||||
r($gitlab->getProjectPairsTest($gitlabID = 1)) && p('2') && e('GitLab Instance / testHtml'); // 获取gitlab服务器1的项目2的名称。
|
||||
r($gitlab->getProjectPairsTest($gitlabID = 10)) && p('1') && e('0'); // 获取GitLab服务器不存在的项目名称。
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getReferenceOptions();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab服务器1空项目id 1的项目分支和标签。 @0
|
||||
- 获取gitlab服务器1项目id 2的项目分支和标签。
|
||||
- 属性branch1 @Branch::branch1
|
||||
- 属性tag1 @Tag::tag1
|
||||
- 获取gitlab服务器1项目id 2的项目分支数量。 @1
|
||||
- 获取不存在gitlab服务器项目id 1的项目分支和标签。 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$projectIds = array(1, 2);
|
||||
$branches = $gitlab->getReferenceOptionsTest($gitlabID = 1, $projectIds[1]);
|
||||
|
||||
r($gitlab->getReferenceOptionsTest($gitlabID = 1, $projectIds[0])) && p('0') && e('0'); // 获取gitlab服务器1空项目id 1的项目分支和标签。
|
||||
r($branches) && p('branch1;tag1') && e('Branch::branch1,Tag::tag1'); // 获取gitlab服务器1项目id 2的项目分支和标签。
|
||||
r(count($branches) > 4) && p() && e('1'); // 获取gitlab服务器1项目id 2的项目分支数量。
|
||||
r($gitlab->getReferenceOptionsTest($gitlabID = 10, $projectIds[0])) && p('0') && e('0'); // 获取不存在gitlab服务器项目id 1的项目分支和标签。
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getRelationByObject();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取任务18对应的issueID。属性issueID @4
|
||||
- 获取bug5对应的issueID。属性issueID @3
|
||||
- 获取需求8对应的issueID。属性issueID @2
|
||||
|
||||
*/
|
||||
|
||||
zdTable('relation')->config('relation')->gen(4);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
r($gitlab->getRelationByObjectTest('task', 18)) && p('issueID') && e('4'); // 获取任务18对应的issueID。
|
||||
r($gitlab->getRelationByObjectTest('bug', 5)) && p('issueID') && e('3'); // 获取bug5对应的issueID。
|
||||
r($gitlab->getRelationByObjectTest('story', 8)) && p('issueID') && e('2'); // 获取需求8对应的issueID。
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->setProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试设置project。属性name @test_project
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$projectId = 1;
|
||||
|
||||
$project = new stdclass();
|
||||
$project->id = 1;
|
||||
$project->name = 'test_project';
|
||||
|
||||
r($gitlab->setProjectTest($gitlabID = 1, $projectId, $project)) && p('name') && e('test_project'); // 测试设置project。
|
||||
@@ -0,0 +1,82 @@
|
||||
title: table zt_relation
|
||||
desc: "issue关系"
|
||||
author: automated export
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
note: "ID"
|
||||
range: 1-4
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: product
|
||||
note: "所属产品"
|
||||
range: 1
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: execution
|
||||
note: "所属执行"
|
||||
range: "2,1"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: AType
|
||||
note: "object类型"
|
||||
range: task,bug,story
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: AID
|
||||
note: "自身ID"
|
||||
range: "18,5,8,19"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: AVersion
|
||||
note: "自身版本"
|
||||
range: 2
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: relation
|
||||
note: "关联关系"
|
||||
range: gitlab
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: BType
|
||||
note: "被关联需求类型"
|
||||
range: issue
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: BID
|
||||
note: "被关联需求ID"
|
||||
range: "4,3,2,1"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: BVersion
|
||||
note: "被关联版本"
|
||||
range: 2
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: extra
|
||||
note: ""
|
||||
range: 1
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
Reference in New Issue
Block a user