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.
83 lines
3.9 KiB
PHP
83 lines
3.9 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $relative) use ($root): string {
|
|
$contents = file_get_contents($root . '/' . $relative);
|
|
if (!is_string($contents)) {
|
|
throw new RuntimeException('Cannot read ' . $relative);
|
|
}
|
|
return $contents;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$runtime = $read('app/Services/UserCopy/UserCopyViewRuntime.php');
|
|
$bootstrap = $read('resources/views/venix/user/user_copy_bootstrap.tpl');
|
|
$head = $read('resources/views/venix/user/user_copy_editor_head.tpl');
|
|
$javascript = $read('public/cloud/admin-user-copy-page-editor.js');
|
|
$stylesheet = $read('public/cloud/admin-user-copy-page-editor.css');
|
|
|
|
$assert(str_contains($runtime, "'user_copy_editor_enabled' => \$editorEnabled")
|
|
&& str_contains($runtime, "'page' => \$pageKey")
|
|
&& str_contains($runtime, "'runtime_locale' => \$catalog->locale()")
|
|
&& str_contains($runtime, "'csrf_token' => \$csrfToken")
|
|
&& str_contains($runtime, "preg_match('/\\A[a-f0-9]{64}\\z/D'"),
|
|
'The page-editor capability is not constrained by page, locale and CSRF state.');
|
|
|
|
$layouts = [
|
|
'resources/views/venix/cloud/page.tpl',
|
|
'resources/views/venix/user/layout_header.tpl',
|
|
'resources/views/venix/user/layout_plain_header.tpl',
|
|
'resources/views/venix/home/layout_header.tpl',
|
|
'resources/views/venix/auth/layout_header.tpl',
|
|
];
|
|
foreach ($layouts as $layout) {
|
|
$contents = $read($layout);
|
|
$assert(substr_count($contents,
|
|
"{include file='user/user_copy_editor_head.tpl'}") === 1,
|
|
$layout . ' does not load the conditional editor stylesheet once.');
|
|
}
|
|
|
|
$assert(str_contains($head, '{if $user_copy_editor_enabled|default:false}')
|
|
&& str_contains($head, '/cloud/admin-user-copy-page-editor.css')
|
|
&& str_contains($bootstrap, '{if $user_copy_editor_enabled|default:false}')
|
|
&& substr_count($bootstrap, '/cloud/admin-request-runtime.js') === 1
|
|
&& substr_count($bootstrap, '/cloud/admin-user-copy-page-editor.js') === 1
|
|
&& substr_count($bootstrap, 'user-copy-editor-bootstrap') === 1,
|
|
'Editor assets are not isolated behind the server-side authoring capability.');
|
|
|
|
$assert(str_contains($javascript, "query.set('channel', 'page')")
|
|
&& str_contains($javascript, "query.set('page', bootstrap.page)")
|
|
&& str_contains($javascript, "document.querySelectorAll('[data-user-copy-key]')")
|
|
&& str_contains($javascript, "state.bindings.has(String(entry.key || ''))")
|
|
&& str_contains($javascript, "'/admin/user-copy/entries/'")
|
|
&& str_contains($javascript, "+ '/draft'")
|
|
&& str_contains($javascript, "method: 'PUT'")
|
|
&& str_contains($javascript, 'draft_version:')
|
|
&& str_contains($javascript, 'hidden: false')
|
|
&& substr_count($javascript, 'transport.mutate(') === 1,
|
|
'The page editor does not use the constrained page workspace and draft-only mutation.');
|
|
|
|
foreach (['synchronize', 'publications', 'rollback', 'contenteditable'] as $forbidden) {
|
|
$assert(!str_contains(strtolower($javascript), $forbidden),
|
|
'The page editor exposes forbidden capability: ' . $forbidden);
|
|
}
|
|
foreach (['409', '419', '422', '403', 'mutationMayHaveApplied'] as $required) {
|
|
$assert(str_contains($javascript, $required),
|
|
'The page editor does not explicitly handle ' . $required . '.');
|
|
}
|
|
|
|
$assert(str_contains($javascript, 'scrollIntoView')
|
|
&& str_contains($javascript, "event.key === 'Escape'")
|
|
&& str_contains($javascript, "event.key !== 'Tab'")
|
|
&& str_contains($stylesheet, '.is-user-copy-page-highlight')
|
|
&& str_contains($stylesheet, 'outline: 3px solid')
|
|
&& str_contains($stylesheet, '@media (max-width: 640px)')
|
|
&& str_contains($stylesheet, 'width: 100%;'),
|
|
'The editor lacks non-layout highlighting, focus handling or mobile full width.');
|
|
|
|
echo "User-copy page editor capability and draft-only contracts passed.\n";
|