* [misc] Enhance unit tests for gitModel::printLog() 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:11 +08:00
co-authored by Claude
parent b0c4245e1c
commit d18a6613e8
2 changed files with 44 additions and 9 deletions
@@ -172,4 +172,21 @@ class gitTest
return false;
}
}
/**
* Test printLog method.
*
* @param string $log
* @access public
* @return string
*/
public function printLogTest(string $log): string
{
ob_start();
$this->gitModel->printLog($log);
$result = trim(ob_get_clean());
if(dao::isError()) return dao::getError();
return $result;
}
}
+27 -9
View File
@@ -3,22 +3,40 @@
/**
title=gitModel->printLog();
title=测试 gitModel::printLog();
timeout=0
cid=1
cid=0
- 输出日志信息 @abc
- 测试步骤1:正常字符串日志输出 @1
- 测试步骤2:空字符串日志输出 @1
- 测试步骤3:包含特殊字符的日志输出 @1
- 测试步骤4:长字符串日志输出 @1
- 测试步骤5:包含换行符的日志输出 @1
- 测试步骤6:数字字符串日志输出 @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/git.unittest.class.php';
su('admin');
global $tester;
$git = $tester->loadModel('git');
$gitTest = new gitTest();
ob_start();
$git->printLog('Log: abc');
$result = trim(ob_get_clean());
r(substr($result, -3)) && p() && e('abc'); // 输出日志信息
$result1 = $gitTest->printLogTest('test log message');
r(strpos($result1, 'test log message') !== false) && p() && e(1); // 测试步骤1:正常字符串日志输出
$result2 = $gitTest->printLogTest('');
r(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $result2)) && p() && e(1); // 测试步骤2:空字符串日志输出
$result3 = $gitTest->printLogTest('log with @#$%^&*()_+ special chars');
r(strpos($result3, 'log with @#$%^&*()_+ special chars') !== false) && p() && e(1); // 测试步骤3:包含特殊字符的日志输出
$result4 = $gitTest->printLogTest(str_repeat('A', 100));
r(strpos($result4, str_repeat('A', 100)) !== false) && p() && e(1); // 测试步骤4:长字符串日志输出
$result5 = $gitTest->printLogTest("line1\nline2");
r(strpos($result5, "line1\nline2") !== false) && p() && e(1); // 测试步骤5:包含换行符的日志输出
$result6 = $gitTest->printLogTest('12345');
r(strpos($result6, '12345') !== false) && p() && e(1); // 测试步骤6:数字字符串日志输出