🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
260 lines
6.9 KiB
PHP
260 lines
6.9 KiB
PHP
<?php
|
|
class adminTest
|
|
{
|
|
public function __construct()
|
|
{
|
|
global $tester;
|
|
$this->objectModel = $tester->loadModel('admin');
|
|
$this->user = $tester->loadModel('user');
|
|
}
|
|
|
|
/**
|
|
* 测试获取配置信息是否成功。
|
|
* Test get api config.
|
|
*
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function getApiConfigTest(): string
|
|
{
|
|
$objects = $this->objectModel->getApiConfig();
|
|
if(empty($objects)) return 'Fail';
|
|
|
|
return 'Success';
|
|
}
|
|
|
|
/**
|
|
* 测试弱口令扫描。
|
|
* Test check weak.
|
|
*
|
|
* @param string $account
|
|
* @access public
|
|
* @return bool
|
|
*/
|
|
public function checkWeakTest(string $account): bool
|
|
{
|
|
$user = $this->user->getById($account);
|
|
$result = $this->objectModel->checkWeak($user);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 测试获取页面导航索引。
|
|
* Test get menu key.
|
|
*
|
|
* @param string $moduleName
|
|
* @param string $methodName
|
|
* @param array $params
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getMenuKeyTest(string $moduleName, string $methodName, array $params = array()): string
|
|
{
|
|
global $app;
|
|
$app->rawModule = $moduleName;
|
|
$app->rawMethod = $methodName;
|
|
$app->rawParams = $params;
|
|
|
|
$menuKey = $this->objectModel->getMenuKey();
|
|
return empty($menuKey) ? 'null' : $menuKey;
|
|
}
|
|
|
|
/**
|
|
* 测试获取有权限的链接。
|
|
* Test get the authorized link.
|
|
*
|
|
* @param string $menuKey
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getHasPrivLinkTest(string $menuKey): array
|
|
{
|
|
global $lang;
|
|
$link = array();
|
|
foreach($lang->admin->menuList->$menuKey['subMenu'] as $subMenu)
|
|
{
|
|
$link = $this->objectModel->getHasPrivLink($subMenu);
|
|
if(!empty($link)) return $link;
|
|
}
|
|
return $link;
|
|
}
|
|
|
|
/**
|
|
* 测试获取签名。
|
|
* Test get signature.
|
|
*
|
|
* @param array $params
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function getSignatureTest(array $params): string
|
|
{
|
|
$result = $this->objectModel->getSignature($params);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 测试检查导航权限并设置导航链接。
|
|
* Test check priv menu.
|
|
*
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function checkPrivMenuTest(): array
|
|
{
|
|
global $lang;
|
|
|
|
// 保存原始数据
|
|
$originalMenuList = isset($lang->admin->menuList) ? $lang->admin->menuList : null;
|
|
|
|
// 执行checkPrivMenu方法
|
|
$this->objectModel->checkPrivMenu();
|
|
|
|
// 检查是否有错误
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
// 获取处理结果
|
|
$result = array();
|
|
if(isset($lang->admin->menuList))
|
|
{
|
|
$result['hasMenuList'] = true;
|
|
$result['menuCount'] = count(get_object_vars($lang->admin->menuList));
|
|
|
|
// 检查菜单项是否有link和disabled属性设置
|
|
$hasLinkedMenu = false;
|
|
$hasDisabledMenu = false;
|
|
foreach($lang->admin->menuList as $menuKey => $menu)
|
|
{
|
|
if(!empty($menu['link'])) $hasLinkedMenu = true;
|
|
if($menu['disabled']) $hasDisabledMenu = true;
|
|
}
|
|
$result['hasLinkedMenu'] = $hasLinkedMenu;
|
|
$result['hasDisabledMenu'] = $hasDisabledMenu;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 测试设置后台二级导航。
|
|
* Test set menu.
|
|
*
|
|
* @param string $moduleName
|
|
* @param string $methodName
|
|
* @param array $params
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function setMenuTest(string $moduleName = 'admin', string $methodName = 'index', array $params = array())
|
|
{
|
|
global $app, $lang;
|
|
|
|
// 保存原始值
|
|
$originalModule = isset($app->rawModule) ? $app->rawModule : '';
|
|
$originalMethod = isset($app->rawMethod) ? $app->rawMethod : '';
|
|
$originalParams = isset($app->rawParams) ? $app->rawParams : array();
|
|
|
|
// 设置测试值
|
|
$app->rawModule = $moduleName;
|
|
$app->rawMethod = $methodName;
|
|
$app->rawParams = $params;
|
|
|
|
// 执行setMenu方法
|
|
$this->objectModel->setMenu();
|
|
|
|
// 检查是否有错误
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
// 恢复原始值
|
|
$app->rawModule = $originalModule;
|
|
$app->rawMethod = $originalMethod;
|
|
$app->rawParams = $originalParams;
|
|
|
|
// 返回设置结果的标识
|
|
$result = array();
|
|
if(isset($lang->admin->menu)) $result['hasMenu'] = true;
|
|
if(isset($lang->admin->menuOrder)) $result['hasMenuOrder'] = true;
|
|
if(isset($lang->admin->dividerMenu)) $result['hasDividerMenu'] = true;
|
|
if(isset($lang->admin->tabMenu)) $result['hasTabMenu'] = true;
|
|
if(isset($lang->switcherMenu)) $result['hasSwitcherMenu'] = true;
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 测试设置二级导航。
|
|
* Test set sub menu.
|
|
*
|
|
* @param string $menuKey
|
|
* @param array $menu
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function setSubMenuTest(string $menuKey, array $menu): array
|
|
{
|
|
$result = $this->objectModel->setSubMenu($menuKey, $menu);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test setTabMenu method.
|
|
*
|
|
* @param string $subMenuKey
|
|
* @param array $menu
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function setTabMenuTest(string $subMenuKey, array $menu)
|
|
{
|
|
$result = $this->objectModel->setTabMenu($subMenuKey, $menu);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test genDateUsed method.
|
|
*
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function genDateUsedTest()
|
|
{
|
|
$result = $this->objectModel->genDateUsed();
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Test setSwitcher method.
|
|
*
|
|
* @param string $currentMenuKey
|
|
* @access public
|
|
* @return mixed
|
|
*/
|
|
public function setSwitcherTest($currentMenuKey = 'system')
|
|
{
|
|
global $lang;
|
|
|
|
// 保存原始的switcherMenu值
|
|
$originalSwitcherMenu = isset($lang->switcherMenu) ? $lang->switcherMenu : null;
|
|
|
|
// 执行setSwitcher方法
|
|
$result = $this->objectModel->setSwitcher($currentMenuKey);
|
|
if(dao::isError()) return dao::getError();
|
|
|
|
// 简单返回方法执行是否成功(没有致命错误)
|
|
if(empty($currentMenuKey)) return '0';
|
|
|
|
// 对于非空参数,返回1表示执行成功
|
|
return 1;
|
|
}
|
|
}
|