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.
87 lines
4.8 KiB
PHP
87 lines
4.8 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__, 2);
|
|
$read = static function (string $path) use ($root): string {
|
|
$content = file_get_contents($root . '/' . $path);
|
|
if ($content === false) {
|
|
throw new RuntimeException('Cannot read ' . $path);
|
|
}
|
|
return $content;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$locale = $read('web/app/Services/PublicLocale.php');
|
|
$base = $read('web/app/Controllers/BaseController.php');
|
|
$home = $read('web/app/Controllers/HomeController.php');
|
|
$auth = $read('web/app/Controllers/AuthController.php');
|
|
$password = $read('web/app/Controllers/PasswordController.php');
|
|
$legal = $read('web/app/Controllers/LegalController.php');
|
|
|
|
$assert(str_contains($locale, "COOKIE_NAME = 'venix_public_locale'")
|
|
&& str_contains($locale, 'HTTP_ACCEPT_LANGUAGE') === false
|
|
&& str_contains($locale, 'browserLocale(')
|
|
&& str_contains($locale, "\$query['lang']"),
|
|
'The public locale resolver is missing explicit selection, cookie, or browser-language support.');
|
|
$assert(str_contains($base, 'PublicLocale::requestedLocale($query)')
|
|
&& str_contains($base, 'Cookie::set([')
|
|
&& str_contains($base, "\$_SERVER['HTTP_ACCEPT_LANGUAGE']")
|
|
&& str_contains($base, 'PublicLocale::viewData('),
|
|
'The shared controller does not persist and expose the resolved public locale.');
|
|
foreach ([$home, $auth, $password] as $controller) {
|
|
$assert(str_contains($controller, '$this->initializePublicLocale();'),
|
|
'A public-page controller does not initialize the shared locale resolver.');
|
|
$assert(str_contains($controller, '$this->publicView()'),
|
|
'A public-page controller does not expose shared locale data to its templates.');
|
|
}
|
|
$assert(str_contains($legal, '$this->publicLocale')
|
|
&& str_contains($legal, "withHeader('Vary', 'Accept-Language, Cookie')"),
|
|
'Legal pages do not use the shared locale or declare cache variance.');
|
|
foreach ([$base, $home, $auth, $password, $legal] as $controller) {
|
|
$assert(!str_contains($controller, "Configurations::where('name', 'language'")
|
|
&& !str_contains($controller, "Config::get('language'"),
|
|
'A public page still depends on the removed administrator language setting.');
|
|
}
|
|
|
|
$layoutHeader = $read('web/resources/views/venix/auth/layout_header.tpl');
|
|
$layoutFooter = $read('web/resources/views/venix/auth/layout_footer.tpl');
|
|
$siteHeader = $read('web/resources/views/venix/home/site_header.tpl');
|
|
$navActions = $read('web/resources/views/venix/home/nav_actions.tpl');
|
|
$languageSwitch = $read('web/resources/views/venix/home/language_switch.tpl');
|
|
$siteFooter = $read('web/resources/views/venix/home/site_footer.tpl');
|
|
$css = $read('web/public/theme/venix/css/home.css');
|
|
$accountCss = $read('web/public/cloud/account.css');
|
|
|
|
$assert(str_contains($layoutHeader, "include file='home/site_header.tpl'")
|
|
&& str_contains($layoutHeader, 'theme/venix/css/home.css'),
|
|
'Authentication pages do not reuse the landing-page header and its stylesheet.');
|
|
$assert(str_contains($layoutFooter, "include file='home/site_footer.tpl'"),
|
|
'Authentication pages do not reuse the landing-page footer.');
|
|
foreach (['auth/login.tpl', 'auth/register.tpl', 'password/reset.tpl', 'password/token.tpl'] as $templatePath) {
|
|
$template = $read('web/resources/views/venix/' . $templatePath);
|
|
$assert(str_contains($template, "include file='auth/layout_footer.tpl'"),
|
|
$templatePath . ' does not include the persistent public footer.');
|
|
$assert(!str_contains($template, "include file='auth/copyright.tpl'"),
|
|
$templatePath . ' still includes the retired local copyright fragment.');
|
|
}
|
|
$assert(str_contains($siteHeader, "include file='home/nav_actions.tpl'")
|
|
&& str_contains($navActions, "include file='home/language_switch.tpl'")
|
|
&& str_contains($languageSwitch, '$language_zh_url')
|
|
&& str_contains($languageSwitch, '$language_en_url'),
|
|
'The shared navigation does not expose both language switch targets.');
|
|
$assert(!str_contains($siteHeader, '?lang=en') && !str_contains($siteFooter, '?lang=en'),
|
|
'Public navigation still hard-codes English query parameters instead of using the locale cookie.');
|
|
$assert(preg_match('/\.landing-site-header\s*\{[^}]*position:\s*fixed;/s', $css) === 1
|
|
&& str_contains($css, '.landing-language-switch')
|
|
&& str_contains($css, '.landing-mobile-nav-actions')
|
|
&& str_contains($accountCss, 'padding-top: 88px;')
|
|
&& str_contains($accountCss, 'padding-top: 76px;'),
|
|
'Persistent desktop or mobile public-navigation styling is incomplete.');
|
|
$assert(str_contains($read('web/resources/views/venix/layout_assets.tpl'), "value='2026102503'"),
|
|
'The shared browser asset version was not advanced with the navigation styles.');
|
|
|
|
echo "Public page locale and shared-layout contract tests passed.\n";
|