+ [misc] Add unit tests for convertTao::buildWorklogData() 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:41 +08:00
co-authored by Claude
parent 0524ed2a64
commit 2f69580e72
2 changed files with 85 additions and 0 deletions
@@ -2128,4 +2128,30 @@ class convertTest
return 'error: ' . $e->getMessage();
}
}
/**
* Test buildWorklogData method.
*
* @param array $data
* @access public
* @return mixed
*/
public function buildWorklogDataTest($data = array())
{
try {
// 使用反射来访问protected方法
$reflection = new ReflectionClass($this->objectTao);
$method = $reflection->getMethod('buildWorklogData');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao, $data);
if(dao::isError()) return dao::getError();
return $result;
} catch (Exception $e) {
return 'exception: ' . $e->getMessage();
} catch (Error $e) {
return 'error: ' . $e->getMessage();
}
}
}
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env php
<?php
/**
title=测试 convertTao::buildWorklogData();
timeout=0
cid=0
- 步骤1:正常情况
- 属性id @1
- 属性issueid @100
- 属性author @testuser
- 属性worklogbody @Test worklog content
- 属性timeworked @3600
- 属性created @2023-01-01 10:00:00
- 步骤2:缺少部分可选字段
- 属性id @2
- 属性issueid @200
- 属性author @user2
- 属性worklogbody @~~
- 属性timeworked @0
- 步骤3:最小必需字段
- 属性id @3
- 属性issueid @300
- 属性author @~~
- 属性worklogbody @~~
- 属性timeworked @0
- 步骤4:包含无效字段
- 属性id @4
- 属性issueid @400
- 属性author @user4
- 属性worklogbody @Content with invalid field
- 步骤5:边界值数据
- 属性id @0
- 属性issueid @0
- 属性author @~~
- 属性worklogbody @~~
- 属性timeworked @0
- 属性created @~~
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/convert.unittest.class.php';
// 2. 用户登录(选择合适角色)
su('admin');
// 3. 创建测试实例(变量名与模块名一致)
$convertTest = new convertTest();
// 4. 🔴 强制要求:必须包含至少5个测试步骤
r($convertTest->buildWorklogDataTest(array('id' => 1, 'issue' => 100, 'author' => 'testuser', 'body' => 'Test worklog content', 'timeworked' => 3600, 'created' => '2023-01-01 10:00:00'))) && p('id,issueid,author,worklogbody,timeworked,created') && e('1,100,testuser,Test worklog content,3600,2023-01-01 10:00:00'); // 步骤1:正常情况
r($convertTest->buildWorklogDataTest(array('id' => 2, 'issue' => 200, 'author' => 'user2'))) && p('id,issueid,author,worklogbody,timeworked') && e('2,200,user2,~~,0'); // 步骤2:缺少部分可选字段
r($convertTest->buildWorklogDataTest(array('id' => 3, 'issue' => 300))) && p('id,issueid,author,worklogbody,timeworked') && e('3,300,~~,~~,0'); // 步骤3:最小必需字段
r($convertTest->buildWorklogDataTest(array('id' => 4, 'issue' => 400, 'author' => 'user4', 'invalidfield' => 'invalid', 'body' => 'Content with invalid field'))) && p('id,issueid,author,worklogbody') && e('4,400,user4,Content with invalid field'); // 步骤4:包含无效字段
r($convertTest->buildWorklogDataTest(array('id' => 0, 'issue' => 0, 'author' => '', 'body' => '', 'timeworked' => 0, 'created' => null))) && p('id,issueid,author,worklogbody,timeworked,created') && e('0,0,~~,~~,0,~~'); // 步骤5:边界值数据