* [misc] Enhance unit tests for repoModel::getListByCondition() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,24 @@ class repoTest
|
||||
return $this->objectModel->session->repoID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getListByCondition method.
|
||||
*
|
||||
* @param string $repoQuery
|
||||
* @param string $SCM
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getListByConditionTest(string $repoQuery = '', string $SCM = '', string $orderBy = 'id_desc', ?object $pager = null)
|
||||
{
|
||||
$result = $this->objectModel->getListByCondition($repoQuery, $SCM, $orderBy, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getCommitsByObject method.
|
||||
*
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getListByCondition();
|
||||
title=测试 repoModel::getListByCondition();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 根据query查询 @0
|
||||
- query为空时查询第1条的name属性 @testHtml
|
||||
- 排序条件查询属性id @1
|
||||
- 按分页查询属性id @3
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是'', '' @1
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是'', '' @5
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是"name='testHtml'", '' @2
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是'', 'Gitlab' @3
|
||||
- 执行$results第0条的id属性 @1
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是'', '', 'id_desc', $pager @2
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是"name like '%test%'", '' @4
|
||||
- 执行repoTest模块的getListByConditionTest方法,参数是'id = 999', '' @0
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
|
||||
|
||||
zenData('repo')->loadYaml('repo')->gen(5);
|
||||
|
||||
$repo = $tester->loadModel('repo');
|
||||
$repo->app->moduleName = 'repo';
|
||||
$repo->app->methodName = 'browse';
|
||||
$repo->app->rawModule = 'repo';
|
||||
$repo->app->rawMethod = 'browse';
|
||||
su('admin');
|
||||
|
||||
$repoQuery = "path like '%123%'";
|
||||
$orderBy = 'id_asc';
|
||||
$repoTest = new repoTest();
|
||||
|
||||
$pager = new stdclass();
|
||||
$pager->recPerPage = 2;
|
||||
$pager->pageID = 2;
|
||||
$repo->app->loadClass('pager', true);
|
||||
$pager->pageID = 1;
|
||||
$repoTest->objectModel->app->loadClass('pager', true);
|
||||
$pager = pager::init(0, $pager->recPerPage, $pager->pageID);
|
||||
|
||||
r($repo->getListByCondition($repoQuery, $SCM = 'Gitlab')) && p() && e('0'); //根据query查询
|
||||
r($repo->getListByCondition('', $SCM = 'Gitlab')) && p('1:name') && e('testHtml'); //query为空时查询
|
||||
|
||||
$result = $repo->getListByCondition('', $SCM = 'Gitlab', $orderBy);
|
||||
r(array_shift($result)) && p('id') && e(1); //排序条件查询
|
||||
|
||||
$result = $repo->getListByCondition('', $SCM = 'Gitlab,Gitea', $orderBy, $pager);
|
||||
r(array_shift($result)) && p('id') && e(3); //按分页查询
|
||||
r(is_array($repoTest->getListByConditionTest('', ''))) && p() && e('1');
|
||||
r(count($repoTest->getListByConditionTest('', ''))) && p() && e('5');
|
||||
r(count($repoTest->getListByConditionTest("name='testHtml'", ''))) && p() && e('2');
|
||||
r(count($repoTest->getListByConditionTest('', 'Gitlab'))) && p() && e('3');
|
||||
$results = $repoTest->getListByConditionTest('', '', 'id_asc');
|
||||
r(array_values($results)) && p('0:id') && e('1');
|
||||
r(count($repoTest->getListByConditionTest('', '', 'id_desc', $pager))) && p() && e('2');
|
||||
r(count($repoTest->getListByConditionTest("name like '%test%'", ''))) && p() && e('4');
|
||||
r(count($repoTest->getListByConditionTest('id = 999', ''))) && p() && e('0');
|
||||
@@ -0,0 +1,41 @@
|
||||
title: repo数据 for getListByCondition测试
|
||||
desc: 为getListByCondition方法测试提供测试数据
|
||||
author: Claude
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
range: 1-10
|
||||
- field: product
|
||||
range: 1-5
|
||||
- field: projects
|
||||
range: 11-15
|
||||
- field: name
|
||||
range: testRepo1,testRepo2,prodRepo1,prodRepo2,devRepo1,devRepo2,specialRepo,emptyRepo,gitlabRepo,giteaRepo
|
||||
- field: path
|
||||
range: "http://gitlab.test.com/test1,http://gitlab.test.com/test2,/var/repo/prod1,/var/repo/prod2,http://gitea.test.com/dev1,http://gitea.test.com/dev2,/home/special,[],,/path/gitea"
|
||||
- field: SCM
|
||||
range: Gitlab,Gitlab,Gitlab,Gitlab,Gitea,Gitea,Gitea,Git,Git,Subversion
|
||||
- field: client
|
||||
range: git,git,git,git,git,git,git,git,git,svn
|
||||
- field: serviceHost
|
||||
range: 1,1,2,2,1,1,0,0,0,0
|
||||
- field: serviceProject
|
||||
range: "test1,test2,prod1,prod2,dev1,dev2,[],[],[],[]"
|
||||
- field: commits
|
||||
range: 0,5,10,15,20,25,30,0,0,5
|
||||
- field: account
|
||||
range: "admin,admin,user,user,tester,tester,[],[],[],[]"
|
||||
- field: password
|
||||
range: "123456,123456,pass123,pass123,test123,test123,[],[],[],[]"
|
||||
- field: encrypt
|
||||
range: plain,plain,plain,plain,base64,base64,plain,plain,plain,plain
|
||||
- field: synced
|
||||
range: 1,1,1,1,1,1,0,0,1,1
|
||||
- field: extra
|
||||
range: 1,2,3,4,5,6,7,8,9,10
|
||||
- field: preMerge
|
||||
range: 0,0,1,1,0,0,0,0,0,0
|
||||
- field: job
|
||||
range: 0,0,0,0,0,0,0,0,0,1
|
||||
- field: deleted
|
||||
range: 0,0,0,0,0,0,0,0,0,1
|
||||
Reference in New Issue
Block a user