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.
109 lines
4.1 KiB
PHP
109 lines
4.1 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\PublicLocale;
|
|
|
|
final class PublicPageGuestForLocaleTest
|
|
{
|
|
public bool $isLogin = false;
|
|
|
|
public function isAdmin(): bool
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$directory = sys_get_temp_dir() . '/virt-public-locale-render-' . bin2hex(random_bytes(8));
|
|
if (!mkdir($directory, 0700)) {
|
|
throw new RuntimeException('Cannot create private public-page render directory.');
|
|
}
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$smarty = new Smarty();
|
|
$smarty->setTemplateDir(dirname(__DIR__) . '/resources/views/venix');
|
|
$smarty->setCompileDir($directory);
|
|
$smarty->setCacheDir($directory);
|
|
foreach (['urlencode', 'number_format', 'date'] as $modifier) {
|
|
$smarty->registerPlugin('modifier', $modifier, $modifier);
|
|
}
|
|
$smarty->assign([
|
|
'appName' => 'Locale Test Cloud',
|
|
'config' => [
|
|
'appName' => 'Locale Test Cloud',
|
|
'jump_delay' => 500,
|
|
],
|
|
'cdn' => '',
|
|
'backup_cdn' => '',
|
|
'seo' => '',
|
|
'user' => new PublicPageGuestForLocaleTest(),
|
|
'captch_login' => 'false',
|
|
'captch_reg' => 'false',
|
|
'captch_respass' => 'false',
|
|
'enable_invite_code' => 'false',
|
|
'enable_email_verify' => 'false',
|
|
'invite_required' => false,
|
|
'tos_reg' => 'true',
|
|
'code' => '',
|
|
'aff_code' => '',
|
|
'aff' => 0,
|
|
'aff_method' => '',
|
|
'token' => str_repeat('a', 64),
|
|
]);
|
|
|
|
$pages = [
|
|
'index.tpl' => ['Your cloud resources', '你的云资源'],
|
|
'auth/login.tpl' => ['Log in to your account', '登录账户'],
|
|
'auth/register.tpl' => ['Create your account', '注册新账户'],
|
|
'password/reset.tpl' => ['Request a password reset', '重置密码请求'],
|
|
'password/token.tpl' => ['Enter and confirm your new password.', '输入并确认你的新密码。'],
|
|
];
|
|
|
|
try {
|
|
foreach ([PublicLocale::ENGLISH, PublicLocale::CHINESE] as $locale) {
|
|
$smarty->assign(PublicLocale::viewData($locale, '/auth/register?aff=ABCDEFGH'));
|
|
$expectedFlag = $locale === PublicLocale::ENGLISH ? 0 : 1;
|
|
foreach ($pages as $template => $copy) {
|
|
$html = $smarty->fetch($template);
|
|
$assert(str_contains($html, '<html lang="' . $locale . '">'),
|
|
$template . ' rendered the wrong HTML language for ' . $locale . '.');
|
|
$assert(str_contains($html, $copy[$expectedFlag]),
|
|
$template . ' did not render its ' . $locale . ' copy.');
|
|
$assert(substr_count($html, 'class="landing-site-header"') === 1,
|
|
$template . ' did not render exactly one shared site header.');
|
|
$assert(substr_count($html, 'class="landing-site-footer"') === 1,
|
|
$template . ' did not render exactly one shared site footer.');
|
|
$assert(str_contains($html, 'lang="zh-CN" hreflang="zh-CN"')
|
|
&& str_contains($html, 'lang="en" hreflang="en"'),
|
|
$template . ' is missing one of the language switch links.');
|
|
$assert(str_contains($html, 'aff=ABCDEFGH&lang=en')
|
|
&& str_contains($html, 'aff=ABCDEFGH&lang=zh-CN'),
|
|
$template . ' did not preserve query parameters in language switch links.');
|
|
$assert(str_contains($html, '© 2026 Locale Test Cloud. All rights reserved.'),
|
|
$template . ' is missing the persistent dynamic copyright footer.');
|
|
$assert(!str_contains($html, 'auth-site-nav') && !str_contains($html, 'auth-copyright'),
|
|
$template . ' rendered a retired authentication-only header or footer.');
|
|
}
|
|
}
|
|
} finally {
|
|
$generatedFiles = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS),
|
|
RecursiveIteratorIterator::CHILD_FIRST
|
|
);
|
|
foreach ($generatedFiles as $generated) {
|
|
if ($generated->isFile()) {
|
|
unlink($generated->getPathname());
|
|
} elseif ($generated->isDir()) {
|
|
rmdir($generated->getPathname());
|
|
}
|
|
}
|
|
rmdir($directory);
|
|
}
|
|
|
|
echo "Public landing and authentication pages rendered in Chinese and English.\n";
|