+ [misc] Add unit tests for commonModel::printBack() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-11-05 18:51:26 +08:00
co-authored by Claude
parent a0d16ac359
commit c283ab718a
2 changed files with 96 additions and 0 deletions
+67
View File
@@ -41,4 +41,71 @@ class commonModelTest extends baseTest
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test printBack method metadata.
*
* @param string $checkType
* @access public
* @return mixed
*/
public function printBackMetaTest(string $checkType)
{
if($checkType == 'exists')
{
return method_exists('commonModel', 'printBack') ? '1' : '0';
}
$reflection = new ReflectionMethod('commonModel', 'printBack');
if($checkType == 'static')
{
return $reflection->isStatic() ? '1' : '0';
}
if($checkType == 'public')
{
return $reflection->isPublic() ? '1' : '0';
}
if($checkType == 'paramCount')
{
return (string)$reflection->getNumberOfParameters();
}
return '0';
}
/**
* Test printBack method.
*
* @param string $backLink
* @param string $class
* @param string $misc
* @param bool $onlyBody
* @access public
* @return mixed
*/
public function printBackTest(string $backLink, string $class = '', string $misc = '', bool $onlyBody = false)
{
if($onlyBody)
{
$_GET['onlybody'] = 'yes';
}
else
{
unset($_GET['onlybody']);
}
ob_start();
$result = commonModel::printBack($backLink, $class, $misc);
$output = ob_get_clean();
if(dao::isError()) return dao::getError();
// Return different data based on what we're testing
if($onlyBody) return $result;
if(!empty($output)) return $output;
return $result;
}
}
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
/**
title=测试 commonModel::printBack();
timeout=0
cid=0
- 测试步骤1:检查printBack方法是否存在 @1
- 测试步骤2:检查printBack方法是否为静态方法 @1
- 测试步骤3:检查printBack方法是否为公共方法 @1
- 测试步骤4:检查printBack方法参数数量 @3
- 测试步骤5:在onlybody模式下调用printBack返回false @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
su('admin');
$commonTest = new commonModelTest();
r($commonTest->printBackMetaTest('exists')) && p() && e('1'); // 测试步骤1:检查printBack方法是否存在
r($commonTest->printBackMetaTest('static')) && p() && e('1'); // 测试步骤2:检查printBack方法是否为静态方法
r($commonTest->printBackMetaTest('public')) && p() && e('1'); // 测试步骤3:检查printBack方法是否为公共方法
r($commonTest->printBackMetaTest('paramCount')) && p() && e('3'); // 测试步骤4:检查printBack方法参数数量
r($commonTest->printBackTest('index.php', '', '', true)) && p() && e('0'); // 测试步骤5:在onlybody模式下调用printBack返回false