+ [misc] Add unit tests for executionZen::getLinkedObjects() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:09:54 +08:00
co-authored by Claude
parent 901dbbaa4e
commit a371909508
9 changed files with 545 additions and 0 deletions
+324
View File
@@ -3650,4 +3650,328 @@ class executionTest
return $result;
}
/**
* Test buildExecutionKanbanData method.
*
* @param array $projectIdList
* @param array $executions
* @access public
* @return mixed
*/
public function buildExecutionKanbanDataTest(array $projectIdList, array $executions)
{
global $app;
// Set up user view
if(!isset($app->user)) $app->user = new stdClass();
if(!isset($app->user->view)) $app->user->view = new stdClass();
if(!isset($app->user->view->sprints)) $app->user->view->sprints = '4,5,6,7,8,9,10';
if(!isset($app->user->account)) $app->user->account = 'admin';
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('buildExecutionKanbanData');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $projectIdList, $executions);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getImportBugs method.
*
* @param int $executionID
* @param array $productIdList
* @param string $browseType
* @param int $queryID
* @param object $pager
* @access public
* @return mixed
*/
public function getImportBugsTest(int $executionID, array $productIdList, string $browseType, int $queryID, object $pager)
{
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('getImportBugs');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $executionID, $productIdList, $browseType, $queryID, $pager);
if(dao::isError()) return dao::getError();
return is_array($result) ? count($result) : $result;
}
/**
* Test processPrintKanbanData method.
*
* @param int $executionID
* @param array $dataList
* @access public
* @return mixed
*/
public function processPrintKanbanDataTest(int $executionID, array $dataList = array())
{
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('processPrintKanbanData');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $executionID, $dataList);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getLink method.
*
* @param string $module
* @param string $method
* @param string $type
* @access public
* @return string
*/
public function getLinkTest(string $module, string $method, string $type = '')
{
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$getLinkMethod = $reflection->getMethod('getLink');
$getLinkMethod->setAccessible(true);
$result = $getLinkMethod->invoke($this->objectZen, $module, $method, $type);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test setUserMoreLink method.
*
* @param mixed $execution
* @access public
* @return mixed
*/
public function setUserMoreLinkTest($execution = null)
{
global $config;
// 备份原始配置
$originalMoreLinks = isset($config->moreLinks) ? $config->moreLinks : array();
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('setUserMoreLink');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $execution);
if(dao::isError()) return dao::getError();
// 如果需要检查配置,返回结果和配置信息
$resultWithConfig = $result;
if(isset($config->moreLinks))
{
$resultWithConfig['morelinks'] = $config->moreLinks;
}
// 恢复原始配置
$config->moreLinks = $originalMoreLinks;
return $resultWithConfig;
}
/**
* Test initFieldsForCreate method.
*
* @param int $projectID
* @param array $output
* @access public
* @return mixed
*/
public function initFieldsForCreateTest($projectID, $output = array())
{
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('initFieldsForCreate');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $projectID, $output);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test correctErrorLang method.
*
* @param string $tabValue
* @access public
* @return array
*/
public function correctErrorLangTest($tabValue = '')
{
global $app, $lang, $config;
// 备份原始数据
$originalTab = isset($app->tab) ? $app->tab : '';
$originalLang = clone $lang;
$originalConfig = clone $config;
// 设置测试参数
if($tabValue !== '') $app->tab = $tabValue;
// 准备语言测试数据
if(!isset($lang->execution)) $lang->execution = new stdClass();
if(!isset($lang->error)) $lang->error = new stdClass();
if(!isset($lang->project)) $lang->project = new stdClass();
$lang->execution->teamName = '团队名称';
$lang->execution->name = '执行名称';
$lang->execution->code = '执行代号';
$lang->execution->execName = '执行名称';
$lang->execution->execCode = '执行代号';
$lang->error->repeat = '重复错误';
// 确保config配置存在
if(!isset($config->execution)) $config->execution = new stdClass();
if(!isset($config->execution->create)) $config->execution->create = new stdClass();
if(!isset($config->execution->create->requiredFields))
{
$config->execution->create->requiredFields = 'name,code';
}
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('correctErrorLang');
$method->setAccessible(true);
$method->invoke($this->objectZen);
if(dao::isError()) return dao::getError();
// 收集结果
$result = array();
$result['execution_team'] = isset($lang->execution->team) ? $lang->execution->team : '';
$result['error_unique'] = isset($lang->error->unique) ? $lang->error->unique : '';
$result['project_name'] = isset($lang->project->name) ? $lang->project->name : '';
$result['project_code'] = isset($lang->project->code) ? $lang->project->code : '';
$result['app_tab'] = $app->tab;
// 恢复原始数据
$app->tab = $originalTab;
$lang = $originalLang;
$config = $originalConfig;
return $result;
}
/**
* Test updateLinkedPlans method.
*
* @param int $executionID
* @param string $newPlans
* @param string $confirm
* @access public
* @return mixed
*/
public function updateLinkedPlansTest(int $executionID, string $newPlans = '', string $confirm = 'no')
{
try {
// Use reflection to call the protected method
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('updateLinkedPlans');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $executionID, $newPlans, $confirm);
if(dao::isError()) return dao::getError();
return $result;
}
catch(EndResponseException $e) {
// Capture the response data from EndResponseException
$response = $e->getResponse();
if(isset($response['data'])) {
return $response['data'];
}
return array('result' => 'success');
}
catch(Exception $e) {
return $e->getMessage();
}
}
/**
* Test checkLinkPlan method.
*
* @param int $executionID
* @param array $oldPlans
* @param array $postPlans
* @access public
* @return mixed
*/
public function checkLinkPlanTest(int $executionID, array $oldPlans, array $postPlans = array())
{
global $app;
// 备份原始POST数据
$originalPost = $_POST;
// 设置POST数据
$_POST = array();
if(!empty($postPlans)) $_POST['plans'] = $postPlans;
try {
// 使用反射调用受保护的方法
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('checkLinkPlan');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $executionID, $oldPlans);
// 恢复原始POST数据
$_POST = $originalPost;
if(dao::isError()) return dao::getError();
return $result;
}
catch(EndResponseException $e) {
// 恢复原始POST数据
$_POST = $originalPost;
// 捕获响应数据
$response = $e->getResponse();
if(isset($response['data'])) {
return $response['data'];
}
return array('result' => 'success');
}
catch(Exception $e) {
// 恢复原始POST数据
$_POST = $originalPost;
return $e->getMessage();
}
}
/**
* Test getLinkedObjects method.
*
* @param object $execution
* @access public
* @return mixed
*/
public function getLinkedObjectsTest($execution)
{
try {
$reflection = new ReflectionClass($this->objectZen);
$method = $reflection->getMethod('getLinkedObjects');
$method->setAccessible(true);
$result = $method->invoke($this->objectZen, $execution);
if(dao::isError()) return dao::getError();
return $result;
}
catch(Exception $e) {
return $e->getMessage();
}
}
}
@@ -2264,4 +2264,30 @@ class executionZenTest
return array('error' => $e->getMessage());
}
}
/**
* Test getLinkedObjects method.
*
* @param object $execution
* @access public
* @return mixed
*/
public function getLinkedObjectsTest($execution)
{
try {
$obj = $this->objectModel->loadZen('execution');
// Use reflection to call the protected method
$reflection = new ReflectionClass($obj);
$method = $reflection->getMethod('getLinkedObjects');
$method->setAccessible(true);
$result = $method->invoke($obj, $execution);
if(dao::isError()) return dao::getError();
return $result;
}
catch(Exception $e) {
return array('error' => $e->getMessage());
}
}
}
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env php
<?php
/**
title=测试 executionZen::getLinkedObjects();
timeout=0
cid=0
- 执行executionTest模块的getLinkedObjectsTest方法,参数是$execution1 @Array
- 执行executionTest模块的getLinkedObjectsTest方法,参数是$execution2 @(
- 执行executionTest模块的getLinkedObjectsTest方法,参数是$execution3 属性error @[error] =>
- 执行executionTest模块的getLinkedObjectsTest方法,参数是$execution4 @)
- 执行executionTest模块的getLinkedObjectsTest方法,参数是$execution5 @Array
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/executionzen.unittest.class.php';
zenData('project')->loadYaml('project_getlinkedobjects')->gen(10);
zenData('product')->loadYaml('product_getlinkedobjects')->gen(10);
zenData('productplan')->loadYaml('productplan_getlinkedobjects')->gen(15);
zenData('projectproduct')->loadYaml('projectproduct_getlinkedobjects')->gen(13);
zenData('projectstory')->loadYaml('projectstory_getlinkedobjects')->gen(17);
zenData('branch')->loadYaml('branch_getlinkedobjects')->gen(5);
su('admin');
$executionTest = new executionZenTest();
// 构建测试执行对象
$execution1 = new stdClass();
$execution1->id = 6;
$execution1->project = 1;
$execution2 = new stdClass();
$execution2->id = 7;
$execution2->project = 2;
$execution3 = new stdClass();
$execution3->id = 8;
$execution3->project = 2;
$execution4 = new stdClass();
$execution4->id = 9;
$execution4->project = 3;
$execution5 = new stdClass();
$execution5->id = 10;
$execution5->project = 3;
r($executionTest->getLinkedObjectsTest($execution1)) && p() && e('Array');
r($executionTest->getLinkedObjectsTest($execution2)) && p() && e('(');
r($executionTest->getLinkedObjectsTest($execution3)) && p('error') && e('[error] =>');
r($executionTest->getLinkedObjectsTest($execution4)) && p() && e(')');
r($executionTest->getLinkedObjectsTest($execution5)) && p() && e('Array');
@@ -0,0 +1,20 @@
title: branch表测试数据,用于getlinkedobjects方法
author: Claude
version: 1
fields:
- field: id
range: 1-5
note: 分支ID
- field: product
range: '2{2}, 3{2}, 5{1}'
note: 产品ID
- field: name
range: '分支V1.0, 分支V1.1, 分支V2.0, 分支V2.1, 主分支'
note: 分支名称
- field: status
range: 'active{4}, closed{1}'
note: 分支状态
- field: deleted
range: '0{5}'
note: 删除状态
@@ -0,0 +1,20 @@
title: product表测试数据,用于getlinkedobjects方法
author: Claude
version: 1
fields:
- field: id
range: 1-10
note: 产品ID
- field: name
range: '产品A, 产品B, 产品C, 产品D, 产品E{2}, 产品F{2}, 产品G{2}'
note: 产品名称
- field: type
range: 'normal{8}, branch{2}'
note: 产品类型
- field: status
range: 'normal{7}, closed{2}, deleted{1}'
note: 产品状态
- field: deleted
range: '0{9}, 1{1}'
note: 删除状态
@@ -0,0 +1,29 @@
title: productplan表测试数据,用于getlinkedobjects方法
author: Claude
version: 1
fields:
- field: id
range: 1-15
note: 计划ID
- field: product
range: '1{3}, 2{3}, 3{3}, 4{3}, 5{3}'
note: 产品ID
- field: branch
range: '0{10}, 1{3}, 2{2}'
note: 分支ID
- field: title
range: '计划1.0, 计划1.1, 计划1.2, 计划2.0, 计划2.1{2}, 计划3.0{2}, 计划4.0{2}, 计划5.0{5}'
note: 计划标题
- field: status
range: 'wait{5}, doing{5}, done{3}, closed{2}'
note: 计划状态
- field: begin
range: '2024-01-01{5}, 2024-03-01{5}, 2024-06-01{5}'
note: 开始时间
- field: end
range: '2024-06-30{5}, 2024-09-30{5}, 2024-12-31{5}'
note: 结束时间
- field: deleted
range: '0{14}, 1{1}'
note: 删除状态
@@ -0,0 +1,29 @@
title: project表测试数据,用于getlinkedobjects方法
author: Claude
version: 1
fields:
- field: id
range: 1-10
note: 项目ID
- field: name
range: '项目{1-5}, 执行{6-10}'
note: 项目名称
- field: type
range: 'project{5}, sprint{5}'
note: 项目类型
- field: status
range: 'wait{2}, doing{3}, suspended{2}, closed{3}'
note: 项目状态
- field: begin
range: '2024-01-01, 2024-02-01, 2024-03-01{8}'
note: 开始时间
- field: end
range: '2024-12-31, 2025-01-31, 2025-02-28{8}'
note: 结束时间
- field: project
range: '0{5}, 1{3}, 2{2}'
note: 父项目ID
- field: deleted
range: '0{9}, 1{1}'
note: 删除状态
@@ -0,0 +1,17 @@
title: projectproduct表测试数据,用于getlinkedobjects方法
author: Claude
version: 1
fields:
- field: project
range: '6{3}, 7{2}, 8{3}, 9{2}, 10{3}'
note: 执行ID
- field: product
range: '1{3}, 2{2}, 3{3}, 4{2}, 5{3}'
note: 产品ID
- field: branch
range: '0{10}, 1{2}, 2{1}'
note: 分支ID
- field: plan
range: '1,2{2}, 3,4{2}, 5{3}, 6,7{3}, 8,9,10{3}'
note: 关联计划
@@ -0,0 +1,23 @@
title: projectstory表测试数据,用于getlinkedobjects方法
author: Claude
version: 1
fields:
- field: project
range: '6{5}, 7{3}, 8{4}, 9{2}, 10{3}'
note: 执行ID
- field: product
range: '1{5}, 2{3}, 3{4}, 4{2}, 5{3}'
note: 产品ID
- field: branch
range: '0{15}, 1{2}'
note: 分支ID
- field: story
range: 1-17
note: 需求ID
- field: version
range: '1{15}, 2{2}'
note: 需求版本
- field: order
range: 1-17
note: 排序