isDir() ? rmdir($item->getPathname()) : unlink($item->getPathname()); } rmdir($directory); }; $runtimeRoot = sys_get_temp_dir() . '/virt-user-copy-view-' . bin2hex(random_bytes(8)); $smartyRoot = $runtimeRoot . '/smarty'; mkdir($smartyRoot, 0700, true); try { $source = new UserCopySourceCatalog(UserCopyManifest::load()); $compiled = (new UserCopyCatalogCompiler($source))->compile('en', [ // Test fixture copy is runtime publication data, never source copy. 'common.shell.user_center' => '运行时发布的账户外壳', 'common.shell.nav.instances' => '运行时发布的实例导航', 'common.toast.success.title' => '运行时发布的成功标题', 'common.toast.success.body' => '运行时发布的成功内容', 'common.toast.error.title' => '运行时发布的失败标题', 'common.toast.warning.title' => '运行时发布的警告标题', 'common.toast.close.aria' => '运行时发布的关闭标签', ]); (new UserCopyPublicationStore($runtimeRoot))->publish($compiled); $reader = new UserCopyRuntimeReader($runtimeRoot, $source); $runtime = new UserCopyViewRuntime($reader); $smarty = new Smarty(); $smarty->setCompileDir($smartyRoot); $smarty->setCacheDir($smartyRoot); $catalog = $runtime->bind( $smarty, 'en', '/user/cloud/instances?page=2', 'cloud.instances' ); $html = $smarty->fetch( 'string:' . '{user_copy key="common.shell.user_center"}|' . '{user_copy key="common.shell.nav.instances"}|' . '{$user_copy_language_zh_url}|{$user_copy_language_en_url}' . '' ); $assert(str_contains($html, 'lang="en"') && str_contains($html, '运行时发布的账户外壳') && str_contains($html, '运行时发布的实例导航'), 'Smarty did not render the active runtime publication.'); $assert(str_contains($html, 'page=2&lang=zh-CN') && str_contains($html, 'page=2&lang=en'), 'Language switching did not preserve the current query.'); $assert($catalog->generation() === $compiled->generation, 'The user view did not bind the active immutable generation.'); $variables = $smarty->getTemplateVars(); $bootstrap = json_decode( (string) ($variables['user_copy_bootstrap_json'] ?? ''), true, 512, JSON_THROW_ON_ERROR ); $assert(($bootstrap['locale'] ?? null) === 'en' && ($bootstrap['generation'] ?? null) === $compiled->generation && ($bootstrap['messages']['common.toast.success.title'] ?? null) === '运行时发布的成功标题', 'Browser bootstrap does not match the server request snapshot.'); $fallbackSmarty = new Smarty(); $fallbackSmarty->setCompileDir($smartyRoot); $fallbackSmarty->setCacheDir($smartyRoot); $fallback = $runtime->bind( $fallbackSmarty, 'fr', '/user/ticket', null ); $assert($fallback->generation() === null && $fallback->text('common.shell.user_center') === '用户中心', 'An unpublished locale did not fall back to source copy.'); } finally { $removeTree($runtimeRoot); } echo "User copy locale, Smarty and browser-bootstrap runtime checks passed.\n";