|
|
<?php
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
set_error_handler(static function (int $severity, string $message, string $file, int $line): bool {
|
|
|
if ((error_reporting() & $severity) && ($severity & (E_WARNING | E_USER_WARNING | E_DEPRECATED))) {
|
|
|
throw new ErrorException($message, 0, $severity, $file, $line);
|
|
|
}
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
// Rendering and browser fixtures use synthetic accounts and announcements only.
|
|
|
$smarty = new Smarty();
|
|
|
$compileDir = sys_get_temp_dir() . '/user-announcement-view-' . bin2hex(random_bytes(6));
|
|
|
mkdir($compileDir);
|
|
|
$smarty->setCompileDir($compileDir);
|
|
|
$smarty->setTemplateDir(dirname(__DIR__) . '/resources/views/venix');
|
|
|
$smarty->assign('config', ['appName' => 'Venix Test', 'jump_delay' => 1000]);
|
|
|
$smarty->assign('cdn', '');
|
|
|
$smarty->assign('user', (object) ['user_name' => '演示用户']);
|
|
|
$smarty->assign('admin_can_manage', false);
|
|
|
$smarty->assign('ticket_navigation_enabled', true);
|
|
|
$smarty->assign('user_iso_enabled', false);
|
|
|
$preview = '<section class="host-card"><h1>用户页面预览</h1><p>此处仅使用合成数据,公告打开前不请求公告接口。</p></section>'
|
|
|
. str_repeat('<section class="host-card"><h2>预览内容</h2><p>用于检查打开公告前后页面滚动位置。</p></section>', 8);
|
|
|
$accountHtml = $smarty->fetch('string:{include file="user/layout_header.tpl" vu_title="账户设置" vu_active="edit"}')
|
|
|
. $preview . $smarty->fetch('string:{include file="user/layout_footer.tpl"}{include file="user/layout_scripts.tpl"}</body></html>');
|
|
|
$smarty->assign('cloud_page', 'fixture');
|
|
|
$smarty->assign('cloud_title', '我的实例');
|
|
|
$smarty->assign('cloud_vm_id', '');
|
|
|
$smarty->assign('cloud_invoice_id', '');
|
|
|
$cloudHtml = $smarty->fetch('cloud/page.tpl');
|
|
|
$cloudFixture = str_replace('<main class="content">', '<main class="content">' . $preview, $cloudHtml);
|
|
|
// Isolate this feature's browser preview from unrelated VM/session requests.
|
|
|
$cloudFixture = preg_replace('#<script type="module" src="/cloud/app\.js\?[^\"]*"></script>#', '', $cloudFixture);
|
|
|
$now = time();
|
|
|
$items = [];
|
|
|
for ($id = 12; $id >= 1; --$id) {
|
|
|
$kind = $id === 12 ? 'maintenance' : ($id === 11 ? 'incident' : 'notice');
|
|
|
$items[] = ['id' => $id, 'title' => $id === 12 ? '香港区域计划维护通知' : ($id === 11 ? '区域网络故障说明' : '站点服务通知 ' . $id),
|
|
|
'type' => $kind, 'type_label' => ['notice' => '通知', 'maintenance' => '维护', 'incident' => '故障'][$kind],
|
|
|
'body' => $id === 12 ? "维护时间:2026-10-01 02:00 至 03:00(站点时间)。\n维护期间可能短暂中断,请提前保存工作。\n这是一条预览公告,不代表真实维护安排。"
|
|
|
: ($id === 11 ? "历史故障说明,仅用于预览。\nHTML 不执行:<img src=x onerror=alert(1)>\n<script>window.announcementUnsafe=1</script>"
|
|
|
: "服务通知正文。\n保持段落换行,使用原有用户页面主题。"),
|
|
|
'status' => 'published', 'published_at' => '2026-09-' . str_pad((string) (17 + $id), 2, '0', STR_PAD_LEFT) . ' 10:00:00',
|
|
|
'updated_at' => '2026-09-' . str_pad((string) (17 + $id), 2, '0', STR_PAD_LEFT) . ' 10:00:00'];
|
|
|
}
|
|
|
$pages = [];
|
|
|
foreach ([1, 2] as $page) {
|
|
|
$pages[$page] = ['items' => array_slice($items, ($page - 1) * 10, 10),
|
|
|
'pagination' => ['page' => $page, 'per_page' => 10, 'total' => 12, 'total_pages' => 2], 'generated_at' => $now];
|
|
|
}
|
|
|
$empty = ['items' => [], 'pagination' => ['page' => 1, 'per_page' => 10, 'total' => 0, 'total_pages' => 1], 'generated_at' => $now];
|
|
|
if (in_array('--fixture', $argv ?? [], true)) {
|
|
|
echo json_encode(['html' => ['account' => $accountHtml, 'cloud' => $cloudFixture], 'pages' => $pages, 'empty' => $empty],
|
|
|
JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR);
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
$assert = static function (bool $condition, string $message): void { if (!$condition) throw new RuntimeException($message); };
|
|
|
$parse = static function (string $html): DOMXPath {
|
|
|
$dom = new DOMDocument(); libxml_use_internal_errors(true);
|
|
|
$dom->loadHTML('<?xml encoding="UTF-8">' . $html);
|
|
|
return new DOMXPath($dom);
|
|
|
};
|
|
|
foreach (['account' => $accountHtml, 'cloud' => $cloudHtml] as $mode => $html) {
|
|
|
$xpath = $parse($html);
|
|
|
$assert($xpath->query('//dialog[@id="panel-announcements-drawer"]')->length === 1, $mode . ': drawer missing or duplicated.');
|
|
|
$assert($xpath->query('//script[contains(@src,"/cloud/announcements.js?")]')->length === 1, $mode . ': shared module must load once.');
|
|
|
$assert($xpath->query('//header[contains(@class,"panel-topbar")]//button[@data-announcements-open]')->length === 1,
|
|
|
$mode . ': global topbar announcement trigger missing.');
|
|
|
$assert($xpath->query('//button[@data-announcements-open and @aria-controls="panel-announcements-drawer" and @aria-haspopup="dialog"]')->length === 1,
|
|
|
$mode . ': trigger accessibility contract missing.');
|
|
|
$assert($xpath->query('//a[@href="/user/announcement"]')->length === 0, $mode . ': retired announcement navigation remains.');
|
|
|
$assert($xpath->query('//*[@id="panel-announcements-list"]/*')->length === 0,
|
|
|
$mode . ': should not preload unrelated announcement content into every user response.');
|
|
|
$assert($xpath->query('//*[@id="panel-announcements-state" and @hidden and @role="alert"]')->length === 1
|
|
|
&& trim($xpath->query('//*[@id="panel-announcements-state"]')->item(0)->textContent) === '',
|
|
|
$mode . ': routine announcement loading and refresh must not display status messages.');
|
|
|
$assert($xpath->query('//button[@id="panel-announcements-refresh" and not(@hidden)]')->length === 1,
|
|
|
$mode . ': retain the manual refresh button.');
|
|
|
$assert($xpath->query('//*[@id="panel-announcements-read-time" and @hidden and not(@role) and not(@aria-live)]')->length === 1,
|
|
|
$mode . ': show read time only after a successful response, without recurring live announcements.');
|
|
|
$assert($xpath->query('//link[contains(@href,"admin-home.css")]')->length === 0,
|
|
|
$mode . ': user shell must not load the administrator theme.');
|
|
|
$assert($xpath->query('//button[@id="panel-announcements-close" and @autofocus]')->length === 1,
|
|
|
$mode . ': drawer needs an accessible initial close control.');
|
|
|
$assert(!str_contains($html, '未读') && !str_contains($html, 'new-announcement-dot'),
|
|
|
$mode . ': do not fabricate unread state.');
|
|
|
}
|
|
|
$smarty->assign('user', (object) ['user_name' => '<img src=x onerror=alert(1)>']);
|
|
|
$unsafeHtml = $smarty->fetch('user/panel_topbar.tpl');
|
|
|
$assert($parse($unsafeHtml)->query('//*[@onerror]')->length === 0, 'The shared topbar must retain username escaping.');
|
|
|
$invite = file_get_contents(dirname(__DIR__) . '/resources/views/venix/user/invite.tpl');
|
|
|
$assert(!str_contains($invite, '/user/announcement') && str_contains($invite, 'data-announcements-open'),
|
|
|
'Invite rules must use the drawer instead of the removed page.');
|
|
|
$script = file_get_contents(dirname(__DIR__) . '/public/cloud/announcements.js');
|
|
|
$assert(!str_contains($script, '.innerHTML') && !str_contains($script, 'insertAdjacentHTML')
|
|
|
&& str_contains($script, 'node.textContent = String(value)'), 'Announcement title and body must be plain text.');
|
|
|
$assert(str_contains($script, '/api/v1/announcements?page=') && !str_contains($script, '/session')
|
|
|
&& !str_contains($script, 'from \'./runtime.js\''), 'Announcements must not depend on a VM session.');
|
|
|
$assert(str_contains($script, "item.status !== 'published'") && str_contains($script, 'visibilitychange'),
|
|
|
'Visible drawers must revalidate published content without background polling when hidden.');
|
|
|
$assert(str_contains($script, "void load(1, state.pagination ? 'auto' : 'initial');"),
|
|
|
'Every drawer open must immediately revalidate existing content without displaying progress.');
|
|
|
foreach (['旧内容', '正在刷新', '正在读取最新公告', '正在加载更多公告'] as $retiredMessage) {
|
|
|
$assert(!str_contains($script, $retiredMessage), 'Retired announcement status message remains: ' . $retiredMessage);
|
|
|
}
|
|
|
$css = file_get_contents(dirname(__DIR__) . '/public/cloud/client.css');
|
|
|
$assert(preg_match('/\.panel-announcements-trigger\.button \{[^}]*width: 30px;[^}]*height: 30px;[^}]*background: transparent;/', $css) === 1,
|
|
|
'The topbar announcement trigger must match the 30px avatar without a large button background.');
|
|
|
$assert(preg_match('/\.panel-announcements-close\.button \{[^}]*width: 44px;[^}]*height: 44px;/', $css) === 1,
|
|
|
'The drawer close control must retain its 44px touch size.');
|
|
|
echo "User announcement shared shell, silent drawer, plain-text contract and retired navigation checks passed.\n";
|