diff --git a/test/class/pipeline.class.php b/test/class/pipeline.class.php new file mode 100644 index 0000000000..55177da77a --- /dev/null +++ b/test/class/pipeline.class.php @@ -0,0 +1,124 @@ +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; + } +} diff --git a/test/model/pipeline/create.php b/test/model/pipeline/create.php new file mode 100644 index 0000000000..110eefd069 --- /dev/null +++ b/test/model/pipeline/create.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +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'); diff --git a/test/model/pipeline/delete.php b/test/model/pipeline/delete.php new file mode 100644 index 0000000000..39f07ef34d --- /dev/null +++ b/test/model/pipeline/delete.php @@ -0,0 +1,19 @@ +#!/usr/bin/env php +delete(); +cid=1 +pid=1 + +*/ + +$pipeline = new pipelineTest(); + +r($pipeline->deleteTest(1)) && p('deleted') && e('1'); //测试删除之后deleted值是否为1 + +system('./ztest init'); diff --git a/test/model/pipeline/getbyid.php b/test/model/pipeline/getbyid.php new file mode 100644 index 0000000000..06d1cc2de7 --- /dev/null +++ b/test/model/pipeline/getbyid.php @@ -0,0 +1,20 @@ +#!/usr/bin/env php +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为不存在的数据 diff --git a/test/model/pipeline/getlist.php b/test/model/pipeline/getlist.php new file mode 100644 index 0000000000..d2c06bc3a7 --- /dev/null +++ b/test/model/pipeline/getlist.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +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的数据量 diff --git a/test/model/pipeline/getpairs.php b/test/model/pipeline/getpairs.php new file mode 100644 index 0000000000..8b67e1040a --- /dev/null +++ b/test/model/pipeline/getpairs.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +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 diff --git a/test/model/pipeline/update.php b/test/model/pipeline/update.php new file mode 100644 index 0000000000..5524297701 --- /dev/null +++ b/test/model/pipeline/update.php @@ -0,0 +1,34 @@ +#!/usr/bin/env php +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'); diff --git a/test/ztest b/test/ztest index 61374a132c..d94f20d70c 100755 --- a/test/ztest +++ b/test/ztest @@ -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]);