* Unit test and adjust code
This commit is contained in:
+8
-3
@@ -52,7 +52,7 @@ class mrModel extends model
|
||||
if($filterProjects === false) return array();
|
||||
|
||||
$filterProjectSql = '';
|
||||
if(!empty($filterProjects))
|
||||
if(!$this->app->user->admin and !empty($filterProjects))
|
||||
{
|
||||
foreach($filterProjects as $gitlabID => $projects)
|
||||
{
|
||||
@@ -113,9 +113,14 @@ class mrModel extends model
|
||||
if(!$this->app->user->admin and !isset($gitlabUsers[$gitlabID])) continue;
|
||||
|
||||
$allProjects[$gitlabID] = $this->gitlab->apiGetProjects($gitlabID, 'false');
|
||||
|
||||
/* If not an administrator, need to obtain group member information. */
|
||||
$groupIDList = array(0 => 0);
|
||||
$groups = $this->gitlab->apiGetGroups($gitlabID, 'name_asc', $this->config->gitlab->accessLevel['reporter']);
|
||||
foreach($groups as $group) $groupIDList[] = $group->id;
|
||||
if(!$this->app->user->admin)
|
||||
{
|
||||
$groups = $this->gitlab->apiGetGroups($gitlabID, 'name_asc', $this->config->gitlab->accessLevel['reporter']);
|
||||
foreach($groups as $group) $groupIDList[] = $group->id;
|
||||
}
|
||||
$allGroups[$gitlabID] = $groupIDList;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pid=1
|
||||
通过gitlabID,projectID,获取GitLab分支列表 >> 1
|
||||
通过gitlabID,projectID,获取GitLab分支数量 >> 1
|
||||
当前项目没有分支时,获取GitLab分支列表 >> 0
|
||||
当gitlabID存在,projectID不存在时,获取GitLab分支列表 >> 404 Project Not Found
|
||||
当gitlabID存在,projectID不存在时,获取GitLab分支列表 >> return empty
|
||||
当gitlabID,projectID都为0时,获取GitLab分支列表 >> return empty
|
||||
|
||||
*/
|
||||
@@ -30,7 +30,9 @@ r(count($gitlab->apiGetBranches($gitlabID, $projectID))) && p() && e(0); //当
|
||||
|
||||
$gitlabID = 1;
|
||||
$projectID = 0;
|
||||
r($gitlab->apiGetBranches($gitlabID, $projectID)) && p('message') && e('404 Project Not Found'); //通过gitlabID,projectID,获取GitLab分支列表
|
||||
$result = $gitlab->apiGetBranches($gitlabID, $projectID);
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //当gitlabID存在,projectID不存在时,获取GitLab分支列表
|
||||
|
||||
$gitlabID = 0;
|
||||
$projectID = 0;
|
||||
|
||||
+10
-10
@@ -8,9 +8,9 @@ title=测试 mrModel::create();
|
||||
cid=0
|
||||
pid=0
|
||||
|
||||
使用空的repoID, gitlabID数据 >> 『GitLab』不能为空。
|
||||
使用空的repoID, gitlabID。创建mr。 >> 『GitLab』不能为空。
|
||||
使用正确的repoID, gitlabID。POST数据正确 或者错误原因为已存在一样的mr请求 >> success
|
||||
使用源分支和目标分支一样的数据mr请求 >> 通过API创建合并请求失败,失败原因:源项目分支与目标项目分支不能相同
|
||||
使用源分支和目标分支一样的数据mr请求 >> 通过API创建合并请求失败,失败原因:源项目分支与目标项目分支不能相同
|
||||
|
||||
*/
|
||||
|
||||
@@ -18,16 +18,16 @@ $mrModel = $tester->loadModel('mr');
|
||||
|
||||
$_POST = array();
|
||||
|
||||
$_POST['gitlabID'] = 0;
|
||||
$_POST['repoID'] = 0;
|
||||
$_POST['gitlabID'] = 0;
|
||||
$_POST['repoID'] = 0;
|
||||
$_POST['sourceProject'] = 42;
|
||||
$_POST['sourceBranch'] = 'branch-08';
|
||||
$_POST['targetProject'] = 42;
|
||||
$_POST['targetBranch'] = 'branch-09';
|
||||
$result = $mrModel->create();
|
||||
r($result) && p('message[gitlabID]:0') && e('『GitLab』不能为空。'); //使用空的repoID, gitlabID。创建mr。
|
||||
|
||||
$_POST['gitlabID'] = 1;
|
||||
$_POST['sourceProject'] = 42;
|
||||
$_POST['sourceBranch'] = 'branch-08';
|
||||
$_POST['targetProject'] = 42;
|
||||
$_POST['targetBranch'] = 'branch-09';
|
||||
$_POST['title'] = 'test_create';
|
||||
$_POST['description'] = 'test_create';
|
||||
$_POST['repoID'] = 1;
|
||||
@@ -35,10 +35,10 @@ $_POST['assignee'] = '';
|
||||
$_POST['removeSourceBranch'] = '1';
|
||||
$result = $mrModel->create();
|
||||
if($result['result'] == 'success') $result = 'success';
|
||||
$result = preg_match('/通过API创建合并请求失败,失败原因:存在另外一个同样的合并请求在源项目分支中: !([0-9]+)/', $result['message'], $matches); //检查错误原因是否是已存在一样的mr请求
|
||||
$result = preg_match('/存在另外一个同样的合并请求在源项目分支中: ID([0-9]+)/', $result['message'], $matches); //检查错误原因是否是已存在一样的mr请求
|
||||
if($result) $result = 'success';
|
||||
r($result) && p() && e('success'); //使用正确的repoID, gitlabID。POST数据正确 或者错误原因为已存在一样的mr请求
|
||||
|
||||
$_POST['targetBranch'] = 'branch-08';
|
||||
$result = $mrModel->create();
|
||||
r($result) && p('message') && e('通过API创建合并请求失败,失败原因:源项目分支与目标项目分支不能相同'); //使用源分支和目标分支一样的数据mr请求
|
||||
r($result) && p('message') && e('通过API创建合并请求失败,失败原因:源项目分支与目标项目分支不能相同'); //使用源分支和目标分支一样的数据mr请求
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 mrModel::getAllGitlabProjects();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
普通用户获取所有gitlab服务器项目列表 >> return empty
|
||||
|
||||
*/
|
||||
|
||||
$mrModel = $tester->loadModel('mr');
|
||||
|
||||
$result = $mrModel->getAllGitlabProjects();
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //普通用户获取所有gitlab服务器项目列表
|
||||
|
||||
su('admin');
|
||||
$result = $mrModel->getAllGitlabProjects();
|
||||
r(isset(array_shift($result[1])->name)) && p() && e(1); //管理员获取所有gitlab服务器项目列表
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 mrModel::getList();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
普通用户获取mr列表 >> return empty
|
||||
管理员获取mr列表 >> Test MR
|
||||
|
||||
*/
|
||||
|
||||
$tester->app->loadClass('pager', $static = true);
|
||||
$mrModel = $tester->loadModel('mr');
|
||||
|
||||
$mode = 'all';
|
||||
$param = 'all';
|
||||
$orderBy = 'id_desc';
|
||||
$pager = new pager(0, 20, 1);
|
||||
|
||||
$projects = $mrModel->getAllGitlabProjects();
|
||||
$result = $mrModel->getList($mode, $param, $orderBy, $pager, empty($projects) ? false : $projects);
|
||||
if(empty($result)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //普通用户获取mr列表
|
||||
|
||||
su('admin');
|
||||
$projects = $mrModel->getAllGitlabProjects();
|
||||
$result = $mrModel->getList($mode, $param, $orderBy, $pager, empty($projects) ? false : $projects);
|
||||
r(array_shift($result)) && p('title') && e('Test MR'); //管理员获取mr列表
|
||||
@@ -16,7 +16,7 @@ pid=1
|
||||
$sonarqube = $tester->loadModel('sonarqube');
|
||||
|
||||
$sonarqubeID = 2;
|
||||
$sonarqubeServer = $sonarqube->getByID($sonarqubeID);
|
||||
$sonarqubeServer = $tester->loadModel('pipeline')->getByID($sonarqubeID);
|
||||
$result = $sonarqube->apiValidate($sonarqubeServer->url, $sonarqubeServer->token);
|
||||
r($result) && p('valid') && e(1); //通过host,token检验api权限
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ title=测试 sonarqubeModel::getApiBase();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过sonarqubeID,获取SonarQube url和header >> http://192.168.1.161:59001/api/%s
|
||||
通过sonarqubeID,获取SonarQube url和header >> http://192.168.1.161:59001/api/%s
|
||||
当sonarqubeID为0时,获取SonarQube url和header >> return empty
|
||||
|
||||
*/
|
||||
@@ -22,4 +22,4 @@ r($apiRoot) && p() && e('http://192.168.1.161:59001/api/%s'); //通过sonarqubeI
|
||||
$sonarqubeID = 0;
|
||||
list($apiRoot, $header) = $sonarqube->getApiBase($sonarqubeID);
|
||||
if(empty($apiRoot)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube url和header
|
||||
r($result) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube url和header
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::getByID();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过id获取sonarqube服务器 >> sonarqube服务器
|
||||
通过空的id获取sonarqube服务器 >> return empty
|
||||
|
||||
*/
|
||||
|
||||
$sonarqube = $tester->loadModel('sonarqube');
|
||||
|
||||
$sonarqubeID = 2;
|
||||
$sonarqubeServer = $sonarqube->getByID($sonarqubeID);
|
||||
r($sonarqubeServer) && p('name') && e('sonarqube服务器'); //通过id获取sonarqube服务器
|
||||
|
||||
$sonarqubeID = 0;
|
||||
$sonarqubeServer = $sonarqube->getByID($sonarqubeID);
|
||||
if(empty($sonarqubeServer)) $result = 'return empty';
|
||||
r($result) && p() && e('return empty'); //通过空的id获取sonarqube服务器
|
||||
Reference in New Issue
Block a user