You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/AuthVisualContractTest.php

62 lines
3.4 KiB
PHTML

<?php
$root = dirname(__DIR__);
$views = $root . '/resources/views/venix';
$assert = static function ($condition, $message) {
if (!$condition) throw new RuntimeException($message);
};
$login = file_get_contents($views . '/auth/login.tpl');
$register = file_get_contents($views . '/auth/register.tpl');
$passwordReset = file_get_contents($views . '/password/reset.tpl');
$passwordToken = file_get_contents($views . '/password/token.tpl');
$layout = file_get_contents($views . '/auth/layout_header.tpl');
$layoutFooter = file_get_contents($views . '/auth/layout_footer.tpl');
$story = file_get_contents($views . '/auth/virsh_story.tpl');
$styles = file_get_contents($root . '/public/cloud/account.css');
$homeStyles = file_get_contents($root . '/public/theme/venix/css/home.css');
$assets = file_get_contents($views . '/layout_assets.tpl');
foreach ([$login, $register, $passwordReset, $passwordToken] as $template) {
$assert(str_contains($template, 'auth-shell auth-shell-virsh'),
'Authentication page is missing the virsh-cloud shell.');
$assert(str_contains($template, "include file='auth/virsh_story.tpl'"),
'Authentication page is missing the shared virsh-cloud artwork.');
$assert(str_contains($template, "include file='auth/layout_footer.tpl'"),
'Authentication page is missing the shared public footer.');
}
$assert(str_contains($layout, 'venix-auth{if isset($auth_page)} virsh-auth{/if}'),
'Authentication layout does not scope the migrated visual treatment.');
$assert(str_contains($layout, "include file='home/site_header.tpl'")
&& str_contains($layout, 'theme/venix/css/home.css'),
'Authentication pages do not reuse the persistent public header styles.');
$assert(str_contains($layoutFooter, "include file='home/site_footer.tpl'")
&& str_contains($layoutFooter, "include file='auth/layout_scripts.tpl'"),
'Authentication pages do not reuse the persistent public footer and scripts.');
$assert(str_contains($story, '{$auth_app_name|escape:"html"}')
&& !str_contains($story, 'VirtPilot'),
'Virsh-cloud artwork must use the configured site name.');
$assert(!str_contains($login, '请通过 HTTPS 安全连接')
&& !str_contains($register, '密码和验证码不会写入浏览器存储'),
'Retired authentication security hints are still present.');
$assert(str_contains($styles, 'grid-template-columns: minmax(390px, 48%) minmax(0, 1fr);')
&& str_contains($styles, '.auth-story-virsh')
&& str_contains($styles, '.virsh-auth-art-grid')
&& str_contains($styles, '@media (max-width: 740px)')
&& str_contains($styles, '.auth-story-virsh { display: none; }')
&& preg_match('/\.landing-site-header\s*\{[^}]*position:\s*fixed;/s', $homeStyles) === 1
&& str_contains($homeStyles, '.landing-site-footer'),
'Responsive virsh-cloud authentication styles are incomplete.');
$assert(str_contains($login, "VenixAuth.post('/auth/login'")
&& str_contains($register, "VenixAuth.post('/auth/register'")
&& str_contains($passwordReset, "VenixAuth.post('/password/reset'")
&& str_contains($passwordToken, "VenixAuth.post('/password/token/{\$token}'"),
'Authentication endpoints changed while migrating visual styles.');
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets, $version) === 1
&& (int) $version[1] >= 2026102414,
'Shared asset version was not advanced for the authentication stylesheet.');
echo "Auth visual contract passed.\n";