ThinkAdmin/plugin/think-plugs-system/tests/ConfigPageRenderTest.php
邹景立 7e87c0d65a style(config): 重整系统配置页布局
将系统配置首页从混合展示存储信息调整为聚焦运行模式与基础参数,移除首页对存储中心上下文的加载,降低配置页渲染耦合。

拆分系统参数表单的入口主题、插件中心、运行参数、安全资源和品牌信息构建逻辑,并加入专用响应式样式,让多列字段在桌面端更紧凑、小屏端自动堆叠。

优化系统与存储概览卡片的栅格展示,更新渲染测试断言,确保配置页不再展示旧存储中心入口,同时保留存储配置独立页面的概览信息。
2026-05-21 00:15:55 +08:00

209 lines
9.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* +----------------------------------------------------------------------
* | ThinkAdmin Plugin
* +----------------------------------------------------------------------
* | Copyright (c) 2014~2026 ThinkAdmin [ thinkadmin.top ]
* +----------------------------------------------------------------------
* | Official Website: https://thinkadmin.top
* +----------------------------------------------------------------------
* | Licensed: https://mit-license.org
* | Disclaimer: https://thinkadmin.top/disclaimer
* | Vip Rights: https://thinkadmin.top/vip-introduce
* +----------------------------------------------------------------------
* | Gitee Repository: https://gitee.com/zoujingli/ThinkAdmin
* | Github Repository: https://github.com/zoujingli/ThinkAdmin
* +----------------------------------------------------------------------
*/
namespace think\admin\tests;
use plugin\system\controller\Config as ConfigController;
use plugin\system\service\LangService;
use plugin\system\storage\StorageConfig;
use plugin\system\service\SystemContext as PluginSystemContext;
use think\admin\contract\SystemContextInterface;
use think\admin\runtime\RequestContext;
use think\admin\tests\Support\SqliteIntegrationTestCase;
use think\Container;
use think\exception\HttpResponseException;
use think\Request;
/**
* @internal
* @coversNothing
*/
class ConfigPageRenderTest extends SqliteIntegrationTestCase
{
public function testIndexRendersDashboardWithoutPluginCards(): void
{
$this->bindAdminUser();
$html = $this->callPageHtml('index');
$this->assertStringContainsString('统一管理运行模式与系统基础参数', $html);
$this->assertStringContainsString('站点名称', $html);
$this->assertStringContainsString('插件中心', $html);
$this->assertStringContainsString('菜单入口策略', $html);
$this->assertStringContainsString('system-site-fields', $html);
$this->assertStringContainsString('page-builder-schema', $html);
$this->assertStringContainsString('系统参数配置', $html);
$this->assertStringNotContainsString('插件应用', $html);
$this->assertStringNotContainsString('插件标识', $html);
$this->assertStringNotContainsString('默认存储驱动', $html);
$this->assertStringNotContainsString('存储中心', $html);
$this->assertStringNotContainsString('进入存储中心', $html);
$this->assertStringNotContainsString('配置当前驱动', $html);
}
public function testSystemRendersGroupedConfigurationSections(): void
{
$this->bindAdminUser();
sysdata('system.security', ['jwt_secret' => '1234567890abcdef1234567890abcdef']);
$html = $this->callPageHtml('system');
$this->assertStringContainsString('系统参数设置', $html);
$this->assertStringContainsString('保存修改', $html);
$this->assertStringContainsString('取消修改', $html);
$this->assertStringContainsString('class="system-config-form layui-form"', $html);
$this->assertStringContainsString('SystemConfigFormStyle', $html);
$this->assertStringContainsString('system-config-cols-2', $html);
$this->assertStringContainsString('system-config-cols-3', $html);
$this->assertStringContainsString('data-builder-scope="page"', $html);
$this->assertStringContainsString('站点品牌信息', $html);
$this->assertStringContainsString('data-target-submit', $html);
$this->assertStringContainsString('data-target-backup', $html);
$this->assertStringContainsString('data-open-site-theme', $html);
$this->assertStringContainsString("'760px'", $html);
$this->assertStringContainsString('form-builder-schema', $html);
$this->assertStringContainsString('运行参数', $html);
$this->assertStringContainsString('id="RefreshJwtKey"', $html);
$this->assertStringContainsString('type="password"', $html);
$this->assertStringContainsString('name="site[login_entry]"', $html);
$this->assertStringContainsString('data-field="site[browser_icon]"', $html);
$this->assertStringContainsString('name="site[host]"', $html);
$this->assertStringContainsString('站点基础域名', $html);
$this->assertStringNotContainsString('1234567890abcdef1234567890abcdef', $html);
$this->assertStringNotContainsString('统一管理登录入口、品牌信息与安全配置', $html);
}
public function testStorageRendersBuilderDashboard(): void
{
$this->bindAdminUser();
$html = $this->callPageHtml('storage');
$this->assertStringContainsString('统一管理文件上传、命名策略与外链输出', $html);
$this->assertStringContainsString('存储引擎', $html);
$this->assertStringContainsString('page-builder-schema', $html);
$this->assertStringContainsString('当前默认驱动', $html);
$this->assertStringContainsString('storage-overview-kv', $html);
}
public function testStorageDriverFormRendersWithBuilder(): void
{
$this->bindAdminUser();
StorageConfig::save([
'default_driver' => 'local',
'naming_rule' => 'xmd5',
'link_mode' => 'none',
'allowed_extensions' => ['png', 'jpg'],
'drivers' => [
'local' => ['protocol' => 'follow', 'domain' => ''],
'alist' => ['protocol' => 'http', 'domain' => 'storage.example.com', 'path' => '/uploads', 'username' => 'root', 'password' => 'alist-secret'],
'qiniu' => ['protocol' => 'https', 'region' => 'z0', 'bucket' => 'demo', 'domain' => 'cdn.example.com', 'access_key' => 'ak-demo', 'secret_key' => 'sk-demo'],
'upyun' => ['protocol' => 'https', 'bucket' => 'demo', 'domain' => 'up.example.com', 'username' => 'operator', 'password' => 'up-secret'],
'txcos' => ['protocol' => 'https', 'region' => 'ap-shanghai', 'bucket' => 'demo', 'domain' => 'cos.example.com', 'access_key' => 'sid-demo', 'secret_key' => 'skey-demo'],
'alioss' => ['protocol' => 'https', 'region' => 'oss-cn-hangzhou', 'bucket' => 'demo', 'domain' => 'oss.example.com', 'access_key' => 'oss-ak', 'secret_key' => 'oss-sk'],
],
]);
$html = $this->callPageHtml('storage', ['type' => 'local']);
$this->assertStringContainsString('本地服务器存储 存储配置', $html);
$this->assertStringContainsString('返回存储中心', $html);
$this->assertStringContainsString('全局上传策略', $html);
$this->assertStringContainsString('本地服务器存储 驱动参数', $html);
$this->assertStringContainsString('form-builder-schema', $html);
$this->assertStringContainsString('data-builder-preset="dialog-form"', $html);
$this->assertStringContainsString('name="storage[default_driver]" value="local"', $html);
$this->assertStringNotContainsString('alist-secret', $html);
$this->assertStringNotContainsString('ak-demo', $html);
$this->assertStringNotContainsString('sk-demo', $html);
$this->assertStringNotContainsString('data-builder-preset="page-form"', $html);
$this->assertStringNotContainsString('统一维护上传策略与驱动参数', $html);
}
public function testSystemRendersEnglishTextsWhenLangSetIsEnUs(): void
{
$this->bindAdminUser();
sysdata('system.security', ['jwt_secret' => '1234567890abcdef1234567890abcdef']);
$this->switchSystemLang('en-us');
$html = $this->callPageHtml('system');
$this->assertStringContainsString('System Parameter Settings', $html);
$this->assertStringContainsString('Save Changes', $html);
$this->assertStringContainsString('Cancel Modification', $html);
$this->assertStringContainsString('Site Branding', $html);
$this->assertStringContainsString('Runtime Settings', $html);
$this->assertStringContainsString('Login Entry', $html);
$this->assertStringContainsString('Site Base URL', $html);
$this->assertStringContainsString('Site Name', $html);
$this->assertStringContainsString('Choose Backend Default Theme', $html);
$this->assertStringNotContainsString('站点品牌信息', $html);
}
protected function defineSchema(): void
{
$this->createSystemDataTable();
}
protected function afterSchemaCreated(): void
{
$context = new PluginSystemContext();
Container::getInstance()->instance(SystemContextInterface::class, $context);
$this->app->instance(SystemContextInterface::class, $context);
$this->configureView([
'view_path' => TEST_PROJECT_ROOT . '/plugin/think-plugs-system/src/view' . DIRECTORY_SEPARATOR,
]);
}
private function callPageHtml(string $action, array $query = []): string
{
$request = (new Request())
->setMethod('GET')
->setController('config')
->setAction($action)
->withGet($query);
$this->app->instance('request', $request);
try {
$controller = new ConfigController($this->app);
$controller->{$action}();
self::fail("Expected ConfigController::{$action} to throw HttpResponseException.");
} catch (HttpResponseException $exception) {
return $exception->getResponse()->getContent();
}
}
private function bindAdminUser(): void
{
RequestContext::instance()->setAuth([
'id' => 9101,
'username' => 'admin',
'password' => $this->hashSystemPassword('changed-password'),
], '', true);
}
private function switchSystemLang(string $langSet): void
{
$this->app->lang->switchLangSet($langSet);
LangService::load($this->app, $langSet);
}
}