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/CloudMaintenanceNoticeAdmin...

57 lines
2.8 KiB
PHP

<?php
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$source = file_get_contents($root . '/' . $path);
if (!is_string($source)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $source;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$routes = $read('config/routes.php');
$controller = $read('app/Controllers/Admin/CloudPageController.php');
$service = $read('app/Services/Cloud/CloudMaintenanceNoticeService.php');
$template = $read('resources/views/venix/admin/cloud/maintenance_notices.tpl');
$sidebar = $read('resources/views/venix/admin/static_header.tpl');
$script = $read('public/cloud/admin-maintenance-notices.js');
$assert(str_contains($routes,
"'/maintenance-notices',\n 'App\\Controllers\\Admin\\CloudPageController:maintenanceNotices'")
&& str_contains($controller, 'public function maintenanceNotices(')
&& str_contains($controller, "'private, no-store'")
&& str_contains($controller, 'JSON_HEX_TAG | JSON_HEX_AMP')
&& str_contains($controller, "'can_manage' => (bool)"),
'The administrator page route lost authorization or private bootstrap boundaries.');
$assert(str_contains($service, 'public function catalog(): array')
&& str_contains($service, 'public function prefill(')
&& str_contains($service, "hash_equals((string) \$pool['pool_key'], \$poolKey)")
&& str_contains($service, "'state' => (string) \$pool->state"),
'Audience shortcuts must resolve through the full server-owned catalog.');
$assert(str_contains($template, 'data-admin-maintenance-notices')
&& str_contains($template, 'data-can-manage=')
&& str_contains($template, '<fieldset {if !$admin_can_manage|default:false}disabled{/if}>')
&& str_contains($template, 'admin-maintenance-notice-bootstrap')
&& str_contains($template, ' nofilter}</script>')
&& str_contains($template,
'/cloud/admin-maintenance-notices.js?v={$venix_asset_version}')
&& str_contains($sidebar, 'href="/admin/maintenance-notices"'),
'Maintenance notice page or navigation contracts are incomplete.');
$assert(str_contains($script, 'window.VenixAdminRequestRuntime.create')
&& str_contains($script, 'window.VenixAdminDangerDialog.confirm')
&& str_contains($script, 'mutationMayHaveApplied')
&& str_contains($script, 'state.mutationLocked = true')
&& str_contains($script, 'audience_digest: state.preview.audience_digest')
&& str_contains($script, 'textContent')
&& !str_contains($script, 'window.confirm')
&& !str_contains($script, 'innerHTML')
&& !preg_match('/\bfetch\s*\(/', $script),
'Browser actions must use the shared runtime and safe DOM rendering.');
echo "Maintenance notice administrator page contracts passed.\n";