+ [misc] Add unit tests for projectZen::checkWorkdaysLegtimate() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -124,4 +124,21 @@ class projectZenTest
|
||||
$projectList = $this->objectModel->dao->select('*')->from(TABLE_PROJECT)->where('type')->eq('project')->fetchAll('id');
|
||||
return callZenMethod('project', 'processProjectListData', [$projectList]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试检查工作日是否合法。
|
||||
* Test checkWorkdaysLegtimate method.
|
||||
*
|
||||
* @param object $project
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function checkWorkdaysLegtimateTest($project): bool
|
||||
{
|
||||
$method = $this->projectZenTest->getMethod('checkWorkdaysLegtimate');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->projectZenTest->newInstance(), [$project]);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 projectZen::checkWorkdaysLegtimate();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 执行projectTest模块的checkWorkdaysLegtimateTest方法,参数是$project1 @1
|
||||
- 执行projectTest模块的checkWorkdaysLegtimateTest方法,参数是$project2 @1
|
||||
- 执行projectTest模块的checkWorkdaysLegtimateTest方法,参数是$project3 @0
|
||||
- 执行projectTest模块的checkWorkdaysLegtimateTest方法,参数是$project4 @1
|
||||
- 执行projectTest模块的checkWorkdaysLegtimateTest方法,参数是$project5 @1
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/projectzen.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备
|
||||
zenData('project')->loadYaml('project_checkworkdayslegtimate', false, 2)->gen(5);
|
||||
|
||||
// 3. 用户登录
|
||||
su('admin');
|
||||
|
||||
// 4. 创建测试实例
|
||||
$projectTest = new projectZenTest();
|
||||
|
||||
// 5. 测试步骤(必须至少5个)
|
||||
|
||||
// 步骤1:正常情况,工作天数(20)小于日期差(30+1=31)
|
||||
$project1 = new stdClass();
|
||||
$project1->begin = '2024-01-01';
|
||||
$project1->end = '2024-01-31';
|
||||
$project1->days = 20;
|
||||
r($projectTest->checkWorkdaysLegtimateTest($project1)) && p() && e('1');
|
||||
|
||||
// 步骤2:边界情况,工作天数(31)等于日期差(30+1=31)
|
||||
$project2 = new stdClass();
|
||||
$project2->begin = '2024-01-01';
|
||||
$project2->end = '2024-01-31';
|
||||
$project2->days = 31;
|
||||
r($projectTest->checkWorkdaysLegtimateTest($project2)) && p() && e('1');
|
||||
|
||||
// 步骤3:无效情况,工作天数(40)大于日期差(30+1=31)
|
||||
$project3 = new stdClass();
|
||||
$project3->begin = '2024-01-01';
|
||||
$project3->end = '2024-01-31';
|
||||
$project3->days = 40;
|
||||
dao::$errors = array(); // 清除之前的错误
|
||||
r($projectTest->checkWorkdaysLegtimateTest($project3)) && p() && e('0');
|
||||
|
||||
// 步骤4:无工作天数字段情况
|
||||
$project4 = new stdClass();
|
||||
$project4->begin = '2024-01-01';
|
||||
$project4->end = '2024-01-31';
|
||||
r($projectTest->checkWorkdaysLegtimateTest($project4)) && p() && e('1');
|
||||
|
||||
// 步骤5:工作天数为0的情况
|
||||
$project5 = new stdClass();
|
||||
$project5->begin = '2024-01-01';
|
||||
$project5->end = '2024-01-31';
|
||||
$project5->days = 0;
|
||||
r($projectTest->checkWorkdaysLegtimateTest($project5)) && p() && e('1');
|
||||
@@ -0,0 +1,119 @@
|
||||
---
|
||||
title: project表测试数据 - checkWorkdaysLegtimate方法测试
|
||||
desc: 测试项目工作日检查逻辑的数据
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 项目ID
|
||||
range: 1-5
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: project
|
||||
note: 父项目ID,0表示顶级项目
|
||||
range: 0
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: model
|
||||
note: 项目模型
|
||||
range: scrum
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: type
|
||||
note: 项目类型
|
||||
range: project
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: parent
|
||||
note: 父节点ID
|
||||
range: 0
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: path
|
||||
note: 路径
|
||||
range: ',1,'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: grade
|
||||
note: 层级
|
||||
range: 1
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: name
|
||||
note: 项目名称
|
||||
range: '项目1,项目2,项目3,项目4,项目5'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: code
|
||||
note: 项目代码
|
||||
range: 'PRJ001,PRJ002,PRJ003,PRJ004,PRJ005'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: begin
|
||||
note: 开始日期
|
||||
range: '2024-01-01'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: end
|
||||
note: 结束日期
|
||||
range: '2024-01-31'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: days
|
||||
note: 工作天数
|
||||
range: 20,30,40,0,0
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: status
|
||||
note: 项目状态
|
||||
range: wait
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: deleted
|
||||
note: 是否删除
|
||||
range: '0'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: openedBy
|
||||
note: 创建者
|
||||
range: admin
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: openedDate
|
||||
note: 创建日期
|
||||
range: '2024-01-01 09:00:00'
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
Reference in New Issue
Block a user