* [misc] Enhance unit tests for programplanTao::buildPointDataForGantt() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:16:45 +08:00
co-authored by Claude
parent 385e9fe2d2
commit dc6cb89f82
4 changed files with 160 additions and 25 deletions
@@ -878,4 +878,35 @@ class programplanTest
return $result;
}
/**
* Test buildPointDataForGantt method.
*
* @param int $planID
* @param object $point
* @param array $reviewDeadline
* @access public
* @return object|array
*/
public function buildPointDataForGanttTest(int $planID, ?object $point, array $reviewDeadline): object|array
{
if($point === null) return array('error' => 'Point object is null');
try
{
$reflection = new ReflectionClass($this->objectTao);
$method = $reflection->getMethod('buildPointDataForGantt');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao, $planID, $point, $reviewDeadline);
if(dao::isError()) return dao::getError();
return $result;
}
catch(Throwable $e)
{
return array('error' => $e->getMessage());
}
}
}
+72 -25
View File
@@ -3,42 +3,89 @@
/**
title=测试 loadModel->buildPointDataForGantt()
title=测试 programplanTao::buildPointDataForGantt();
timeout=0
cid=0
- 禅道版本为IPD。
- 属性id @1-PP-1
- 属性reviewID @1
- 属性type @point
- 属性text @<i class='icon-seal'></i> 这个是评审或基线的标题1
- 步骤1:正常评审点数据构建属性id @1-PP-1
- 步骤2:验证数据类型属性type @point
- 步骤3:验证评审状态属性rawStatus @pass
- 步骤4:DCP类别评审点处理属性id @2-DCP-2
- 步骤5:TR类别评审点处理属性id @3-TR4-3
*/
include dirname(__FILE__, 5). '/test/lib/init.php';
su('admin');
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/programplan.unittest.class.php';
// 1. 准备测试数据
zendata('object')->loadYaml('object_buildpointdataforgantt', false, 2)->gen(5);
zendata('review')->loadYaml('review_buildpointdataforgantt', false, 2)->gen(5);
zenData('review')->gen(20);
zenData('object')->gen(20);
$project = zenData('project');
$project->type->range('stage');
$project->attribute->range('devel');
$project->begin->range('`2023-09-28`');
$project->end->range('`2024-04-02`');
$project->gen(10);
$project->begin->range('`2023-09-01`');
$project->end->range('`2023-12-31`');
$project->gen(3);
global $tester;
$tester->loadModel('programplan');
// 2. 用户登录
su('admin');
$point = $tester->programplan->dao->select('t1.*, t2.status, t2.lastReviewedDate,t2.id as reviewID')->from(TABLE_OBJECT)->alias('t1')
->leftJoin(TABLE_REVIEW)->alias('t2')->on('t1.id = t2.object')
->where('t1.deleted')->eq('0')
->andWhere('t1.project')->eq(1)
->andWhere('t1.product')->eq(1)
->fetch();
// 3. 创建测试实例
$programplanTest = new programplanTest();
$plans = $tester->programplan->dao->select('*')->from(TABLE_PROJECT)->where('type')->eq('stage')->fetchAll('id');
$plans = $tester->programplan->processPlans($plans);
// 4. 构建测试评审点对象
$normalPoint = new stdclass();
$normalPoint->id = 1;
$normalPoint->category = 'PP';
$normalPoint->title = '评审点标题1';
$normalPoint->status = 'pass';
$normalPoint->reviewID = 1;
$normalPoint->lastReviewedDate = '2023-06-01 14:00:00';
$normalPoint->createdDate = '2023-01-01 09:00:00';
$normalPoint->end = '2023-12-31';
$normalResult = $tester->programplan->initGanttPlans($plans);
$pointWithoutEnd = new stdclass();
$pointWithoutEnd->id = 2;
$pointWithoutEnd->category = 'DCP';
$pointWithoutEnd->title = '基线评审点2';
$pointWithoutEnd->status = 'reviewing';
$pointWithoutEnd->reviewID = 2;
$pointWithoutEnd->lastReviewedDate = '';
$pointWithoutEnd->createdDate = '2023-02-01 10:00:00';
$pointWithoutEnd->end = '';
r($tester->programplan->buildPointDataForGantt(1, $point, $normalResult['reviewDeadline'])) && p('id,reviewID,type,text') && e("1-PP-1,1,point,<i class='icon-seal'></i> 这个是评审或基线的标题1"); //禅道版本为IPD。
$trPoint = new stdclass();
$trPoint->id = 3;
$trPoint->category = 'TR4';
$trPoint->title = '测试评审点3';
$trPoint->status = 'wait';
$trPoint->reviewID = 3;
$trPoint->lastReviewedDate = '';
$trPoint->createdDate = '2023-03-01 11:00:00';
$trPoint->end = '';
$dcpPoint = new stdclass();
$dcpPoint->id = 4;
$dcpPoint->category = 'PDCP';
$dcpPoint->title = '设计评审点4';
$dcpPoint->status = 'fail';
$dcpPoint->reviewID = 4;
$dcpPoint->lastReviewedDate = '2023-07-01 15:00:00';
$dcpPoint->createdDate = '2023-01-15 09:30:00';
$dcpPoint->end = '';
// 5. 准备reviewDeadline数据
$reviewDeadline = array(
1 => array('stageEnd' => '2023-12-31', 'stageBegin' => '2023-01-01'),
2 => array('stageEnd' => '2024-01-31', 'stageBegin' => '2023-02-01'),
3 => array('stageEnd' => '2024-02-28', 'stageBegin' => '2023-03-01', 'taskEnd' => '2023-11-30')
);
// 6. 执行测试步骤
r($programplanTest->buildPointDataForGanttTest(1, $normalPoint, $reviewDeadline)) && p('id') && e('1-PP-1'); // 步骤1:正常评审点数据构建
r($programplanTest->buildPointDataForGanttTest(1, $normalPoint, $reviewDeadline)) && p('type') && e('point'); // 步骤2:验证数据类型
r($programplanTest->buildPointDataForGanttTest(1, $normalPoint, $reviewDeadline)) && p('rawStatus') && e('pass'); // 步骤3:验证评审状态
r($programplanTest->buildPointDataForGanttTest(2, $pointWithoutEnd, $reviewDeadline)) && p('id') && e('2-DCP-2'); // 步骤4DCP类别评审点处理
r($programplanTest->buildPointDataForGanttTest(3, $trPoint, $reviewDeadline)) && p('id') && e('3-TR4-3'); // 步骤5TR类别评审点处理
@@ -0,0 +1,37 @@
---
title: buildPointDataForGantt方法测试数据
desc: 用于测试programplanTao::buildPointDataForGantt方法的评审点数据
fields:
- field: id
note: 评审点ID
range: 1-10
prefix: ""
postfix: ""
- field: project
note: 项目ID
range: 1-3
- field: product
note: 产品ID
range: 1-2
- field: category
note: 评审点类别
range: [PP,DCP,TR4,PDCP,CDCP]
- field: title
note: 评审点标题
range: [评审点标题1,评审点标题2,基线评审点3,设计评审点4,测试评审点5]
- field: begin
note: 计划开始时间
range: ['2023-01-01','2023-02-01','2023-03-01','','0000-00-00']
- field: end
note: 计划结束时间
range: ['2023-12-31','2024-01-31','2024-02-28','','0000-00-00']
- field: createdDate
note: 创建时间
range: ['2023-01-01 09:00:00','2023-02-01 10:00:00','2023-03-01 11:00:00']
- field: deleted
note: 是否删除
range: ['0']
- field: enabled
note: 是否启用
range: [1]
@@ -0,0 +1,20 @@
---
title: buildPointDataForGantt方法评审测试数据
desc: 用于测试programplanTao::buildPointDataForGantt方法的评审状态数据
fields:
- field: id
note: 评审ID
range: 1-10
- field: object
note: 评审对象ID
range: 1-5
- field: status
note: 评审状态
range: [pass,fail,reviewing,wait,'']
- field: lastReviewedDate
note: 最后评审时间
range: ['2023-06-01 14:00:00','2023-07-01 15:00:00','','0000-00-00 00:00:00']
- field: createdDate
note: 创建时间
range: ['2023-01-01 09:00:00','2023-02-01 10:00:00','2023-03-01 11:00:00']