* Finish pipeline test.
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
class pipelineTest
|
||||
{
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
global $tester;
|
||||
|
||||
|
||||
$this->objectModel = $tester->loadModel('pipeline');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pipeline by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByIDTest($id)
|
||||
{
|
||||
$objects = $this->objectModel->getByID($id);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pipeline list.
|
||||
*
|
||||
* @param string $type jenkins|gitlab
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getListTest($type = 'jenkins', $orderBy = 'id_desc', $pager = null)
|
||||
{
|
||||
$objects = $this->objectModel->getList($type, $orderBy, $pager);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pipeline pairs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPairs($data)
|
||||
{
|
||||
$objects = $this->objectModel->getPairs($data['type']);
|
||||
|
||||
if(empty($objects)) return '没有获取到数据';
|
||||
if(isset($data['id'])) return $objects[$data['id']];
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pipeline.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function createTest($type, $param)
|
||||
{
|
||||
foreach($param as $k => $v) $_POST[$k] = $v;
|
||||
$objects = $this->objectModel->create($type);
|
||||
unset($_POST);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$objects = $this->objectModel->getById($objects);
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a pipeline.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function updateTest($id)
|
||||
{
|
||||
$objects = $this->objectModel->update($id);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$objects = $this->objectModel->getByID($id);
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete one record.
|
||||
*
|
||||
* @param string $id the id to be deleted
|
||||
* @param string $object the action object
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function deleteTest($id, $object = 'gitlab')
|
||||
{
|
||||
$objects = $this->objectModel->delete($id, $object = 'gitlab');
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$objects = $this->objectModel->getById($id);
|
||||
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/pipeline.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 pipelineModel->create();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$pipeline = new pipelineTest();
|
||||
|
||||
$data = new stdClass();
|
||||
$data->name = 'Jenkins';
|
||||
$data->url = 'http://www.zentaopms.com/';
|
||||
$data->account = 'JenkinsAccount';
|
||||
$data->token = 'Jenkins';
|
||||
$data->password = 'Jenkins';
|
||||
|
||||
$result1 = $pipeline->createTest('Jenkins', $data); //获取添加的name
|
||||
$result2 = $pipeline->createTest('Jenkins', $data); //获取添加的account
|
||||
|
||||
$data->url = 'error url';
|
||||
$result3 = $pipeline->createTest('Jenkins', $data); //添加错误的url信息
|
||||
|
||||
$data->url = 'http://www.zentaopms.com/';
|
||||
$data->name = '';
|
||||
$result4 = $pipeline->createTest('Jenkins', $data); //添加名称为空时
|
||||
|
||||
r($result1) && p('type') && e('Jenkins'); //获取添加的type
|
||||
r($result2) && p('account') && e('JenkinsAccount'); //获取添加的account
|
||||
r($result3) && p('url:0') && e('『服务地址』应当为合法的URL。'); //添加错误的url信息
|
||||
r($result4) && p('name:0') && e('『名称』不能为空'); //添加名称为空时
|
||||
|
||||
system('./ztest init');
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/pipeline.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 pipelineModel->delete();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$pipeline = new pipelineTest();
|
||||
|
||||
r($pipeline->deleteTest(1)) && p('deleted') && e('1'); //测试删除之后deleted值是否为1
|
||||
|
||||
system('./ztest init');
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/pipeline.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 pipelineModel->getByID();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$IDList = array('1','0');
|
||||
|
||||
$pipeline = new pipelineTest();
|
||||
|
||||
r($pipeline->getByIDTest($IDList[0])) && p('name') && e('gitlab服务器'); //获取id为1的name字段值
|
||||
r($pipeline->getByIDTest($IDList[1])) && p() && e(); //获取id为不存在的数据
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/pipeline.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 pipelineModel->getList();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$pipeline = new pipelineTest();
|
||||
$tester->app->loadClass('pager', $static = true);
|
||||
|
||||
$pager = new pager(0, 10, 1);
|
||||
|
||||
$gitlabList = $pipeline->getListTest('gitlab', 'id_desc', $pager);
|
||||
$sonarqubeList = $pipeline->getListTest('sonarqube ', 'id_desc', $pager);
|
||||
|
||||
r($gitlabList) && p('1:name') && e('gitlab服务器'); //获取第一页第一条数据的name
|
||||
r(count($gitlabList)) && p() && e('1'); //统计所有type为gitlab的数量
|
||||
r(count($sonarqubeList)) && p() && e('1'); //统计所有type为sonarqube的数据量
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/pipeline.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 pipelineModel->getPairs();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$pipeline = new pipelineTest();
|
||||
|
||||
$data[0] = array('type' => 'gitlab', 'id' => 1);
|
||||
$data[1] = array('type' => 'sonarqube', 'id' => 2);
|
||||
$data[2] = array('type' => 'testType');
|
||||
|
||||
r($pipeline->getPairs($data[0])) && p() && e('gitlab服务器'); //id为1且type为gitlab的pipeline名称
|
||||
r($pipeline->getPairs($data[1])) && p() && e('sonarqube服务器'); //id为2且type为sonarqube的pipeline名称
|
||||
r($pipeline->getPairs($data[2])) && p() && e('没有获取到数据'); //获取不存在的type
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/pipeline.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 pipelineModel->update();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$pipeline = new pipelineTest();
|
||||
|
||||
$_POST['name'] = '测试修改gitlab服务器名称';
|
||||
$_POST['url'] = 'http://www.zentaopms.com/upgrade.php';
|
||||
$result1 = $pipeline->updateTest(1);
|
||||
|
||||
$_POST['name'] = '';
|
||||
$result2 = $pipeline->updateTest(1);
|
||||
|
||||
$_POST['name'] = '测试修改gitlab服务器名称';
|
||||
$_POST['url'] = '';
|
||||
$result3 = $pipeline->updateTest(1);
|
||||
|
||||
unset($_POST);
|
||||
|
||||
r($result1) && p('name') && e('测试修改gitlab服务器名称'); //获取修改后的name值
|
||||
r($result2) && p('name:0') && e('『名称』不能为空。'); //当名称为空时
|
||||
r($result3) && p('url:0') && e('『服务地址』不能为空。'); //url为空时
|
||||
|
||||
system('./ztest init');
|
||||
@@ -85,6 +85,9 @@ switch($argv[1])
|
||||
case 'project':
|
||||
ztfRun('model/project');
|
||||
break;
|
||||
case 'pipeline':
|
||||
ztfRun('model/pipeline');
|
||||
break;
|
||||
case 'report':
|
||||
ztfRun('model/report');
|
||||
break;
|
||||
@@ -113,6 +116,7 @@ switch($argv[1])
|
||||
ztfRun('model/user');
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
ztfExtract($argv[1]);
|
||||
system("php " . $argv[1]);
|
||||
|
||||
Reference in New Issue
Block a user