diff --git a/module/gitlab/test/gitlab.class.php b/module/gitlab/test/gitlab.class.php index b58fe64b8c..0644932e69 100644 --- a/module/gitlab/test/gitlab.class.php +++ b/module/gitlab/test/gitlab.class.php @@ -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; + } } diff --git a/module/gitlab/test/model/createproject.php b/module/gitlab/test/model/createproject.php new file mode 100644 index 0000000000..2b2a6d2d05 --- /dev/null +++ b/module/gitlab/test/model/createproject.php @@ -0,0 +1,40 @@ +#!/usr/bin/env php +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项目 \ No newline at end of file diff --git a/module/gitlab/test/model/createuser.php b/module/gitlab/test/model/createuser.php new file mode 100644 index 0000000000..edddca1cff --- /dev/null +++ b/module/gitlab/test/model/createuser.php @@ -0,0 +1,46 @@ +#!/usr/bin/env php +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用户 diff --git a/module/gitlab/test/model/editproject.php b/module/gitlab/test/model/editproject.php new file mode 100644 index 0000000000..3100e44ac4 --- /dev/null +++ b/module/gitlab/test/model/editproject.php @@ -0,0 +1,53 @@ +#!/usr/bin/env php +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,用户对象正确更新项目描述