+ [misc] Add unit tests for commonModel::printModuleMenu() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1817,6 +1817,57 @@ class commonTest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printModuleMenu method.
|
||||
*
|
||||
* @param string $activeMenu
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function printModuleMenuTest($activeMenu = 'user')
|
||||
{
|
||||
global $app, $lang;
|
||||
|
||||
// Mock basic global variables if not set
|
||||
if (!isset($app))
|
||||
{
|
||||
$app = new stdClass();
|
||||
$app->rawModule = 'user';
|
||||
$app->rawMethod = 'browse';
|
||||
$app->tab = 'system';
|
||||
$app->viewType = 'html';
|
||||
$app->isFlow = false;
|
||||
}
|
||||
|
||||
if (!isset($lang))
|
||||
{
|
||||
$lang = new stdClass();
|
||||
}
|
||||
|
||||
// Set up basic tab menu structure
|
||||
if (!isset($lang->{$app->tab}))
|
||||
{
|
||||
$lang->{$app->tab} = new stdClass();
|
||||
}
|
||||
if (!isset($lang->{$app->tab}->menu))
|
||||
{
|
||||
$lang->{$app->tab}->menu = new stdClass();
|
||||
}
|
||||
|
||||
ob_start();
|
||||
try {
|
||||
commonModel::printModuleMenu($activeMenu);
|
||||
$result = ob_get_clean();
|
||||
} catch (Exception $e) {
|
||||
ob_end_clean();
|
||||
return 'Exception: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printMainMenu method.
|
||||
*
|
||||
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 commonModel::printModuleMenu();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 验证方法存在 @1
|
||||
- 验证为静态方法 @1
|
||||
- 验证为公共方法 @1
|
||||
- 验证参数个数 @1
|
||||
- 验证无返回类型(void类型) @0
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
// 5个测试步骤,使用反射检查方法属性
|
||||
r(method_exists('commonModel', 'printModuleMenu')) && p() && e('1'); // 验证方法存在
|
||||
|
||||
$reflection = new ReflectionMethod('commonModel', 'printModuleMenu');
|
||||
r($reflection->isStatic() ? '1' : '0') && p() && e('1'); // 验证为静态方法
|
||||
r($reflection->isPublic() ? '1' : '0') && p() && e('1'); // 验证为公共方法
|
||||
r($reflection->getNumberOfParameters()) && p() && e('1'); // 验证参数个数
|
||||
r($reflection->hasReturnType() ? '1' : '0') && p() && e('0'); // 验证无返回类型(void类型)
|
||||
Reference in New Issue
Block a user