+ Add unit test case for build.

This commit is contained in:
caoyanyi
2023-10-07 09:57:44 +08:00
parent 186bb55781
commit 8a8786ff8f
3 changed files with 51 additions and 8 deletions
+4 -4
View File
@@ -860,23 +860,23 @@ class buildModel extends model
* @access public
* @return array
*/
public function buildActionList(object $build, int $executionID = 0, $from = 'execution'): array
public function buildActionList(object $build, int $executionID = 0, string $from = 'execution'): array
{
$actions = array();
$executionID = $executionID ? $executionID : $build->execution;
$execution = $this->loadModel('execution')->getByID($executionID);
$execution = $this->loadModel('execution')->fetchByID($executionID);
$module = $from == 'projectbuild' ? 'projectbuild' : 'build';
$build->executionDeleted = $execution ? $execution->deleted : 0;
if(common::hasPriv($module, 'linkstory') && common::canBeChanged('build', $build)) $actions[] = $from == 'projectbuild' ? 'linkProjectStory' : 'linkStory';
if(common::hasPriv('testtask', 'create')) $actions [] = $execution && $execution->deleted === '1' ? '-createTest' : 'createTest';
if(common::hasPriv('testtask', 'create')) $actions[] = $execution && $execution->deleted === '1' ? '-createTest' : 'createTest';
$isNotKanban = $from == 'execution' && !empty($execution->type) && $execution->type != 'kanban';
$isFromProject = $from == 'projectbuild' || empty($execution->type) || $execution->type == 'kanban';
if($isNotKanban && common::hasPriv('execution', 'bug')) $actions[] = 'viewBug';
if($isFromProject && common::hasPriv($module, 'view')) $actions[] = $from == 'projectbuild' ? 'projectBugList' : 'bugList';
if($isFromProject && common::hasPriv($module, 'view')) $actions[] = $from == 'projectbuild' ? 'projectBugList' : 'bugList';
if(common::hasPriv($module, 'edit')) $actions[] = $module . 'Edit';
if(common::hasPriv($module, 'delete')) $actions[] = 'delete';
+20 -4
View File
@@ -483,12 +483,12 @@ class buildTest
/**
* Is clickable
*
* @param string $model
* @param bool $deleted
* @param string $model
* @param bool $deleted
* @access public
* @return void
* @return array|bool
*/
public function isClickable($model = 'bug', $deleted = false)
public function isClickable(string $model = 'bug', bool $deleted = false): array|bool
{
$build = new stdclass();
$build->executionDeleted = $deleted;
@@ -497,4 +497,20 @@ class buildTest
return $objectModels;
}
/**
* 根据状态和权限生成列表中操作列按钮。
* Build table action menu for build browse page.
*
* @param int $buildID
* @param int $executionID
* @access public
* @return string
*/
public function buildActionListObject(int $buildID, int $executionID = 0): string
{
$build = $this->objectModel->getByID($buildID);
$actions = $this->objectModel->buildActionList($build, $executionID);
return implode('|', $actions);
}
}
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/build.class.php';
su('admin');
zdTable('build')->config('build')->gen(7);
$execution = zdTable('project')->config('execution');
$execution->deleted->range('0,1');
$execution->gen(30);
/**
title=测试 buildModel->buildActionList();
timeout=0
cid=1
*/
$buildIdList = range(2, 7);
$executions = array('normal' => 11, 'deleted' => 60, 'kanban' => 124);
$buildTester = new buildTest();
r($buildTester->buildActionListObject($buildIdList[0], $executions['normal'])) && p() && e('linkStory|createTest|viewBug|buildEdit|delete'); // 正常的执行
r($buildTester->buildActionListObject($buildIdList[1], $executions['deleted'])) && p() && e('linkStory|-createTest|viewBug|buildEdit|delete'); // 已删除的执行
r($buildTester->buildActionListObject($buildIdList[1], $executions['kanban'])) && p() && e('linkStory|-createTest|bugList|buildEdit|delete'); // 看板执行