* Add repo unit test.

This commit is contained in:
zenggang
2024-01-03 08:36:25 +00:00
parent aeda204f7a
commit d80abad24d
4 changed files with 150 additions and 8 deletions
+8 -1
View File
@@ -2637,7 +2637,14 @@ class repoModel extends model
->add('execution', $bug->execution)
->get();
$changes = $this->bug->resolve($newBug);
$changes = array();
$result = $this->bug->resolve($newBug);
if($result)
{
$newBug = $this->bug->getByID($bugID);
$changes = common::createChanges($bug, $newBug);
}
foreach($changes as $change) $changes[] = $change;
if($changes)
{
+66
View File
@@ -0,0 +1,66 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/repo.class.php';
su('admin');
/**
title=测试 repoModel->saveAction2PMS();
timeout=0
cid=1
- 开始任务
- 第1条的status属性 @doing
- 第1条的consumed属性 @4
- 第1条的left属性 @3
- 完成任务
- 第2条的status属性 @done
- 第2条的consumed属性 @14
- 第2条的left属性 @0
- 工时计算
- 第8条的status属性 @doing
- 第8条的consumed属性 @11
- 第8条的left属性 @3
- 修复bug1
- 第1条的status属性 @resolved
- 第1条的resolution属性 @fixed
- 修复bug2
- 第2条的status属性 @resolved
- 第2条的resolution属性 @fixed
*/
zdTable('task')->gen(10);
$bug = zdTable('bug');
$bug->execution->range('0');
$bug->gen(10);
zdTable('repo')->config('repo')->gen(4);
$repoID = 1;
$repoRoot = '';
$scm = 'gitlab';
$log = new stdclass();
$log->revision = '61e51cadb1aa21ef3d2b51e3f193be3cc19cfef6';
$log->committer = 'root';
$log->time = '2023-12-29 10:44:36';
$log->comment = 'Start Task #1 Cost:1h Left:3h,Effort Task #8 Cost:1h Left:3h,Finish Task #2 Cost:10h';
$log->author = 'user4';
$log->msg = 'Start Task #1 Cost:1h Left:3h,Effort Task #8 Cost:1h Left:3h,Finish Task #2 Cost:10h';
$log->date = '2023-12-29 10:44:36';
$log->files = array('M' => array('/README.md'));
$log->change = array('/README.md' => array('action' => 'M', 'kind' => 'file', 'oldPath' => ''));
$repo = new repoTest();
$repo->saveAction2PMSTest($log, $repoID);
$result = $tester->loadModel('task')->getByIdList(array(1,2,8));
r($result) && p('1:status,consumed,left') && e('doing,4,3'); //开始任务
r($result) && p('2:status,consumed,left') && e('done,14,0'); //完成任务
r($result) && p('8:status,consumed,left') && e('doing,11,3'); //工时计算
$log->msg = $log->comment = 'Fix bug#1,2';
$repo->saveAction2PMSTest($log, $repoID);
$result = $tester->loadModel('bug')->getByIdList(array(1,2));
r($result) && p('1:status,resolution') && e('resolved,fixed'); //修复bug1
r($result) && p('2:status,resolution') && e('resolved,fixed'); //修复bug2
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/repo.class.php';
su('admin');
/**
title=测试 repoModel->saveRecord();
timeout=0
cid=1
- 保存一条记录
- 属性action @gitcommited
- 属性extra @61e51cadb1
- 更新已有记录属性actor @admin
- 查看历史记录属性field @git
*/
zdTable('task')->gen(10);
zdTable('repo')->config('repo')->gen(4);
$taskID = 1;
$repoRoot = '';
$scm = 'gitlab';
$log = new stdclass();
$log->revision = '61e51cadb1aa21ef3d2b51e3f193be3cc19cfef6';
$log->committer = 'root';
$log->time = '2023-12-29 10:44:36';
$log->comment = 'Start Task #64250 Cost:1h Left:3h Finish Task #64247 Cost:10h';
$log->author = '';
$log->msg = 'Start Task #64250 Cost:1h Left:3h Finish Task #64247 Cost:10h';
$log->date = '2023-12-29 10:44:36';
$log->files = array('M' => array('/README.md'));
$log->change = array('/README.md' => array('action' => 'M', 'kind' => 'file', 'oldPath' => ''));
$action = new stdclass();
$action->actor = 'user4';
$action->date = '2023-12-29 13:14:36';
$action->extra = $scm == 'svn' ? $log->revision : substr($log->revision, 0, 10);
$action->objectType = 'task';
$action->objectID = $taskID;
$action->action = 'gitcommited';
$repo = new repoTest();
r($repo->saveRecordTest($action, $log, $repoRoot, $scm)) && p('action,extra') && e('gitcommited,61e51cadb1'); //保存一条记录
$action->actor = 'admin';
r($repo->saveRecordTest($action, $log, $repoRoot, $scm)) && p('actor') && e('admin'); //更新已有记录
r($repo->saveRecordTest($action, $log, $repoRoot, $scm, true)) && p('field') && e('git'); //查看历史记录
+22 -7
View File
@@ -500,22 +500,37 @@ class repoTest
return $objects;
}
public function saveAction2PMSTest($objects, $log, $repoRoot = '', $encodings = 'utf-8', $scm = 'svn', $gitlabAccountPairs = array())
public function saveAction2PMSTest($log, $repoID, $scm = 'git', $gitlabAccountPairs = array())
{
$objects = $this->objectModel->saveAction2PMS($objects, $log, $repoRoot, $encodings, $scm, $gitlabAccountPairs);
$repo = $this->objectModel->getByID($repoID);
$objects = $this->objectModel->parseComment($log->msg);
$result = $this->objectModel->saveAction2PMS($objects, $log, $repo->path, $repo->encoding, $scm, $gitlabAccountPairs);
if(dao::isError()) return dao::getError();
return $objects;
return $result;
}
public function saveRecordTest($action, $changes)
public function saveRecordTest(object $action, object $log, string $repoRoot, string $scm, bool $returnHistory = false)
{
$objects = $this->objectModel->saveRecord($action, $changes);
$action->comment = $this->objectModel->lang->repo->revisionA . ': #' . $action->extra . "<br />" . htmlSpecialString($this->objectModel->iconvComment($log->msg, 'utf-8'));
$changes = $this->objectModel->createActionChanges($log, $repoRoot, $scm);
$this->objectModel->saveRecord($action, $changes);
if(dao::isError()) return dao::getError();
return $objects;
$record = $this->objectModel->dao->select('*')->from(TABLE_ACTION)
->where('objectType')->eq($action->objectType)
->andWhere('objectID')->eq($action->objectID)
->andWhere('extra')->eq($action->extra)
->andWhere('action')->eq($action->action)
->fetch();
if($returnHistory)
{
return $this->objectModel->dao->select('*')->from(TABLE_HISTORY)->where('action')->eq($record->id)->fetch();
}
return $record;
}
public function createActionChangesTest($log, $repoRoot, $scm = 'svn')