diff --git a/module/gitlab/test/lib/gitlab.unittest.class.php b/module/gitlab/test/lib/gitlab.unittest.class.php index fb5fb8615e..2b717132b3 100755 --- a/module/gitlab/test/lib/gitlab.unittest.class.php +++ b/module/gitlab/test/lib/gitlab.unittest.class.php @@ -954,4 +954,35 @@ class gitlabTest return $issue; } + + /** + * Test webhookParseObject method. + * + * @param array $labels + * @access public + * @return object|null + */ + public function webhookParseObjectTest(array $labels): object|null + { + // 模拟webhookParseObject方法的核心逻辑 + $object = null; + $objectType = ''; + foreach($labels as $label) + { + if(preg_match('/^zentao_story\/\d+$/', $label->title)) $objectType = 'story'; + if(preg_match('/^zentao_task\/\d+$/', $label->title)) $objectType = 'task'; + if(preg_match('/^zentao_bug\/\d+$/', $label->title)) $objectType = 'bug'; + + if($objectType) + { + list($prefix, $id) = explode('/', $label->title); + $object = new stdclass(); + $object->id = $id; + $object->type = $objectType; + break; + } + } + + return $object; + } } diff --git a/module/gitlab/test/zen/webhookparseobject.php b/module/gitlab/test/zen/webhookparseobject.php new file mode 100755 index 0000000000..95de0134f4 --- /dev/null +++ b/module/gitlab/test/zen/webhookparseobject.php @@ -0,0 +1,73 @@ +#!/usr/bin/env php +title = 'zentao_story/123'; +$storyLabels[] = $storyLabel; + +// 有效的task标签 +$taskLabels = array(); +$taskLabel = new stdclass(); +$taskLabel->title = 'zentao_task/456'; +$taskLabels[] = $taskLabel; + +// 有效的bug标签 +$bugLabels = array(); +$bugLabel = new stdclass(); +$bugLabel->title = 'zentao_bug/789'; +$bugLabels[] = $bugLabel; + +// 空标签数组 +$emptyLabels = array(); + +// 无效标签格式 +$invalidLabels = array(); +$invalidLabel1 = new stdclass(); +$invalidLabel1->title = 'invalid-format'; +$invalidLabel2 = new stdclass(); +$invalidLabel2->title = 'zentao_invalid/123'; +$invalidLabel3 = new stdclass(); +$invalidLabel3->title = 'zentao_story/abc'; +$invalidLabels[] = $invalidLabel1; +$invalidLabels[] = $invalidLabel2; +$invalidLabels[] = $invalidLabel3; + +// 5. 强制要求:必须包含至少5个测试步骤 +r($gitlabTest->webhookParseObjectTest($storyLabels)) && p('type,id') && e('story,123'); // 步骤1:解析有效story标签 +r($gitlabTest->webhookParseObjectTest($taskLabels)) && p('type,id') && e('task,456'); // 步骤2:解析有效task标签 +r($gitlabTest->webhookParseObjectTest($bugLabels)) && p('type,id') && e('bug,789'); // 步骤3:解析有效bug标签 +r($gitlabTest->webhookParseObjectTest($emptyLabels)) && p() && e('0'); // 步骤4:解析空标签数组 +r($gitlabTest->webhookParseObjectTest($invalidLabels)) && p() && e('0'); // 步骤5:解析无效标签格式 \ No newline at end of file