From 05db40a333c1e513f27165e6e9f1fb79a3282d7e Mon Sep 17 00:00:00 2001 From: liugang Date: Sat, 20 Sep 2025 12:48:14 +0800 Subject: [PATCH] * [misc] Enhance unit tests for gitlabModel::apiUpdateGroup() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../gitlab/test/lib/gitlab.unittest.class.php | 16 ++++++ module/gitlab/test/model/apiupdategroup.php | 49 +++++++++++++------ 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/module/gitlab/test/lib/gitlab.unittest.class.php b/module/gitlab/test/lib/gitlab.unittest.class.php index ea0805642f..38e63319fa 100755 --- a/module/gitlab/test/lib/gitlab.unittest.class.php +++ b/module/gitlab/test/lib/gitlab.unittest.class.php @@ -49,6 +49,22 @@ class gitlabTest return $pairs; } + /** + * Test apiUpdateGroup method. + * + * @param int $gitlabID + * @param object $group + * @access public + * @return mixed + */ + public function apiUpdateGroupTest(int $gitlabID, object $group): mixed + { + $result = $this->gitlab->apiUpdateGroup($gitlabID, $group); + if(dao::isError()) return dao::getError(); + + return $result; + } + /** * Test apiDeleteGroup method. * diff --git a/module/gitlab/test/model/apiupdategroup.php b/module/gitlab/test/model/apiupdategroup.php index 53a8e266f3..d6e26bbd15 100755 --- a/module/gitlab/test/model/apiupdategroup.php +++ b/module/gitlab/test/model/apiupdategroup.php @@ -8,22 +8,28 @@ title=测试 gitlabModel::apiUpdateGroup(); timeout=0 cid=1 -- 使用空的groupID创建gitlab群组 @0 -- 使用错误gitlabID创建群组 @0 -- 通过gitlabID,用户对象正确更新用户名字属性description @apiUpdatedGroup +- 执行gitlab模块的apiUpdateGroup方法,参数是$gitlabID, $emptyGroup @0 +- 执行gitlab模块的apiUpdateGroup方法,参数是0, $invalidGroup @0 +- 执行gitlab模块的apiUpdateGroup方法,参数是$gitlabID, $invalidGroup 属性description @apiUpdatedGroup +- 执行gitlab模块的apiUpdateGroup方法,参数是$gitlabID, $validGroup 属性name @Updated Group Name +- 执行gitlab模块的apiUpdateGroup方法,参数是$gitlabID, $nonExistentGroup @~~ */ zenData('pipeline')->gen(5); +global $app; +$app->rawModule = 'gitlab'; +$app->rawMethod = 'browse'; + $gitlab = $tester->loadModel('gitlab'); -$gitlabID = 1; +$gitlabID = 1; -/* Create group. */ +/* Create test group first. */ $group = new stdclass(); -$group->name = 'unitTestGroup17'; -$group->path = 'unit_test_group17'; +$group->name = 'unitTestGroup99'; +$group->path = 'unit_test_group99'; $group->description = 'unit_test_group desc'; $group->visibility = 'public'; $group->request_access_enabled = '1'; @@ -34,20 +40,35 @@ $gitlab->apiCreateGroup($gitlabID, $group); /* Get groupID. */ $gitlabGroups = $gitlab->apiGetGroups($gitlabID); +$groupID = 0; foreach($gitlabGroups as $gitlabGroup) { - if($gitlabGroup->name == 'unitTestGroup17') + if($gitlabGroup->name == 'unitTestGroup99') { $groupID = $gitlabGroup->id; break; } } -$group = new stdclass(); -$group->description = 'apiUpdatedGroup'; +/* Test cases. */ +$emptyGroup = new stdclass(); +$emptyGroup->description = 'test description'; -r($gitlab->apiUpdateGroup($gitlabID, $group)) && p() && e('0'); //使用空的groupID创建gitlab群组 -r($gitlab->apiUpdateGroup(0, $group)) && p() && e('0'); //使用错误gitlabID创建群组 +$invalidGroup = new stdclass(); +$invalidGroup->id = $groupID; +$invalidGroup->description = 'apiUpdatedGroup'; -$group->id = $groupID; -r($gitlab->apiUpdateGroup($gitlabID, $group)) && p('description') && e('apiUpdatedGroup'); //通过gitlabID,用户对象正确更新用户名字 \ No newline at end of file +$validGroup = new stdclass(); +$validGroup->id = $groupID; +$validGroup->name = 'Updated Group Name'; +$validGroup->description = 'Updated description'; + +$nonExistentGroup = new stdclass(); +$nonExistentGroup->id = 888888; +$nonExistentGroup->description = 'Non-existent group'; + +r($gitlab->apiUpdateGroup($gitlabID, $emptyGroup)) && p() && e('0'); +r($gitlab->apiUpdateGroup(0, $invalidGroup)) && p() && e('0'); +r($gitlab->apiUpdateGroup($gitlabID, $invalidGroup)) && p('description') && e('apiUpdatedGroup'); +r($gitlab->apiUpdateGroup($gitlabID, $validGroup)) && p('name') && e('Updated Group Name'); +r($gitlab->apiUpdateGroup($gitlabID, $nonExistentGroup)) && p() && e('~~'); \ No newline at end of file