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.
110 lines
5.2 KiB
PHP
110 lines
5.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $path) use ($root): string {
|
|
$contents = file_get_contents($root . '/' . $path);
|
|
if (!is_string($contents)) {
|
|
throw new RuntimeException('Cannot read ' . $path);
|
|
}
|
|
return $contents;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$routes = $read('config/routes.php');
|
|
$controller = $read('app/Controllers/Admin/UserCopyController.php');
|
|
$service = $read('app/Services/UserCopy/UserCopyAdminService.php');
|
|
$template = $read('resources/views/venix/admin/user_copy.tpl');
|
|
$sidebar = $read('resources/views/venix/admin/static_header.tpl');
|
|
$javascript = $read('public/cloud/admin-user-copy.js');
|
|
$css = $read('public/cloud/admin-user-copy.css');
|
|
$manifest = $read('resources/user-copy/manifest.php');
|
|
|
|
$assert(str_contains($routes,
|
|
"'/user-copy',\n 'App\\Controllers\\Admin\\UserCopyController:index'"),
|
|
'Administrator user-copy page route is missing.');
|
|
foreach (['index', 'entries', 'history', 'synchronize', 'draft', 'publish', 'rollback'] as $action) {
|
|
$pattern = "#UserCopyController:{$action}'\)\s*->add\(new SuperAdmin\(\)\)#";
|
|
$assert(preg_match($pattern, $routes) === 1,
|
|
'User-copy route is not protected by SuperAdmin: ' . $action);
|
|
}
|
|
|
|
$assert(str_contains($controller, 'UserCopyAdminService::fromApplication()')
|
|
&& str_contains($controller, 'AdminPermission::isSuperAdmin()')
|
|
&& str_contains($controller, "'private, no-store'"),
|
|
'Controller lost its service seam, write guard or private caching contract.');
|
|
$assert(!str_contains($controller, 'UserCopyPublicationStore')
|
|
&& !str_contains($controller, 'Capsule::')
|
|
&& !str_contains($controller, 'DB::'),
|
|
'Administrator controller bypasses the UserCopyAdminService seam.');
|
|
|
|
foreach (['workspace', 'history', 'saveDraft', 'publish', 'rollback'] as $method) {
|
|
$assert(str_contains($service, 'function ' . $method . '('),
|
|
'UserCopyAdminService contract is missing: ' . $method);
|
|
}
|
|
$assert(str_contains($service, 'function synchronize('),
|
|
'UserCopyAdminService cannot synchronize source Manifest changes.');
|
|
$assert(!str_contains($manifest, "'translations' =>")
|
|
&& !str_contains($manifest, "'target' =>")
|
|
&& str_contains($manifest, 'target-locale translation are maintained by')
|
|
&& str_contains($manifest, 'must never be committed to this source manifest'),
|
|
'Target-locale translations were stored in the source manifest.');
|
|
|
|
$assert(str_contains($sidebar, 'href="/admin/user-copy"')
|
|
&& str_contains($sidebar, '用户界面译文'),
|
|
'Administrator navigation does not expose user-copy management.');
|
|
foreach ([
|
|
'id="user-copy-page"',
|
|
'id="user-copy-locale"',
|
|
'id="user-copy-progress-bar"',
|
|
'发布历史',
|
|
'id="user-copy-toast-only"',
|
|
'id="user-copy-synchronize"',
|
|
'sandbox=""',
|
|
] as $contract) {
|
|
$assert(str_contains($template, $contract),
|
|
'Administrator user-copy template is missing: ' . $contract);
|
|
}
|
|
$assert(str_contains($template . $javascript, '中文源文案(只读)')
|
|
&& str_contains($template . $javascript, '目标语言草稿'),
|
|
'Source copy is not read-only or target drafts are missing.');
|
|
$assert(str_contains($template, 'data-can-manage=')
|
|
&& str_contains($template, 'write_block_reason'),
|
|
'The template does not expose read-only or unavailable-write state.');
|
|
|
|
$assert(str_contains($javascript, 'function previewEntry(')
|
|
&& str_contains($javascript, 'previewFrame.srcdoc = previewDocument(')
|
|
&& str_contains($javascript, "entry.kind === 'toast_title'")
|
|
&& str_contains($javascript, "entry.kind === 'toast_body'"),
|
|
'Local safe preview or Toast preview/filtering is missing.');
|
|
$previewStart = strpos($javascript, 'function previewEntry(');
|
|
$previewEnd = strpos($javascript, 'function closeDrawers(', $previewStart);
|
|
$previewBody = substr($javascript, $previewStart, $previewEnd - $previewStart);
|
|
$assert(!str_contains($previewBody, 'transport.')
|
|
&& !str_contains($previewBody, 'fetch('),
|
|
'Safe preview performs a network operation.');
|
|
foreach (['/api/v1/vms', '/api/v1/orders', '/api/v1/invoices'] as $businessPath) {
|
|
$assert(!str_contains($javascript, $businessPath),
|
|
'Translation management references a business mutation endpoint.');
|
|
}
|
|
$assert(str_contains($javascript, "'/admin/user-copy/entries/'")
|
|
&& str_contains($javascript, "'/admin/user-copy/synchronize'")
|
|
&& str_contains($javascript, "'/admin/user-copy/publications'")
|
|
&& str_contains($javascript, "'/admin/user-copy/publications/'")
|
|
&& str_contains($javascript, 'mutationMayHaveApplied'),
|
|
'Draft, publish, rollback or uncertain mutation handling is incomplete.');
|
|
$assert(str_contains($javascript, 'validation_state')
|
|
&& str_contains($javascript, 'user-copy-validation-error')
|
|
&& str_contains($javascript, '存在无效或过期草稿'),
|
|
'Invalid or stale drafts are not visible before locale publication.');
|
|
$assert(str_contains($css, '@media (max-width: 575.98px)')
|
|
&& str_contains($css, '.user-copy-entry-columns'),
|
|
'Administrator user-copy page lacks responsive layout contracts.');
|
|
|
|
echo "User copy administrator UI contracts passed.\n";
|