diff --git a/test/class/gitlab.class.php b/test/class/gitlab.class.php new file mode 100644 index 0000000000..8018ca5f73 --- /dev/null +++ b/test/class/gitlab.class.php @@ -0,0 +1,88 @@ +tester = $tester; + $this->gitlab = $this->tester->loadModel('gitlab'); + } + + /** + * Get by id. + * + * @param int $id + * @access public + * @return object + */ + public function getByID($id) + { + $gitlab = $this->gitlab->getByID($id); + if(empty($gitlab)) return 0; + return $gitlab; + } + + /** + * Get gitlab list. + * + * @param string $orderBy + * @access public + * @return object + */ + public function getList($orderBy = 'id_desc') + { + $gitlab = $this->gitlab->getList($orderBy); + if(empty($gitlab)) return 0; + return array_shift($gitlab); + } + + /** + * Get gitlab pairs + * + * @return string + */ + public function getPairs() + { + $pairs = $this->gitlab->getPairs(); + return key($pairs); + } + + /** + * Create a gitlab. + * + * @access public + * @return object|string + */ + public function create() + { + $gitlabID = $this->gitlab->create(); + if(dao::isError()) + { + $errors = dao::getError(); + return key($errors); + } + + return $this->gitlab->getById($gitlabID); + } + + /** + * Update a gitlab. + * + * @param int $id + * @access public + * @return object|string + */ + public function update($id) + { + $this->gitlab->update($id); + if(dao::isError()) + { + $errors = dao::getError(); + return key($errors); + } + + return $this->gitlab->getById($id); + } +} diff --git a/test/data/mr.yaml b/test/data/mr.yaml index 8223d4cbc5..24aafc2392 100644 --- a/test/data/mr.yaml +++ b/test/data/mr.yaml @@ -4,7 +4,7 @@ version: "1.0" fields: - field: id range: 1 - - field: gitlabID + - field: hostID range: 1 - field: sourceProject range: 42 diff --git a/test/data/repo.yaml b/test/data/repo.yaml index 1ff0e40ec1..bb77aa7124 100644 --- a/test/data/repo.yaml +++ b/test/data/repo.yaml @@ -14,6 +14,10 @@ fields: range: Gitlab - field: client range: 1 + - field: serviceHost + range: 1 + - field: serviceProject + range: 42 - field: extra range: 42 - field: preMerge diff --git a/test/model/gitlab/create.php b/test/model/gitlab/create.php new file mode 100644 index 0000000000..98b43ccdfb --- /dev/null +++ b/test/model/gitlab/create.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +create(); +cid=1 +pid=1 + +GitLab名称为空 >> name +服务器地址为空 >> url +正确GitLab数据 >> GitLab,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d + +*/ + +$gitlab = new gitlabTest(); + +$_POST = array(); +$_POST['name'] = ''; +$_POST['url'] = 'http://10.0.1.161:51080'; +$_POST['token'] = 'y2UBqwPPzaLxsniy8R6A'; +$_POST['password'] = ''; + +r($gitlab->create()) && p() && e('name'); // GitLab名称为空 + +$_POST['name'] = 'GitLab'; +$_POST['url'] = ''; +r($gitlab->create()) && p() && e('url'); // 服务器地址为空 + +$_POST['url'] = 'http://10.0.1.161:51080'; +r($gitlab->create()) && p('name,url,token') && e('GitLab,http://10.0.1.161:51080,y2UBqwPPzaLxsniy8R6A'); // 正确GitLab数据 + +system("./ztest init"); diff --git a/test/model/gitlab/getbyid.php b/test/model/gitlab/getbyid.php new file mode 100755 index 0000000000..6d3333f7ae --- /dev/null +++ b/test/model/gitlab/getbyid.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +gitById(); +cid=1 +pid=1 + +使用存在的ID >> 3 +使用空的ID >> 0 +使用不存在的ID >> 0 + +*/ + +$gitlab = new gitlabTest(); + +$gitlabID = 1; +r($gitlab->getById($gitlabID)) && p('id') && e('1'); // 使用存在的ID + +$gitlabID = 0; +r($gitlab->getById($gitlabID)) && p() && e(0); // 使用空的ID + +$gitlabID = 111; +r($gitlab->getById($gitlabID)) && p() && e(0); // 使用不存在的ID + +system("./ztest init"); diff --git a/test/model/gitlab/getlist.php b/test/model/gitlab/getlist.php new file mode 100755 index 0000000000..20998159cb --- /dev/null +++ b/test/model/gitlab/getlist.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +gitList(); +cid=1 +pid=1 + +获取GiLlab列表 >> 3 + +*/ + +$gitlab = new gitlabTest(); + +$orderBy = 'id_desc'; +r($gitlab->getList($orderBy)) && p('id') && e('1'); // 获取GitLab列表 + +system("./ztest init"); diff --git a/test/model/gitlab/getpairs.php b/test/model/gitlab/getpairs.php new file mode 100755 index 0000000000..6e11e9e0e9 --- /dev/null +++ b/test/model/gitlab/getpairs.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +gitPairs(); +cid=1 +pid=1 + +获取GitLab >> 3 + +*/ + +$gitlab = new gitlabTest(); + +r($gitlab->getPairs()) && p() && e('1'); // 获取GitLab + +system("./ztest init"); diff --git a/test/model/gitlab/update.php b/test/model/gitlab/update.php new file mode 100644 index 0000000000..4006e3466d --- /dev/null +++ b/test/model/gitlab/update.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +update(); +cid=1 +pid=1 + +GitLab名称为空 >> name +服务器地址为空 >> url +正确GitLab数据 >> Changed GitLab + +*/ + +$gitlab = new gitlabTest(); + +$gitlabID = 3; + +$_POST = array(); +$_POST['name'] = ''; +$_POST['url'] = 'http://10.0.1.161:51080'; +$_POST['account'] = 'admin'; +$_POST['token'] = 'y2UBqwPPzaLxsniy8R6A'; +$_POST['password'] = ''; + +r($gitlab->update($gitlabID)) && p() && e('name'); // GitLab名称为空 + +$_POST['name'] = 'Changed GitLab'; +$_POST['url'] = ''; +r($gitlab->update($gitlabID)) && p() && e('url'); // 服务器地址为空 + +$_POST['url'] = 'http://10.0.1.161:51080'; +r($gitlab->update($gitlabID)) && p('name') && e('Changed GitLab'); // 正确GitLab数据 + +system("./ztest init");