* Add gitlab unit test.
This commit is contained in:
@@ -178,7 +178,7 @@ class gitlab extends control
|
||||
|
||||
$userList = array();
|
||||
$gitlabUsers = $this->gitlab->apiGetUsers($gitlabID);
|
||||
$bindedUsers = $this->gitlab->getUserAccountIdPairs($gitlabID);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
$matchedResult = $this->gitlab->getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers);
|
||||
|
||||
foreach($gitlabUsers as $gitlabUserID => $gitlabUser)
|
||||
@@ -573,7 +573,7 @@ class gitlab extends control
|
||||
}
|
||||
|
||||
$users = $this->loadModel('user')->getList();
|
||||
$bindedUsers = $this->gitlab->getUserAccountIdPairs($gitlabID);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
$userPairs = array();
|
||||
$userInfos = array();
|
||||
foreach($users as $key => $user)
|
||||
@@ -620,7 +620,7 @@ class gitlab extends control
|
||||
$zentaoBindAccount = $this->dao->select('account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlabID)->andWhere('openID')->eq($gitlabUser->id)->fetch('account');
|
||||
|
||||
$users = $this->loadModel('user')->getList();
|
||||
$bindedUsers = $this->gitlab->getUserAccountIdPairs($gitlabID);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
$userPairs = array();
|
||||
foreach($users as $user)
|
||||
{
|
||||
@@ -1119,7 +1119,7 @@ class gitlab extends control
|
||||
|
||||
$repo = $this->loadModel('repo')->getByID($repoID);
|
||||
$users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
|
||||
$bindedUsers = $this->gitlab->getUserAccountIdPairs($repo->gitService);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($repo->gitService, 'gitlab', 'account,openID');
|
||||
|
||||
if(empty($repo->acl))
|
||||
{
|
||||
@@ -1169,7 +1169,7 @@ class gitlab extends control
|
||||
|
||||
/* Get users accesslevel. */
|
||||
$userAccessData = array();
|
||||
$bindedUsers = $this->gitlab->getUserIdAccountPairs($repo->gitService);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($repo->gitService, 'gitlab', 'openID,account');
|
||||
|
||||
foreach($projectMembers as $projectMember)
|
||||
{
|
||||
@@ -1235,36 +1235,6 @@ class gitlab extends control
|
||||
return print(json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax方式获取合并请求用户键值对。
|
||||
* AJAX: Get MR user pairs to select assignee_ids and reviewer_ids.
|
||||
* Attention: The user must be a member of the GitLab project.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetMRUserPairs(int $gitlabID, int $projectID)
|
||||
{
|
||||
if(!$gitlabID) return $this->send(array('message' => array()));
|
||||
|
||||
$bindedUsers = $this->gitlab->getUserIdRealnamePairs($gitlabID);
|
||||
$rawProjectUsers = $this->gitlab->apiGetProjectUsers($gitlabID, $projectID);
|
||||
$users = array();
|
||||
foreach($rawProjectUsers as $rawProjectUser)
|
||||
{
|
||||
if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id];
|
||||
}
|
||||
|
||||
$options = "<option value=''></option>";
|
||||
foreach($users as $index => $user)
|
||||
{
|
||||
$options .= "<option value='{$index}'>{$user}</option>";
|
||||
}
|
||||
$this->send($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个gitlab标签。
|
||||
* Create a gitlab tag.
|
||||
|
||||
+20
-86
@@ -107,74 +107,6 @@ class gitlabModel extends model
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitlab的用户id和禅道的账号 键值对。
|
||||
* Get gitlab user id and zentao account pairs of one gitlab.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUserIdAccountPairs(int $gitlabID): array
|
||||
{
|
||||
return $this->dao->select('openID,account')->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq('gitlab')
|
||||
->andWhere('providerID')->eq($gitlabID)
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitlab的禅道账号和gitlab用户id的 键值对。
|
||||
* Get zentao account gitlab user id pairs of one gitlab.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUserAccountIdPairs(int $gitlabID): array
|
||||
{
|
||||
return $this->dao->select('account,openID')->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq('gitlab')
|
||||
->andWhere('providerID')->eq($gitlabID)
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitlab用户id根据禅道账号。
|
||||
* Get gitlab user id by zentao account.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param string $zentaoAccount
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getUserIDByZentaoAccount(int $gitlabID, string $zentaoAccount): string
|
||||
{
|
||||
return $this->dao->select('openID')->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq('gitlab')
|
||||
->andWhere('providerID')->eq($gitlabID)
|
||||
->andWhere('account')->eq($zentaoAccount)
|
||||
->fetch('openID');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitlab列表根据禅道账号。
|
||||
* Get GitLab id list by user account.
|
||||
*
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getListByAccount(string $account = ''): array
|
||||
{
|
||||
if(!$account) $account = $this->app->user->account;
|
||||
|
||||
return $this->dao->select('providerID,openID')->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq('gitlab')
|
||||
->andWhere('account')->eq($account)
|
||||
->fetchPairs('providerID');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitlab的 项目id和名称 键值对。
|
||||
* Get project pairs of one gitlab.
|
||||
@@ -216,7 +148,7 @@ class gitlabModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
$bindedUsers = $this->getUserIdAccountPairs($gitlabID);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'openID,account');
|
||||
|
||||
$matchedUsers = array();
|
||||
foreach($gitlabUsers as $gitlabUser)
|
||||
@@ -452,9 +384,9 @@ class gitlabModel extends model
|
||||
* @param int $projectID
|
||||
* @param int $sudo
|
||||
* @access public
|
||||
* @return object|array|null
|
||||
* @return object|array|null|string
|
||||
*/
|
||||
public function apiGetTodoList(int $gitlabID, int $projectID, int $sudo): object|array|null
|
||||
public function apiGetTodoList(int $gitlabID, int $projectID, int $sudo): object|array|null|string
|
||||
{
|
||||
$gitlab = $this->loadModel('gitlab')->getByID($gitlabID);
|
||||
if(!$gitlab) return '';
|
||||
@@ -524,7 +456,7 @@ class gitlabModel extends model
|
||||
|
||||
/* Get linked users. */
|
||||
$linkedUsers = array();
|
||||
if($onlyLinked) $linkedUsers = $this->getUserIdAccountPairs($gitlabID);
|
||||
if($onlyLinked) $linkedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'openID,account');
|
||||
|
||||
$users = array();
|
||||
foreach($response as $gitlabUser)
|
||||
@@ -649,9 +581,9 @@ class gitlabModel extends model
|
||||
* @param int $gitlabID
|
||||
* @param object $group
|
||||
* @access public
|
||||
* @return object|array|null
|
||||
* @return object|array|null|false
|
||||
*/
|
||||
public function apiCreateGroup(int $gitlabID, object $group): object|array|null
|
||||
public function apiCreateGroup(int $gitlabID, object $group): object|array|null|false
|
||||
{
|
||||
if(empty($group->name) or empty($group->path)) return false;
|
||||
|
||||
@@ -687,6 +619,8 @@ class gitlabModel extends model
|
||||
$header = $result['header'];
|
||||
$recTotal = $header['X-Total'];
|
||||
$recPerPage = $header['X-Per-Page'];
|
||||
|
||||
$this->app->loadClass('pager', true);
|
||||
$pager = pager::init($recTotal, $recPerPage, $pager->pageID);
|
||||
|
||||
return array('pager' => $pager, 'projects' => json_decode($result['body']));
|
||||
@@ -734,11 +668,11 @@ class gitlabModel extends model
|
||||
* @param int $gitlabID
|
||||
* @param object $project
|
||||
* @access public
|
||||
* @return object|array|null
|
||||
* @return object|array|null|false
|
||||
*/
|
||||
public function apiCreateProject(int $gitlabID, object $project): object|array|null
|
||||
public function apiCreateProject(int $gitlabID, object $project): object|array|null|false
|
||||
{
|
||||
if(empty($project->name) and empty($project->path)) return false;
|
||||
if(empty($project->name) || empty($project->path)) return false;
|
||||
|
||||
$apiRoot = $this->getApiRoot($gitlabID);
|
||||
$url = sprintf($apiRoot, "/projects");
|
||||
@@ -753,9 +687,9 @@ class gitlabModel extends model
|
||||
* @param int $projectID
|
||||
* @param object $member
|
||||
* @access public
|
||||
* @return object|array|null
|
||||
* @return object|array|null|false
|
||||
*/
|
||||
public function apiCreateProjectMember(int $gitlabID, int $projectID, object $member): object|array|null
|
||||
public function apiCreateProjectMember(int $gitlabID, int $projectID, object $member): object|array|null|false
|
||||
{
|
||||
if(empty($member->user_id) or empty($member->access_level)) return false;
|
||||
|
||||
@@ -772,9 +706,9 @@ class gitlabModel extends model
|
||||
* @param int $projectID
|
||||
* @param object $member
|
||||
* @access public
|
||||
* @return object|array|null
|
||||
* @return object|array|null|false
|
||||
*/
|
||||
public function apiUpdateProjectMember(int $gitlabID, int $projectID, object $member): object|array|null
|
||||
public function apiUpdateProjectMember(int $gitlabID, int $projectID, object $member): object|array|null|false
|
||||
{
|
||||
if(empty($member->user_id) or empty($member->access_level)) return false;
|
||||
|
||||
@@ -2116,7 +2050,7 @@ class gitlabModel extends model
|
||||
public function taskToIssue(int $gitlabID, int $gitlabProjectID, object $task): object
|
||||
{
|
||||
$map = $this->config->gitlab->maps->task;
|
||||
$gitlabUsers = $this->getUserAccountIdPairs($gitlabID);
|
||||
$gitlabUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
|
||||
$issue = new stdclass;
|
||||
foreach($map as $taskField => $config)
|
||||
@@ -2158,7 +2092,7 @@ class gitlabModel extends model
|
||||
{
|
||||
$map = $this->config->gitlab->maps->story;
|
||||
$issue = new stdclass;
|
||||
$gitlabUsers = $this->getUserAccountIdPairs($gitlabID);
|
||||
$gitlabUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
if(empty($gitlabUsers)) return false;
|
||||
|
||||
foreach($map as $storyField => $config)
|
||||
@@ -2205,7 +2139,7 @@ class gitlabModel extends model
|
||||
{
|
||||
$map = $this->config->gitlab->maps->bug;
|
||||
$issue = new stdclass;
|
||||
$gitlabUsers = $this->getUserAccountIdPairs($gitlabID);
|
||||
$gitlabUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
if(empty($gitlabUsers)) return false;
|
||||
|
||||
foreach($map as $bugField => $config)
|
||||
@@ -2251,7 +2185,7 @@ class gitlabModel extends model
|
||||
*/
|
||||
public function parseObjectToIssue(int $gitlabID, int $projectID, string $objectType, object $object): object
|
||||
{
|
||||
$gitlabUsers = $this->getUserAccountIdPairs($gitlabID);
|
||||
$gitlabUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'account,openID');
|
||||
if(empty($gitlabUsers)) return false;
|
||||
$issue = new stdclass;
|
||||
$map = $this->config->gitlab->maps->$objectType;
|
||||
@@ -2300,7 +2234,7 @@ class gitlabModel extends model
|
||||
|
||||
if(isset($changes->assignees)) $changes->assignee_id = true;
|
||||
$maps = $this->config->gitlab->maps->{$issue->objectType};
|
||||
$gitlabUsers = $this->getUserIdAccountPairs($gitlabID);
|
||||
$gitlabUsers = $this->loadModel('pipeline')->getUserBindedPairs($gitlabID, 'gitlab', 'openID,account');
|
||||
|
||||
$object = new stdclass;
|
||||
$object->id = $issue->objectID;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiCreateGroup();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的名字创建gitlab群组 @return false
|
||||
- 使用空的群组URL创建gitlab群组 @return false
|
||||
- 使用错误gitlabID创建群组 @0
|
||||
- 通过gitlabID,projectID,分支对象正确创建GitLab分支 @1
|
||||
- 使用重复的分支信息创建分支属性message @Failed to save group {:path=>["已经被使用"]}
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
$group = new stdclass();
|
||||
$group->name = '';
|
||||
$group->path = 'unit_test_group17';
|
||||
$group->description = 'unit_test_group desc';
|
||||
$group->visibility = 'public';
|
||||
$group->request_access_enabled = '1';
|
||||
$group->lfs_enabled = '1';
|
||||
$group->project_creation_level = 'developer';
|
||||
$group->subgroup_creation_level = 'maintainer';
|
||||
|
||||
$result = $gitlab->apiCreateGroup($gitlabID, $group);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的名字创建gitlab群组
|
||||
|
||||
$group->name = 'unitTestGroup17';
|
||||
$group->path = '';
|
||||
$result = $gitlab->apiCreateGroup($gitlabID, $group);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的群组URL创建gitlab群组
|
||||
|
||||
r($gitlab->apiCreateGroup(0, $group)) && p() && e('0'); //使用错误gitlabID创建群组
|
||||
|
||||
$group->path = 'unit_test_group17';
|
||||
$result = $gitlab->apiCreateGroup($gitlabID, $group);
|
||||
if(!empty($result->name) and $result->name == $group->name) $result = true;
|
||||
if(!empty($result->message) and $result->message == 'Failed to save group {:path=>["已经被使用"]}') $result = true;
|
||||
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab分支
|
||||
r($gitlab->apiCreateGroup($gitlabID, $group)) && p('message') && e('Failed to save group {:path=>["已经被使用"]}'); //使用重复的分支信息创建分支
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiCreateProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的名字创建gitlab群组 @return false
|
||||
- 使用空的群组URL创建gitlab群组 @return false
|
||||
- 使用错误gitlabID创建群组 @0
|
||||
- 通过gitlabID,projectID,分支对象正确创建GitLab分支 @1
|
||||
- 使用重复的分支信息创建分支属性message @Failed to save project {:path=>["已经被使用"]}
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
$project = new stdclass();
|
||||
$project->name = '';
|
||||
$project->path = 'unit_test_project17';
|
||||
$project->description = 'unit_test_project desc';
|
||||
$project->visibility = 'public';
|
||||
$project->namespace_id = '1';
|
||||
|
||||
$result = $gitlab->apiCreateProject($gitlabID, $project);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的名字创建gitlab群组
|
||||
|
||||
$project->name = 'unitTestProject17';
|
||||
$project->path = '';
|
||||
$result = $gitlab->apiCreateProject($gitlabID, $project);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的群组URL创建gitlab群组
|
||||
|
||||
r($gitlab->apiCreateProject(0, $project)) && p() && e('0'); //使用错误gitlabID创建群组
|
||||
|
||||
$project->path = 'unit_test_project17';
|
||||
$result = $gitlab->apiCreateProject($gitlabID, $project);
|
||||
if(!empty($result->name) and $result->name == $project->name) $result = true;
|
||||
if(!empty($result->message->path[0]) and $result->message->path[0] == '已经被使用') $result = true;
|
||||
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab分支
|
||||
|
||||
$result = $gitlab->apiCreateProject($gitlabID, $project);
|
||||
r($result->message) && p('path:0') && e('已经被使用'); //使用重复的分支信息创建分支
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiCreateProjectMember();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的user_id创建gitlab群组 @return false
|
||||
- 使用空的access_level创建gitlab群组 @return false
|
||||
- 使用错误gitlabID创建群组 @0
|
||||
- 通过gitlabID,projectID,分支对象正确创建GitLab分支 @1
|
||||
- 使用重复的分支信息创建分支属性message @Member already exists
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
$projectID = 4;
|
||||
|
||||
$projectMember = new stdclass();
|
||||
$projectMember->user_id = '';
|
||||
$projectMember->access_level = '40';
|
||||
|
||||
$result = $gitlab->apiCreateProjectMember($gitlabID, $projectID, $projectMember);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的user_id创建gitlab群组
|
||||
|
||||
$projectMember->user_id = '4';
|
||||
$projectMember->access_level = '';
|
||||
$result = $gitlab->apiCreateProjectMember($gitlabID, $projectID, $projectMember);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的access_level创建gitlab群组
|
||||
|
||||
r($gitlab->apiCreateProjectMember(0, $projectID, $projectMember)) && p() && e('0'); //使用错误gitlabID创建群组
|
||||
|
||||
$projectMember->access_level = '40';
|
||||
$result = $gitlab->apiCreateProjectMember($gitlabID, $projectID, $projectMember);
|
||||
if(!empty($result->access_level) and $result->access_level == $projectMember->access_level) $result = true;
|
||||
if(!empty($result->message) and $result->message == 'Member already exists') $result = true;
|
||||
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab分支
|
||||
|
||||
r( $gitlab->apiCreateProjectMember($gitlabID, $projectID, $projectMember)) && p('message') && e('Member already exists'); //使用重复的分支信息创建分支
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiGetNamespaces();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 通过gitlabID,获取GitLab namespace列表 @1
|
||||
- 通过gitlabID,获取GitLab namespace数量 @1
|
||||
- 通过错误的gitlabID获取namespace列表 @0
|
||||
- 通过错误的gitlabID获取namespace列表数量 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('oauth')->gen(4);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
|
||||
$result = $gitlab->apiGetNamespaces($gitlabID);
|
||||
r(isset($result[0]->path)) && p() && e('1'); //通过gitlabID,获取GitLab namespace列表
|
||||
r(count($result) > 0) && p() && e('1'); //通过gitlabID,获取GitLab namespace数量
|
||||
|
||||
$result = $gitlab->apiGetNamespaces(0);
|
||||
r($result) && p() && e('0'); //通过错误的gitlabID获取namespace列表
|
||||
r(count($result)) && p() && e('0'); //通过错误的gitlabID获取namespace列表数量
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiGetProjects();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 通过gitlabID获取GitLab项目列表 @1
|
||||
- 通过gitlabID获取GitLab项目数量 @1
|
||||
- 通过gitlabID获取GitLab项目列表是否有visibility字段信息。 @0
|
||||
- 当gitlabID为0时,获取GitLab项目列表 @return empty
|
||||
- 通过gitlabID simple字段为false获取GitLab项目列表第0条的visibility属性 @private
|
||||
- 通过gitlabID minID为4获取GitLab项目列表第0条的name属性 @privateTest
|
||||
- 通过gitlabID maxID为4获取GitLab项目列表第0条的name属性 @testHtml
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
$orderBy = 'id_desc';
|
||||
$simple = 'true';
|
||||
|
||||
$result = $gitlab->apiGetProjects($gitlabID, $simple);
|
||||
r(isset($result[0]->name)) && p() && e('1'); //通过gitlabID获取GitLab项目列表
|
||||
r(count($result) > 0) && p() && e('1'); //通过gitlabID获取GitLab项目数量
|
||||
r(isset($result[0]->visibility)) && p() && e('0'); //通过gitlabID获取GitLab项目列表是否有visibility字段信息。
|
||||
|
||||
$gitlabID = 0;
|
||||
$result = $gitlab->apiGetProjects($gitlabID, $simple);
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //当gitlabID为0时,获取GitLab项目列表
|
||||
|
||||
$gitlabID = 1;
|
||||
$simple = 'false';
|
||||
$result = $gitlab->apiGetProjects($gitlabID, $simple);
|
||||
r($result) && p('0:visibility') && e('private'); //通过gitlabID simple字段为false获取GitLab项目列表
|
||||
|
||||
$simple = 'true';
|
||||
$minID = 4;
|
||||
$result = $gitlab->apiGetProjects($gitlabID, $simple, $minID);
|
||||
r($result) && p('0:name') && e('privateTest'); //通过gitlabID minID为4获取GitLab项目列表
|
||||
|
||||
$simple = 'true';
|
||||
$maxID = 2;
|
||||
$result = $gitlab->apiGetProjects($gitlabID, $simple, 0, $maxID);
|
||||
r($result) && p('0:name') && e('testHtml'); //通过gitlabID maxID为4获取GitLab项目列表
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiGetProjectsPager();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 通过gitlabID,projectID,获取GitLab项目列表 @1
|
||||
- 通过gitlabID,projectID,获取GitLab项目数量 @1
|
||||
- 当gitlabID为0时,获取GitLab项目列表 @return empty
|
||||
- 通过gitlabID,projectID,按项目名升序获取GitLab项目列表第1条的name属性 @testHtml
|
||||
- 通过gitlabID,projectID,搜索字符'zentaopms_15.2_20210720'获取GitLab项目列表第0条的name属性 @privateProject
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
$gitlab->app->moduleName = 'gitlab';
|
||||
$gitlab->app->methodName = 'browse';
|
||||
|
||||
$gitlabID = 1;
|
||||
$orderBy = 'id_desc';
|
||||
$keyword = '';
|
||||
|
||||
$pager = new stdclass();
|
||||
$pager->recPerPage = 5;
|
||||
$pager->pageID = 1;
|
||||
|
||||
$result = $gitlab->apiGetProjectsPager($gitlabID, $keyword, $orderBy, $pager);
|
||||
r(isset($result['projects'][0]->name)) && p() && e('1'); //通过gitlabID,获取GitLab项目列表
|
||||
r(count($result['projects']) > 0) && p() && e('1'); //通过gitlabID,获取GitLab项目数量
|
||||
|
||||
$gitlabID = 0;
|
||||
$result = $gitlab->apiGetProjectsPager($gitlabID, $keyword, $orderBy, $pager);
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //当gitlabID为0时,获取GitLab项目列表
|
||||
|
||||
$gitlabID = 1;
|
||||
$orderBy = 'id_asc';
|
||||
$result = $gitlab->apiGetProjectsPager($gitlabID, $keyword, $orderBy, $pager);
|
||||
r($result['projects']) && p('1:name') && e('testHtml'); //通过gitlabID,按项目名升序获取GitLab项目列表
|
||||
|
||||
$keyword = 'private';
|
||||
$result = $gitlab->apiGetProjectsPager($gitlabID, $keyword, $orderBy, $pager);
|
||||
r($result['projects']) && p('0:name') && e('privateProject'); //通过gitlabID,搜索字符'private'获取GitLab项目列表
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiGetTodoList();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 通过gitlabID,projectID,超级管理员获取GitLab待办列表 @1
|
||||
- 通过gitlabID,projectID,超级管理员获取GitLab待办数量 @1
|
||||
- 当前项目没有待办时,获取GitLab待办列表 @0
|
||||
- 当前项目有待办时,指定用户获取GitLab待办列表 @0
|
||||
- 当gitlabID存在,projectID不存在时,获取GitLab待办列表 @return empty
|
||||
- 当gitlabID,projectID都为0时,获取GitLab待办列表 @return empty
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
$projectID = 3;
|
||||
$sudo = 1;
|
||||
$result = $gitlab->apiGetTodoList($gitlabID, $projectID, $sudo);
|
||||
r(isset(array_shift($result)->author)) && p() && e('1'); //通过gitlabID,projectID,超级管理员获取GitLab待办列表
|
||||
r(count($result) > 0) && p() && e('1'); //通过gitlabID,projectID,超级管理员获取GitLab待办数量
|
||||
|
||||
$gitlabID = 1;
|
||||
$projectID = 2;
|
||||
r(count($gitlab->apiGetTodoList($gitlabID, $projectID, $sudo))) && p() && e('0'); //当前项目没有待办时,获取GitLab待办列表
|
||||
|
||||
$projectID = 3;
|
||||
$sudo = 4;
|
||||
r(count($gitlab->apiGetTodoList($gitlabID, $projectID, $sudo))) && p() && e('0'); //当前项目有待办时,指定用户获取GitLab待办列表
|
||||
|
||||
$gitlabID = 1;
|
||||
$projectID = 0;
|
||||
$result = $gitlab->apiGetTodoList($gitlabID, $projectID, $sudo);
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //当gitlabID存在,projectID不存在时,获取GitLab待办列表
|
||||
|
||||
$gitlabID = 0;
|
||||
$projectID = 0;
|
||||
$result = $gitlab->apiGetTodoList($gitlabID, $projectID, $sudo);
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //当gitlabID,projectID都为0时,获取GitLab待办列表
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiGetUsers();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 通过gitlabID,onlyLinked,获取GitLab用户列表 @1
|
||||
- 通过gitlabID,onlyLinked,获取GitLab用户数量 @1
|
||||
- 获取GitLab用户已做了关联的用户列表第0条的account属性 @user6
|
||||
- 获取GitLab用户已做了关联的用户列表数量 @2
|
||||
- 通过gitlabID,onlyLinked,按用户名升序获取GitLab用户列表第0条的account属性 @root
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('oauth')->gen(4);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
$onlyLinked = false;
|
||||
$result = $gitlab->apiGetUsers($gitlabID, $onlyLinked);
|
||||
r(isset($result[0]->account)) && p() && e('1'); //通过gitlabID,onlyLinked,获取GitLab用户列表
|
||||
r(count($result) > 0) && p() && e('1'); //通过gitlabID,onlyLinked,获取GitLab用户数量
|
||||
|
||||
$gitlabID = 1;
|
||||
$onlyLinked = true;
|
||||
$result = $gitlab->apiGetUsers($gitlabID, $onlyLinked);
|
||||
r($result) && p('0:account') && e('user6'); //获取GitLab用户已做了关联的用户列表
|
||||
r(count($result)) && p() && e('2'); //获取GitLab用户已做了关联的用户列表数量
|
||||
|
||||
$gitlabID = 1;
|
||||
$onlyLinked = false;
|
||||
$orderBy = 'id_asc';
|
||||
$result = $gitlab->apiGetUsers($gitlabID, $onlyLinked, $orderBy);
|
||||
r($result) && p('0:account') && e('root'); //通过gitlabID,onlyLinked,按用户名升序获取GitLab用户列表
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::getListByAccount();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 默认admin用户查询绑定的gitlab服务器 @0
|
||||
- 使用已绑定一个gitlab服务器的用户查询 @1
|
||||
- 使用未绑定gitlab服务器的用户查询 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('oauth')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
r(count($gitlab->getListByAccount())) && p() && e('0'); //默认admin用户查询绑定的gitlab服务器
|
||||
r(count($gitlab->getListByAccount('user3'))) && p() && e('1'); //使用已绑定一个gitlab服务器的用户查询
|
||||
r(count($gitlab->getListByAccount('test1'))) && p() && e('0'); //使用未绑定gitlab服务器的用户查询
|
||||
@@ -32,6 +32,6 @@ $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(count($matchedUsers)) && p('') && e('3'); // 获取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匹配的用户数量。
|
||||
r($gitlab->getMatchedUsersTest($gitlabID, $gitlabUsers, array())) && p('4:account,zentaoAccount') && e('user6,user6'); // 当禅道用户为空时获取gitlab服务器1匹配的用户数量。
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getUserAccountIdPairs();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取用户名为user3绑定的gitlab用户id。属性user3 @1
|
||||
- 获取用户名为user5绑定的gitlab用户id。属性user5 @3
|
||||
- 获取GitLab服务器不存在的绑定。属性user3 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('user')->gen(10);
|
||||
zdTable('oauth')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
r($gitlab->getUserAccountIdPairsTest($gitlabID = 1)) && p('user3') && e('1'); // 获取用户名为user3绑定的gitlab用户id。
|
||||
r($gitlab->getUserAccountIdPairsTest($gitlabID = 1)) && p('user5') && e('3'); // 获取用户名为user5绑定的gitlab用户id。
|
||||
r($gitlab->getUserAccountIdPairsTest($gitlabID = 10)) && p('user3') && e('0'); // 获取GitLab服务器不存在的绑定。
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getUserIdAccountPairs();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取GitLab服务器1用户id为1的绑定的用户名。属性1 @user3
|
||||
- 获取GitLab服务器1用户id为3的绑定的用户名。属性3 @user5
|
||||
- 获取GitLab服务器不存在用户id为3的绑定的用户名。属性1 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('user')->gen(10);
|
||||
zdTable('oauth')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
r($gitlab->getUserIdAccountPairsTest($gitlabID = 1)) && p('1') && e('user3'); // 获取GitLab服务器1用户id为1的绑定的用户名。
|
||||
r($gitlab->getUserIdAccountPairsTest($gitlabID = 1)) && p('3') && e('user5'); // 获取GitLab服务器1用户id为3的绑定的用户名。
|
||||
r($gitlab->getUserIdAccountPairsTest($gitlabID = 10)) && p('1') && e('0'); // 获取GitLab服务器不存在用户id为3的绑定的用户名。
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->getUserIDByZentaoAccount();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 根据禅道账号user3获取gitlab用户id。 @1
|
||||
- 根据禅道账号user5获取gitlab用户id。 @3
|
||||
- 根据禅道账号user3获取不存在的gitlab用户id。 @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('user')->gen(10);
|
||||
zdTable('oauth')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
r($gitlab->getUserIDByZentaoAccountTest($gitlabID = 1, 'user3')) && p() && e('1'); // 根据禅道账号user3获取gitlab用户id。
|
||||
r($gitlab->getUserIDByZentaoAccountTest($gitlabID = 1, 'user5')) && p() && e('3'); // 根据禅道账号user5获取gitlab用户id。
|
||||
r($gitlab->getUserIDByZentaoAccountTest($gitlabID = 10, 'user3')) && p() && e('0'); // 根据禅道账号user3获取不存在的gitlab用户id。
|
||||
Reference in New Issue
Block a user