* Add repo unit test.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getCommitsByRevisions();
|
||||
timeout=0
|
||||
cid=8
|
||||
|
||||
- 获取版本库1提交信息属性1 @1
|
||||
- 获取版本库3提交信息属性3 @3
|
||||
|
||||
*/
|
||||
|
||||
zdTable('repo')->config('repo')->gen(4);
|
||||
zdTable('repohistory')->config('repohistory')->gen(3);
|
||||
|
||||
$repo = $tester->loadModel('repo');
|
||||
|
||||
$revisions1 = array('c808480afe22d3a55d94e91c59a8f3170212ade0');
|
||||
$revisions2 = array('d30919bdb9b4cf8e2698f4a6a30e41910427c01c', '0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb');
|
||||
|
||||
r($repo->getCommitsByRevisions($revisions1)) && p('1') && e('1'); //获取版本库1提交信息
|
||||
r($repo->getCommitsByRevisions($revisions2)) && p('3') && e('3'); //获取版本库3提交信息
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getExecutionPairs();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab类型版本库1的分支
|
||||
- 属性master @master
|
||||
- 属性branch1 @branch1
|
||||
- 获取gitlab类型版本库1的分支加label
|
||||
- 属性master @Branch::master
|
||||
- 属性branch1 @Branch::branch1
|
||||
|
||||
*/
|
||||
|
||||
$execution = zdTable('project');
|
||||
$execution->id->range('1-10');
|
||||
$execution->name->range('项目集1,项目1,项目2,项目3,迭代1,迭代2,阶段1,阶段2,看板1,看板2');
|
||||
$execution->type->range('program,project,sprint{2},stage{2},kanban{2}');
|
||||
$execution->model->range('[],scrum,waterfall,kanban,[]{6}');
|
||||
$execution->parent->range('0,1{3},2{2},3{2},4{2}');
|
||||
$execution->project->range('0{4},2{2},3{2},4{2}');
|
||||
$execution->status->range('doing');
|
||||
$execution->vision->range('rnd');
|
||||
$execution->openedBy->range('admin,user1');
|
||||
$execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD');
|
||||
$execution->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD');
|
||||
$execution->gen(10);
|
||||
|
||||
$product = zdTable('product');
|
||||
$product->id->range('1-3');
|
||||
$product->name->range('1-3')->prefix('产品');
|
||||
$product->code->range('1-3')->prefix('product');
|
||||
$product->type->range('normal');
|
||||
$product->status->range('normal');
|
||||
$product->PO->range('admin');
|
||||
$product->QD->range('user1');
|
||||
$product->RD->range('user2');
|
||||
$product->gen(3);
|
||||
|
||||
$projectProduct = zdTable('projectproduct');
|
||||
$projectProduct->project->range('2{3}, 3{3}, 4{3}, 5, 6, 7, 8, 9, 10');
|
||||
$projectProduct->product->range('1-3');
|
||||
$projectProduct->branch->range('0');
|
||||
$projectProduct->gen(9);
|
||||
|
||||
$productID = 3;
|
||||
$branch = 1;
|
||||
|
||||
$repo = $tester->loadModel('repo');
|
||||
|
||||
r($repo->getExecutionPairs($productID)) && p('4,3') && e('项目3,项目2'); // 获取执行键值对
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getFileCommits();
|
||||
timeout=0
|
||||
cid=8
|
||||
|
||||
- 获取代码文件得提交信息
|
||||
- 第0条的revision属性 @c808480afe22d3a55d94e91c59a8f3170212ade0
|
||||
- 第0条的date属性 @2023-12-13 19:00:25
|
||||
- 获取操作为删除文件得提交信息 @0
|
||||
- 获取svn代码库得提交信息
|
||||
- 第0条的revision属性 @1
|
||||
- 第0条的comment属性 @+ Add file.
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(4);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
zdTable('repohistory')->config('repohistory')->gen(4);
|
||||
$repoBranch = zdTable('repobranch');
|
||||
$repoBranch->branch->range('branch3');
|
||||
$repoBranch->gen(1);
|
||||
zdTable('repofiles')->gen(10);
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
$gitlabID = 1;
|
||||
$giteaID = 3;
|
||||
$branch = 'branch3';
|
||||
$parent = '/trunk/zentaoext/zentaopro/cmmi/db';
|
||||
|
||||
r($repo->getFileCommitsTest($gitlabID, $branch)) && p('0:revision,date') && e('c808480afe22d3a55d94e91c59a8f3170212ade0,2023-12-13 19:00:25'); //获取代码文件得提交信息
|
||||
r($repo->getFileCommitsTest($giteaID, '')) && p() && e('0'); //获取操作为删除文件得提交信息
|
||||
r($repo->getFileCommitsTest(4, '', $parent)) && p('0:revision,comment') && e('1,+ Add file.'); //获取svn代码库得提交信息
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::isClickable();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 计算exec为disabled是否能进行执行任务操作 @0
|
||||
- 计算exec为空是否能进行执行任务操作 @1
|
||||
- 计算report为disabled是否能进行执行任务操作 @0
|
||||
- 计算report为空是否能进行执行任务操作 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('repo')->config('repo')->gen(4);
|
||||
zdTable('repohistory')->config('repohistory')->gen(3);
|
||||
|
||||
$repoModel = $tester->loadModel('repo');
|
||||
|
||||
$repo1 = new stdclass();
|
||||
$repo1->exec = 'disabled';
|
||||
|
||||
$repo2 = new stdclass();
|
||||
$repo2->exec = '';
|
||||
|
||||
$repo3 = new stdclass();
|
||||
$repo3->report = 'disabled';
|
||||
|
||||
$repo4 = new stdclass();
|
||||
$repo4->report = '';
|
||||
|
||||
r($repoModel->isClickable($repo1, 'execJob')) && p() && e('0'); //计算exec为disabled是否能进行执行任务操作
|
||||
r($repoModel->isClickable($repo2, 'execJob')) && p() && e('1'); //计算exec为空是否能进行执行任务操作
|
||||
r($repoModel->isClickable($repo3, 'reportView')) && p() && e('0'); //计算report为disabled是否能进行执行任务操作
|
||||
r($repoModel->isClickable($repo4, 'reportView')) && p() && e('1'); //计算report为空是否能进行执行任务操作
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->saveTaskRelation();
|
||||
timeout=0
|
||||
cid=8
|
||||
|
||||
- 保存任务和分支的关联关系
|
||||
- 属性AID @2
|
||||
- 属性BID @1
|
||||
- 属性extra @master
|
||||
|
||||
*/
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
$repoID = 1;
|
||||
$taskID = 2;
|
||||
$branch = 'master';
|
||||
|
||||
r($repo->saveTaskRelationTest($repoID, $taskID, $branch)) && p('AID,BID,extra') && e('2,1,master'); //保存任务和分支的关联关系
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->updateCommit();
|
||||
timeout=0
|
||||
cid=8
|
||||
|
||||
- 保存任务和分支的关联关系
|
||||
- 属性AID @2
|
||||
- 属性BID @1
|
||||
- 属性extra @master
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(4);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
zdTable('repohistory')->config('repohistory')->gen(4);
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
$gitlabID = 1;
|
||||
$svnID = 4;
|
||||
|
||||
r($repo->updateCommitTest($gitlabID)) && p() && e('1'); //更新gitlab代码库
|
||||
r($repo->updateCommitTest($svnID)) && p('5:id,comment') && e('5,+ Add secondary file.'); //更新svn代码库
|
||||
@@ -730,4 +730,50 @@ class repoTest
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function saveTaskRelationTest(int $repoID, int $taskID, string $branch)
|
||||
{
|
||||
$this->objectModel->saveTaskRelation($repoID, $taskID, $branch);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_RELATION)
|
||||
->where('AType')->eq('task')
|
||||
->andWhere('AID')->eq($taskID)
|
||||
->andWhere('BID')->eq($repoID)
|
||||
->andWhere('relation')->eq('linkrepobranch')
|
||||
->andWhere('BType')->eq('repobranch')
|
||||
->fetch();
|
||||
}
|
||||
|
||||
public function updateCommitTest(int $repoID, int $objectID = 0, string $branchID = '')
|
||||
{
|
||||
$result = $this->objectModel->updateCommit($repoID, $objectID, $branchID);
|
||||
|
||||
$repo = $this->objectModel->getByID($repoID);
|
||||
if($repo->SCM == 'Gitlab') return $result;
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->fetchAll('id');
|
||||
}
|
||||
|
||||
public function checkDeletedBranchesTest(int $repoID, array $latestBranches)
|
||||
{
|
||||
$result = $this->objectModel->checkDeletedBranches($repoID, $latestBranches);
|
||||
|
||||
$repoHistoryCount = $this->objectModel->dao->select('*')->from(TABLE_REPOHISTORY)->count();
|
||||
$repoBranchCount = $this->objectModel->dao->select('*')->from(TABLE_REPOBRANCH)->count();
|
||||
$repoFilesCount = $this->objectModel->dao->select('*')->from(TABLE_REPOFILES)->count();
|
||||
|
||||
return array('repoHistoryCount' => $repoHistoryCount, 'repoBranchCount' => $repoBranchCount, 'repoFilesCount' => $repoFilesCount);
|
||||
}
|
||||
|
||||
public function getFileCommitsTest(int $repoID, string $branch, string $parent = '')
|
||||
{
|
||||
$repo = $this->objectModel->getByID($repoID);
|
||||
$result = $this->objectModel->getFileCommits($repo, $branch, $parent);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getFileTreeTest(int $repoID, string $branch = '', array $diffs = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,38 +12,38 @@ fields:
|
||||
format: ""
|
||||
- field: repo
|
||||
note: "代码库ID"
|
||||
range: "1,3{2}"
|
||||
range: "1,3{2},4"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: revision
|
||||
note: "查看版本"
|
||||
range: "c808480afe22d3a55d94e91c59a8f3170212ade0,d30919bdb9b4cf8e2698f4a6a30e41910427c01c,0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb"
|
||||
range: "c808480afe22d3a55d94e91c59a8f3170212ade0,d30919bdb9b4cf8e2698f4a6a30e41910427c01c,0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb,1"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: commit
|
||||
note: "提交"
|
||||
range: "1,2,1"
|
||||
range: "1,2,1,1"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: comment
|
||||
note: "注释"
|
||||
range: "[代码注释],[更新 LICENSE],[Initial commit]"
|
||||
range: "[代码注释],[更新 LICENSE],[Initial commit],[+ Add file.]"
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: committer
|
||||
note: "作者"
|
||||
range: 1-10000
|
||||
prefix: "提交者"
|
||||
range: "admin,gitea{2},admin"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: time
|
||||
note: "提交时间"
|
||||
range: "[2023-12-13 19:00:25],[2023-12-18 19:00:25],[2023-12-13 13:04:27]"
|
||||
range: "[2023-12-13 19:00:25],[2023-12-18 19:00:25],[2023-12-13 13:04:27],[2023-12-14 09:04:27]"
|
||||
|
||||
Reference in New Issue
Block a user