From c82550c55c6357dcffe54d6ad87f71f961867aed Mon Sep 17 00:00:00 2001 From: wangyidong Date: Sat, 7 May 2022 14:57:44 +0800 Subject: [PATCH] * Finish jenkins test. --- test/class/git.class.php | 24 ++------ test/class/jenkins.class.php | 102 ++++++++++++++++++++++++++++++++ test/model/git/getrepologs.php | 3 - test/model/git/getrepos.php | 5 +- test/model/git/updatecommit.php | 3 - test/model/jenkins/create.php | 37 ++++++++++++ test/model/jenkins/getbyid.php | 30 ++++++++++ test/model/jenkins/getlist.php | 22 +++++++ test/model/jenkins/getpairs.php | 21 +++++++ test/model/jenkins/gettasks.php | 30 ++++++++++ test/model/jenkins/update.php | 39 ++++++++++++ test/ztest | 3 + 12 files changed, 291 insertions(+), 28 deletions(-) create mode 100644 test/class/jenkins.class.php create mode 100644 test/model/jenkins/create.php create mode 100755 test/model/jenkins/getbyid.php create mode 100755 test/model/jenkins/getlist.php create mode 100755 test/model/jenkins/getpairs.php create mode 100755 test/model/jenkins/gettasks.php create mode 100644 test/model/jenkins/update.php diff --git a/test/class/git.class.php b/test/class/git.class.php index 6478e17bb5..d667572f9c 100644 --- a/test/class/git.class.php +++ b/test/class/git.class.php @@ -10,17 +10,6 @@ class gitTest $this->gitModel = $this->tester->loadModel('git'); } - /** - * Run - * - * @access public - * @return void - */ - public function run() - { - return $this->gitModel->run(); - } - /** * Update commit. * @@ -28,7 +17,7 @@ class gitTest * @param array $commentGroup * @param bool $printLog * @access public - * @return string + * @return bool */ public function updateCommit($repo) { @@ -44,7 +33,7 @@ class gitTest * Set the repos. * * @access public - * @return mixed + * @return object */ public function setRepos() { @@ -57,7 +46,7 @@ class gitTest * Get repos. * * @access public - * @return array + * @return string */ public function getRepos() { @@ -70,7 +59,7 @@ class gitTest * * @param object $repo * @access public - * @return bool + * @return object */ public function setRepo($repo) { @@ -91,7 +80,7 @@ class gitTest * * @param object $repo * @access public - * @return mixed + * @return int */ public function getRepoTags($repo) { @@ -104,9 +93,8 @@ class gitTest * Get repo logs. * * @param object $repo - * @param int $fromRevision * @access public - * @return array + * @return int */ public function getRepoLogs($repo) { diff --git a/test/class/jenkins.class.php b/test/class/jenkins.class.php new file mode 100644 index 0000000000..7d75f0c5f1 --- /dev/null +++ b/test/class/jenkins.class.php @@ -0,0 +1,102 @@ +tester = $tester; + $this->jenkins = $this->tester->loadModel('jenkins'); + } + + /** + * Get by id. + * + * @param int $id + * @access public + * @return object + */ + public function getByID($id) + { + $jenkins = $this->jenkins->getByID($id); + if(empty($jenkins)) return 0; + return $jenkins; + } + + /** + * Get jenkins list. + * + * @param string $orderBy + * @access public + * @return object + */ + public function getList($orderBy = 'id_desc') + { + $jenkins = $this->jenkins->getList($orderBy); + if(empty($jenkins)) return 0; + return array_shift($jenkins); + } + + /** + * Get jenkins pairs + * + * @return string + */ + public function getPairs() + { + $pairs = $this->jenkins->getPairs(); + return key($pairs); + } + + /** + * Get jenkins tasks. + * + * @param int $id + * @access public + * @return array + */ + public function getTasks($id) + { + $tasks = $this->jenkins->getTasks($id); + if(empty($tasks)) return 0; + return $tasks; + } + + /** + * Create a jenkins. + * + * @access public + * @return object|string + */ + public function create() + { + $jenkinsID = $this->jenkins->create(); + if(dao::isError()) + { + $errors = dao::getError(); + return key($errors); + } + + return $this->jenkins->getById($jenkinsID); + } + + /** + * Update a jenkins. + * + * @param int $id + * @access public + * @return object|string + */ + public function update($id) + { + $this->jenkins->update($id); + if(dao::isError()) + { + $errors = dao::getError(); + return key($errors); + } + + return $this->jenkins->getById($id); + } +} diff --git a/test/model/git/getrepologs.php b/test/model/git/getrepologs.php index b2e1dac8c9..2cd796f534 100755 --- a/test/model/git/getrepologs.php +++ b/test/model/git/getrepologs.php @@ -18,9 +18,6 @@ pid=1 $git = new gitTest(); -/* Fix error Gitlab url. */ -$tester->dao->update(TABLE_PIPELINE)->set('url')->eq('http://10.0.1.161:51080')->where('id')->eq(1)->exec(); - $repo = $tester->dao->select('*')->from(TABLE_REPO)->limit(1)->fetch(); if(strtolower($repo->SCM) == 'gitlab') $repo = $tester->loadModel('repo')->processGitlab($repo); r($git->getRepoLogs($repo)) && p() && e(1); // 获取版本库的tags diff --git a/test/model/git/getrepos.php b/test/model/git/getrepos.php index 0d7260bc9f..dc568ac8d1 100755 --- a/test/model/git/getrepos.php +++ b/test/model/git/getrepos.php @@ -16,10 +16,7 @@ pid=1 $git = new gitTest(); -/* Fix error Gitlab url. */ -$tester->dao->update(TABLE_PIPELINE)->set('url')->eq('http://10.0.1.161:51080')->where('id')->eq(1)->exec(); - $tester->dao->update(TABLE_REPO)->set('synced')->eq(1)->where('id')->eq(1)->exec(); -r($git->getRepos()) && p() && e('http://192.168.1.161:51080/api/v4/projects/42/repository/'); // 获取版本库 +r($git->getRepos()) && p() && e('http://10.0.1.161:51080/api/v4/projects/42/repository/'); // 获取版本库 system("./ztest init"); diff --git a/test/model/git/updatecommit.php b/test/model/git/updatecommit.php index 6e75cb6323..213b8fb322 100755 --- a/test/model/git/updatecommit.php +++ b/test/model/git/updatecommit.php @@ -17,9 +17,6 @@ pid=1 $git = new gitTest(); -/* Fix error Gitlab url. */ -$tester->dao->update(TABLE_PIPELINE)->set('url')->eq('http://10.0.1.161:51080')->where('id')->eq(1)->exec(); - $repo = $tester->dao->select('*')->from(TABLE_REPO)->limit(1)->fetch(); if(strtolower($repo->SCM) == 'gitlab') $repo = $tester->loadModel('repo')->processGitlab($repo); r($git->updateCommit($repo)) && p() && e(1); // 测试正常的版本库 diff --git a/test/model/jenkins/create.php b/test/model/jenkins/create.php new file mode 100644 index 0000000000..627d27b13c --- /dev/null +++ b/test/model/jenkins/create.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +create(); +cid=1 +pid=1 + +Jenkins名称为空 >> name +服务器地址为空 >> url +正确Jenkins数据 >> Jenkins,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d + +*/ + +$jenkins = new jenkinsTest(); + +$_POST = array(); +$_POST['name'] = ''; +$_POST['url'] = 'http://10.0.1.161:58080'; +$_POST['account'] = 'admin'; +$_POST['token'] = '1196c85ba525a268570df9da627e3a7b2d'; +$_POST['password'] = ''; + +r($jenkins->create()) && p() && e('name'); // Jenkins名称为空 + +$_POST['name'] = 'Jenkins'; +$_POST['url'] = ''; +r($jenkins->create()) && p() && e('url'); // 服务器地址为空 + +$_POST['url'] = 'http://10.0.1.161:58080'; +r($jenkins->create()) && p('name,url,token') && e('Jenkins,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d'); // 正确Jenkins数据 + +system("./ztest init"); diff --git a/test/model/jenkins/getbyid.php b/test/model/jenkins/getbyid.php new file mode 100755 index 0000000000..f04d0bcdaf --- /dev/null +++ b/test/model/jenkins/getbyid.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +gitById(); +cid=1 +pid=1 + +使用存在的ID >> 3 +使用空的ID >> 0 +使用不存在的ID >> 0 + +*/ + +$jenkins = new jenkinsTest(); + +$jenkinsID = 3; +r($jenkins->getById($jenkinsID)) && p('id') && e('3'); // 使用存在的ID + +$jenkinsID = 0; +r($jenkins->getById($jenkinsID)) && p() && e(0); // 使用空的ID + +$jenkinsID = 111; +r($jenkins->getById($jenkinsID)) && p() && e(0); // 使用不存在的ID + +system("./ztest init"); diff --git a/test/model/jenkins/getlist.php b/test/model/jenkins/getlist.php new file mode 100755 index 0000000000..e799dd54ae --- /dev/null +++ b/test/model/jenkins/getlist.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +gitList(); +cid=1 +pid=1 + +获取Jenkins列表 >> 3 + +*/ + +$jenkins = new jenkinsTest(); + +$orderBy = 'id_desc'; +r($jenkins->getList($orderBy)) && p('id') && e('3'); // 获取Jenkins列表 + +system("./ztest init"); diff --git a/test/model/jenkins/getpairs.php b/test/model/jenkins/getpairs.php new file mode 100755 index 0000000000..f6b86224d7 --- /dev/null +++ b/test/model/jenkins/getpairs.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +gitPairs(); +cid=1 +pid=1 + +获取Jenkins >> 3 + +*/ + +$jenkins = new jenkinsTest(); + +r($jenkins->getPairs()) && p() && e('3'); // 获取Jenkins + +system("./ztest init"); diff --git a/test/model/jenkins/gettasks.php b/test/model/jenkins/gettasks.php new file mode 100755 index 0000000000..d2cb8aef85 --- /dev/null +++ b/test/model/jenkins/gettasks.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +gitTasks(); +cid=1 +pid=1 + +使用存在的Jenkins >> zentao-test +使用空的Jenkins >> 0 +使用不存在的Jenkins >> 0 + +*/ + +$jenkins = new jenkinsTest(); + +$id = 3; +r($jenkins->getTasks($id)) && p('zentao-test') && e('zentao-test'); // 使用存在的Jenkins + +$id = 0; +r($jenkins->getTasks($id)) && p() && e('0'); // 使用空的Jenkins + +$id = 111; +r($jenkins->getTasks($id)) && p() && e('0'); // 使用不存在的Jenkins + +system("./ztest init"); diff --git a/test/model/jenkins/update.php b/test/model/jenkins/update.php new file mode 100644 index 0000000000..e3b39dea82 --- /dev/null +++ b/test/model/jenkins/update.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +update(); +cid=1 +pid=1 + +Jenkins名称为空 >> name +服务器地址为空 >> url +正确Jenkins数据 >> Changed Jenkins + +*/ + +$jenkins = new jenkinsTest(); + +$jenkinsID = 3; + +$_POST = array(); +$_POST['name'] = ''; +$_POST['url'] = 'http://10.0.1.161:58080'; +$_POST['account'] = 'admin'; +$_POST['token'] = '1196c85ba525a268570df9da627e3a7b2d'; +$_POST['password'] = ''; + +r($jenkins->update($jenkinsID)) && p() && e('name'); // Jenkins名称为空 + +$_POST['name'] = 'Changed Jenkins'; +$_POST['url'] = ''; +r($jenkins->update($jenkinsID)) && p() && e('url'); // 服务器地址为空 + +$_POST['url'] = 'http://10.0.1.161:58080'; +r($jenkins->update($jenkinsID)) && p('name') && e('Changed Jenkins'); // 正确Jenkins数据 + +system("./ztest init"); diff --git a/test/ztest b/test/ztest index 188e7995af..226f270c20 100755 --- a/test/ztest +++ b/test/ztest @@ -61,6 +61,9 @@ switch($argv[1]) case 'group': ztfRun('model/group'); break; + case 'jenkins': + ztfRun('model/jenkins'); + break; case 'kanban': ztfRun('model/kanban'); break;