* Add gitlab test case.
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
class gitlabTest
|
||||
{
|
||||
public $tester;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $tester;
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
range: 1
|
||||
- field: gitlabID
|
||||
- field: hostID
|
||||
range: 1
|
||||
- field: sourceProject
|
||||
range: 42
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->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");
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->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");
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->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");
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->gitPairs();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
获取GitLab >> 3
|
||||
|
||||
*/
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
r($gitlab->getPairs()) && p() && e('1'); // 获取GitLab
|
||||
|
||||
system("./ztest init");
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->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");
|
||||
Reference in New Issue
Block a user