From c854ab0e331908a4461a09de8fb6d254aec11d3c Mon Sep 17 00:00:00 2001 From: zenggang Date: Wed, 22 Dec 2021 01:01:17 +0000 Subject: [PATCH 1/3] * Add apigettags method unit --- test/model/gitlab/apigettags.php | 57 ++++++++++++++++++++++++++++++++ test/model/mr/create.php | 19 ++++++----- 2 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 test/model/gitlab/apigettags.php diff --git a/test/model/gitlab/apigettags.php b/test/model/gitlab/apigettags.php new file mode 100644 index 0000000000..d268a93072 --- /dev/null +++ b/test/model/gitlab/apigettags.php @@ -0,0 +1,57 @@ +#!/usr/bin/env php +> 2021/12/20 +通过gitlabID,projectID,获取GitLab标签数量 >> 1 +当前项目没有标签时,获取GitLab标签列表 >> 0 +当gitlabID存在,projectID不存在时,获取GitLab标签列表 >> 404 Project Not Found +当gitlabID,projectID都为0时,获取GitLab标签列表 >> return empty +通过gitlabID,projectID,按标签名升序获取GitLab标签列表 >> with_cicredentials +通过gitlabID,projectID,搜索字符'zentaopms_15.2_20210720'获取GitLab标签列表 >> zentaopms_15.2_20210720 +通过gitlabID,projectID,每页20条记录,分页获取第二页GitLab标签列表 >> zentaopms_2.0_stable_20110503 + +*/ + +$gitlab = $tester->loadModel('gitlab'); + +$gitlabID = 1; +$projectID = 1552; +$result = $gitlab->apiGetTags($gitlabID, $projectID); +r($result) && p('0:name') && e('2021/12/20'); //通过gitlabID,projectID,获取GitLab标签列表 +r(count($result)) && p() && e(1); //通过gitlabID,projectID,获取GitLab标签数量 + +$gitlabID = 1; +$projectID = 1570; +r(count($gitlab->apiGetTags($gitlabID, $projectID))) && p() && e(0); //当前项目没有标签时,获取GitLab标签列表 + +$gitlabID = 1; +$projectID = 0; +r($gitlab->apiGetTags($gitlabID, $projectID)) && p('message') && e('404 Project Not Found'); //通过gitlabID,projectID,获取GitLab标签列表 + +$gitlabID = 0; +$projectID = 0; +$result = $gitlab->apiGetTags($gitlabID, $projectID); +if(empty($result)) $result = 'return empty'; +r($result) && p() && e('return empty'); //当gitlabID,projectID都为0时,获取GitLab标签列表 + +$gitlabID = 1; +$projectID = 964; +$orderBy = 'name_asc'; +$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy); +r($result) && p('0:name') && e('with_cicredentials'); //通过gitlabID,projectID,按标签名升序获取GitLab标签列表 + +$keyword = 'zentaopms_15.2_20210720'; +$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy, $keyword); +r($result) && p('0:name') && e('zentaopms_15.2_20210720'); //通过gitlabID,projectID,搜索字符'zentaopms_15.2_20210720'获取GitLab标签列表 + +$tester->app->loadClass('pager', $static = true); +$pager = new pager(0, 20, 2); +$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy, '', $pager); +r($result) && p('0:name') && e('zentaopms_2.0_stable_20110503'); //通过gitlabID,projectID,每页20条记录,分页获取第二页GitLab标签列表 diff --git a/test/model/mr/create.php b/test/model/mr/create.php index a41bcb7bea..bf8f987a6c 100644 --- a/test/model/mr/create.php +++ b/test/model/mr/create.php @@ -23,15 +23,16 @@ $_POST['repoID'] = 0; $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; -$_POST['assignee'] = ''; +$_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; +$_POST['assignee'] = ''; +$_POST['removeSourceBranch'] = '1'; $result = $mrModel->create(); if($result['result'] == 'success') $result = 'success'; $result = preg_match('/通过API创建合并请求失败,失败原因:存在另外一个同样的合并请求在源项目分支中: !([0-9]+)/', $result['message'], $matches); //检查错误原因是否是已存在一样的mr请求 From ca1f1e645b607ba4c0516ff7e68d3d9f8963907a Mon Sep 17 00:00:00 2001 From: zenggang Date: Wed, 22 Dec 2021 07:49:49 +0000 Subject: [PATCH 2/3] * Add mr update unit --- test/model/mr/update.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/model/mr/update.php diff --git a/test/model/mr/update.php b/test/model/mr/update.php new file mode 100644 index 0000000000..e36c15bf41 --- /dev/null +++ b/test/model/mr/update.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +> success +使用title为空的数据mr请求 >> 『名称』不能为空。 + +*/ + +$mrModel = $tester->loadModel('mr'); +$MRID = 1; + +$_POST = array(); +$_POST['targetBranch'] = 'master'; +$_POST['title'] = 'Test MR'; +$_POST['description'] = date("Y-m-d H:i:s"); +$_POST['repoID'] = 1; +$_POST['assignee'] = ''; +$_POST['removeSourceBranch'] = '0'; +$result = $mrModel->update($MRID); +if($result['result'] == 'success') $result = 'success'; +r($result) && p() && e('success'); //POST数据正确修改MR描述 + +$_POST['title'] = ''; +$result = $mrModel->update($MRID); +r($result) && p('message[title]:0') && e('『名称』不能为空。'); //使用title为空的数据mr请求 From b164538b75823645aa1c6617f30711d3ebf7c1f8 Mon Sep 17 00:00:00 2001 From: zenggang Date: Wed, 22 Dec 2021 08:11:38 +0000 Subject: [PATCH 3/3] * Adjust code --- test/model/gitlab/apigettags.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/model/gitlab/apigettags.php b/test/model/gitlab/apigettags.php index d268a93072..a00b42f3a1 100644 --- a/test/model/gitlab/apigettags.php +++ b/test/model/gitlab/apigettags.php @@ -48,10 +48,10 @@ $result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy); r($result) && p('0:name') && e('with_cicredentials'); //通过gitlabID,projectID,按标签名升序获取GitLab标签列表 $keyword = 'zentaopms_15.2_20210720'; -$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy, $keyword); +$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy, $keyword); r($result) && p('0:name') && e('zentaopms_15.2_20210720'); //通过gitlabID,projectID,搜索字符'zentaopms_15.2_20210720'获取GitLab标签列表 $tester->app->loadClass('pager', $static = true); -$pager = new pager(0, 20, 2); -$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy, '', $pager); +$pager = new pager(0, 20, 2); +$result = $gitlab->apiGetTags($gitlabID, $projectID, $orderBy, '', $pager); r($result) && p('0:name') && e('zentaopms_2.0_stable_20110503'); //通过gitlabID,projectID,每页20条记录,分页获取第二页GitLab标签列表