* [misc] Enhance unit tests for commonModel::isOpenMethod() 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:15:48 +08:00
co-authored by Claude
parent 9477cb791b
commit 557e2dca04
2 changed files with 41 additions and 18 deletions
@@ -2714,4 +2714,20 @@ class commonTest
return $result;
}
/**
* Test isOpenMethod method.
*
* @param string $module
* @param string $method
* @access public
* @return bool
*/
public function isOpenMethodTest($module, $method)
{
$result = $this->objectModel->isOpenMethod($module, $method);
if(dao::isError()) return dao::getError();
return $result;
}
}
+25 -18
View File
@@ -1,30 +1,37 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
su('admin');
/**
title=测试 commonModel->isOpenMethod();
title=测试 commonModel::isOpenMethod();
timeout=0
cid=1
cid=0
- 执行$priv1 @1
- 执行$priv2 @1
- 执行$priv3 @0
- 执行$priv4 @1
- 步骤1:公开方法权限验证 @1
- 步骤2:登录后方法权限验证 @1
- 步骤3:非公开方法权限验证 @0
- 步骤4:特殊模块方法权限验证 @1
- 步骤5:Ajax方法权限验证 @1
- 步骤6:block模块特殊方法权限验证 @1
- 步骤7:不存在方法权限验证 @0
*/
global $tester;
$tester->loadModel('common');
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/common.unittest.class.php';
$priv1 = $tester->common->isOpenMethod('misc', 'changelog');
$priv2 = $tester->common->isOpenMethod('tutorial', 'quit');
$priv3 = $tester->common->isOpenMethod('my', 'task');
$priv4 = $tester->common->isOpenMethod('product', 'showerrornone');
// 2. 用户登录(已登录状态进行测试)
su('admin');
r($priv1) && p() && e('1');
r($priv2) && p() && e('1');
r($priv3) && p() && e('0');
r($priv4) && p() && e('1');
// 3. 创建测试实例
$commonTest = new commonTest();
// 4. 测试步骤:必须包含至少5个测试步骤
r($commonTest->isOpenMethodTest('misc', 'changelog')) && p() && e('1'); // 步骤1:公开方法权限验证
r($commonTest->isOpenMethodTest('tutorial', 'quit')) && p() && e('1'); // 步骤2:登录后方法权限验证
r($commonTest->isOpenMethodTest('my', 'task')) && p() && e('0'); // 步骤3:非公开方法权限验证
r($commonTest->isOpenMethodTest('product', 'showerrornone')) && p() && e('1'); // 步骤4:特殊模块方法权限验证
r($commonTest->isOpenMethodTest('user', 'ajaxGetList')) && p() && e('1'); // 步骤5:Ajax方法权限验证
r($commonTest->isOpenMethodTest('block', 'dashboard')) && p() && e('1'); // 步骤6:block模块特殊方法权限验证
r($commonTest->isOpenMethodTest('unknown', 'invalidmethod')) && p() && e('0'); // 步骤7:不存在方法权限验证