* Add gitlab unit test.
This commit is contained in:
@@ -313,4 +313,31 @@ class gitlabTest
|
||||
$result = $this->gitlab->saveIssueRelation($objectType, $object, $gitlabID, $issue);
|
||||
return $result ? $this->gitlab->getRelationByObject($objectType, $object->id) : $result;
|
||||
}
|
||||
|
||||
public function createUserTest(int $gitlabID, object $gitlabUser)
|
||||
{
|
||||
$result = $this->gitlab->createUser($gitlabID, $gitlabUser);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createProjectTest(int $gitlabID, object $project)
|
||||
{
|
||||
$result = $this->gitlab->createProject($gitlabID, $project);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function editProjectTest(int $gitlabID, object $project)
|
||||
{
|
||||
$result = $this->gitlab->editProject($gitlabID, $project);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::createProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的名字创建gitlab项目第name条的0属性 @项目名称不能为空
|
||||
- 使用空的群组URL创建gitlab项目第path条的0属性 @项目标识串不能为空
|
||||
- 通过gitlabID,projectID,分支对象正确创建GitLab项目 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$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';
|
||||
|
||||
r($gitlab->createProjectTest($gitlabID, $project)) && p('name:0') && e('项目名称不能为空'); //使用空的名字创建gitlab项目
|
||||
|
||||
$project->name = 'unitTestProject17';
|
||||
$project->path = '';
|
||||
r($gitlab->createProjectTest($gitlabID, $project)) && p('path:0') && e('项目标识串不能为空'); //使用空的群组URL创建gitlab项目
|
||||
|
||||
$project->path = 'unit_test_project17';
|
||||
$result = $gitlab->createProjectTest($gitlabID, $project);
|
||||
if(!empty($result['name'][0]) and $result['name'][0] == '已经被使用') $result = true;
|
||||
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab项目
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::createUser();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的name创建gitlab用户第name条的0属性 @名称不能为空
|
||||
- 使用空的username创建gitlab用户第username条的0属性 @用户名不能为空
|
||||
- 检查二次密码不一致的情况 @二次密码不一致!
|
||||
- 通过gitlabID,projectID,分支对象正确创建GitLab用户 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
$gitlabID = 1;
|
||||
|
||||
$user = new stdclass();
|
||||
$user->account = 'admin';
|
||||
$user->name = '';
|
||||
$user->username = 'apiuser17';
|
||||
$user->email = 'apiuser17@test.com';
|
||||
$user->password = '12345678';
|
||||
$user->password_repeat = '';
|
||||
|
||||
r($gitlab->createUserTest($gitlabID, $user)) && p('name:0') && e('名称不能为空'); //使用空的name创建gitlab用户
|
||||
|
||||
$user->name = 'apiCreatedUser';
|
||||
$user->username = '';
|
||||
r($gitlab->createUserTest($gitlabID, $user)) && p('username:0') && e('用户名不能为空'); //使用空的username创建gitlab用户
|
||||
|
||||
$user->username = 'apiuser17';
|
||||
r($gitlab->createUserTest($gitlabID, $user)) && p('0') && e('二次密码不一致!'); //检查二次密码不一致的情况
|
||||
|
||||
$user->password_repeat = '12345678';
|
||||
$result = $gitlab->createUserTest($gitlabID, $user); //
|
||||
if(!empty($result[0]) and $result[0] == 'Email has already been taken') $result = true;
|
||||
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab用户
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::editProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的projectID创建gitlab群组 @0
|
||||
- 使用错误gitlabID创建群组 @0
|
||||
- 通过gitlabID,用户对象正确更新项目描述属性description @apiUpdatedProject
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 1;
|
||||
|
||||
/* Create project. */
|
||||
$project = new stdclass();
|
||||
$project->name = 'unitTestProject17';
|
||||
$project->path = 'unit_test_project17';
|
||||
$project->description = 'unit_test_project editproject unit test';
|
||||
$project->visibility = 'public';
|
||||
$project->namespace_id = '1';
|
||||
$gitlab->apiCreateProject($gitlabID, $project);
|
||||
|
||||
/* Get projectID. */
|
||||
$gitlabProjects = $gitlab->apiGetProjects($gitlabID);
|
||||
foreach($gitlabProjects as $gitlabProject)
|
||||
{
|
||||
if($gitlabProject->name == 'unitTestProject17')
|
||||
{
|
||||
$projectID = $gitlabProject->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$project = new stdclass();
|
||||
$project->description = 'editProject';
|
||||
|
||||
$gitlabTest = new gitlabTest();
|
||||
r($gitlabTest->editProjectTest($gitlabID, $project)) && p('name:0') && e('项目名称不能为空'); //使用空的projectID创建gitlab群组
|
||||
|
||||
$project->name = 'unitTestProject17';
|
||||
$project->id = $projectID;
|
||||
r($gitlabTest->editProjectTest($gitlabID, $project)) && p() && e('1'); //通过gitlabID,用户对象正确更新项目描述
|
||||
Reference in New Issue
Block a user