|
|
|
|
<?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, "activeTab: 'page'")
|
|
|
|
|
&& str_contains($javascript, 'workspaces: {')
|
|
|
|
|
&& str_contains($javascript, 'page: null')
|
|
|
|
|
&& str_contains($javascript, 'shared: null')
|
|
|
|
|
&& str_contains($javascript, "query.set('channel', channel)")
|
|
|
|
|
&& str_contains($javascript, "query.set('page', bootstrap.page)")
|
|
|
|
|
&& str_contains($javascript, "query.set('catalog_page', String(catalogPage))")
|
|
|
|
|
&& str_contains($javascript, "query.set('per_page', '100')")
|
|
|
|
|
&& str_contains($javascript, "query.set('q', requestedQuery)")
|
|
|
|
|
&& str_contains($javascript, "document.querySelectorAll('[data-user-copy-key]')")
|
|
|
|
|
&& str_contains($javascript, "entry.editor_surface === 'page'")
|
|
|
|
|
&& str_contains($javascript, "entry.editor_surface === 'shared'")
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
"sharedGroups.has(String(entry.editor_group || ''))")
|
|
|
|
|
&& 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 constrained page/shared workspaces and draft-only mutation.');
|
|
|
|
|
$visibleEntriesStart = strpos($javascript, 'function visibleEntries()');
|
|
|
|
|
$visibleEntriesEnd = strpos(
|
|
|
|
|
$javascript,
|
|
|
|
|
'function paginationFor(',
|
|
|
|
|
$visibleEntriesStart
|
|
|
|
|
);
|
|
|
|
|
$visibleEntriesBody = substr(
|
|
|
|
|
$javascript,
|
|
|
|
|
$visibleEntriesStart,
|
|
|
|
|
$visibleEntriesEnd - $visibleEntriesStart
|
|
|
|
|
);
|
|
|
|
|
$renderEntryStart = strpos($javascript, 'function renderEntry(');
|
|
|
|
|
$renderEntryEnd = strpos($javascript, 'function renderEntries(', $renderEntryStart);
|
|
|
|
|
$renderEntryBody = substr(
|
|
|
|
|
$javascript,
|
|
|
|
|
$renderEntryStart,
|
|
|
|
|
$renderEntryEnd - $renderEntryStart
|
|
|
|
|
);
|
|
|
|
|
$assert(!str_contains(
|
|
|
|
|
$visibleEntriesBody,
|
|
|
|
|
"if (!state.bindings.has(String(entry.key || ''))) return false;"
|
|
|
|
|
)
|
|
|
|
|
&& str_contains($visibleEntriesBody, "state.activeTab === 'page'")
|
|
|
|
|
&& str_contains($visibleEntriesBody, "entry.editor_surface === 'page'")
|
|
|
|
|
&& str_contains($visibleEntriesBody, "entry.editor_surface === 'shared'")
|
|
|
|
|
&& !str_contains($visibleEntriesBody, "entry.editor_surface === 'admin'")
|
|
|
|
|
&& str_contains(
|
|
|
|
|
$visibleEntriesBody,
|
|
|
|
|
"&& state.bindings.has(String(entry.key || ''))"
|
|
|
|
|
),
|
|
|
|
|
'Unbound page copy is hidden instead of limiting DOM bindings to shared copy.');
|
|
|
|
|
$assert(str_contains(
|
|
|
|
|
$renderEntryBody,
|
|
|
|
|
"state.bindings.has(String(entry.key || ''))"
|
|
|
|
|
)
|
|
|
|
|
&& str_contains($renderEntryBody, 'if (bound)')
|
|
|
|
|
&& str_contains($renderEntryBody, 'meta.append(locateButton)')
|
|
|
|
|
&& str_contains($renderEntryBody, "textarea.addEventListener('input'")
|
|
|
|
|
&& str_contains($renderEntryBody, 'card.append(save)'),
|
|
|
|
|
'Unbound page copy cannot stay editable while omitting its locate action.');
|
|
|
|
|
$assert(!str_contains($javascript, 'if (state.bindings.size === 0) return;'),
|
|
|
|
|
'A mapped page without DOM bindings cannot open its page-copy catalog.');
|
|
|
|
|
$assert(str_contains($javascript, 'reads: {')
|
|
|
|
|
&& str_contains($javascript, 'new AbortController()')
|
|
|
|
|
&& str_contains($javascript, '{ signal: controller.signal }')
|
|
|
|
|
&& str_contains($javascript, 'read.serial !== serial')
|
|
|
|
|
&& str_contains($javascript, 'read.controller !== controller')
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
"requestedQuery !== String(state.query || '').trim()")
|
|
|
|
|
&& str_contains($javascript, 'function abortAllReads()')
|
|
|
|
|
&& str_contains($javascript, 'abortAllReads();')
|
|
|
|
|
&& str_contains($javascript, "error.name === 'AbortError'")
|
|
|
|
|
&& str_contains($javascript, "error.code === 'cancelled'"),
|
|
|
|
|
'Page-editor reads are not protected from stale or cancelled responses.');
|
|
|
|
|
$assert(str_contains($javascript, 'function mergeEntries(')
|
|
|
|
|
&& str_contains($javascript, "loadMore.addEventListener('click'")
|
|
|
|
|
&& str_contains($javascript, '{ append: true }')
|
|
|
|
|
&& str_contains($javascript, 'pagination.has_more === true')
|
|
|
|
|
&& str_contains($javascript, "list.setAttribute('aria-busy', 'true')")
|
|
|
|
|
&& str_contains($javascript, 'merged.set(String(entry.key')
|
|
|
|
|
&& str_contains($stylesheet, '.user-copy-page-editor-catalog-footer'),
|
|
|
|
|
'Page-editor pagination or de-duplicated load-more behavior is missing.');
|
|
|
|
|
$assert(str_contains($javascript, 'state.searchTimer = setTimeout(')
|
|
|
|
|
&& str_contains($javascript, '}, 250);')
|
|
|
|
|
&& str_contains($javascript, 'abortRead(state.activeTab)')
|
|
|
|
|
&& str_contains($javascript, 'workspace.catalog_query')
|
|
|
|
|
&& !str_contains($javascript, "var query = state.query.trim().toLowerCase()"),
|
|
|
|
|
'Page-editor search is not debounced and delegated to the complete server catalog.');
|
|
|
|
|
$assert(str_contains($javascript, "new Set(['common.shared'])")
|
|
|
|
|
&& str_contains($javascript, '/^(cloud|user)\\./')
|
|
|
|
|
&& str_contains($javascript, "groups.add('shell.user')")
|
|
|
|
|
&& str_contains($javascript, '/^(auth|legal|public)\\./')
|
|
|
|
|
&& str_contains($javascript, "groups.add('shell.public')"),
|
|
|
|
|
'The page editor does not select the appropriate shared shell groups.');
|
|
|
|
|
$assert(str_contains($javascript, "tabs.setAttribute('role', 'tablist')")
|
|
|
|
|
&& substr_count($javascript, "setAttribute('role', 'tab')") === 2
|
|
|
|
|
&& str_contains($javascript, "list.setAttribute('role', 'tabpanel')")
|
|
|
|
|
&& str_contains($javascript, "setAttribute('aria-selected'")
|
|
|
|
|
&& str_contains($javascript, '当前页面正文')
|
|
|
|
|
&& str_contains($javascript, '公共框架'),
|
|
|
|
|
'The page editor does not expose an accessible page/shared tab interface.');
|
|
|
|
|
$assert(str_contains($javascript,
|
|
|
|
|
'function applyWorkspace(channel, workspace, append, query)')
|
|
|
|
|
&& str_contains($javascript, 'workspace.authoring.channel !== channel')
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
'workspace.selected.page !== bootstrap.page')
|
|
|
|
|
&& str_contains($javascript, 'state.workspaces[channel] = workspace')
|
|
|
|
|
&& str_contains($javascript, 'if (channel !== state.activeTab) return;')
|
|
|
|
|
&& substr_count(
|
|
|
|
|
$javascript,
|
|
|
|
|
'loadWorkspace(state.activeTab, state.locale)'
|
|
|
|
|
) >= 3,
|
|
|
|
|
'Inactive-tab responses can render directly or active-tab refresh was lost.');
|
|
|
|
|
$assert(str_contains($javascript, 'draftBuffer: new Map()')
|
|
|
|
|
&& str_contains($javascript, 'dirtyKeys: new Set()')
|
|
|
|
|
&& str_contains($javascript, 'function bufferKey(locale, copyKey)')
|
|
|
|
|
&& str_contains($javascript, 'var buffered = draftFor(entry, state.locale)')
|
|
|
|
|
&& str_contains($javascript, 'textarea.value = buffered.text')
|
|
|
|
|
&& str_contains($javascript, "textarea.addEventListener('input'")
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
'rememberDraft(entry, state.locale, textarea.value)'),
|
|
|
|
|
'Page-editor inputs are not buffered across tab or search redraws.');
|
|
|
|
|
$saveStart = strpos($javascript, 'async function saveDraft(');
|
|
|
|
|
$saveEnd = strpos($javascript, 'function openEditor(', $saveStart);
|
|
|
|
|
$saveBody = substr($javascript, $saveStart, $saveEnd - $saveStart);
|
|
|
|
|
$assert(str_contains($saveBody, 'var locale = state.locale')
|
|
|
|
|
&& substr_count($saveBody, 'clearBufferedDraft(locale, entry.key)') === 1
|
|
|
|
|
&& strpos($saveBody, 'clearBufferedDraft(locale, entry.key)')
|
|
|
|
|
> strpos($saveBody, 'await transport.mutate(')
|
|
|
|
|
&& strpos($saveBody, 'clearBufferedDraft(locale, entry.key)')
|
|
|
|
|
< strpos($saveBody, '} catch (error)'),
|
|
|
|
|
'The page editor clears buffered input before confirmation or on failure.');
|
|
|
|
|
$assert(str_contains($javascript, 'state.dirtyKeys.size > 0')
|
|
|
|
|
&& str_contains($javascript, 'discardAllDrafts()')
|
|
|
|
|
&& str_contains($javascript, 'hasDirtyLocale(previousLocale)')
|
|
|
|
|
&& str_contains($javascript, 'discardLocaleDrafts(previousLocale)')
|
|
|
|
|
&& str_contains($javascript, 'localeSelect.value = previousLocale')
|
|
|
|
|
&& str_contains($javascript, "window.addEventListener('beforeunload'")
|
|
|
|
|
&& str_contains($javascript, 'event.returnValue =')
|
|
|
|
|
&& str_contains($javascript, '存在未保存输入,关闭编辑器后将丢弃这些输入。')
|
|
|
|
|
&& str_contains($javascript, '当前语言存在未保存输入,切换后将丢弃这些输入。'),
|
|
|
|
|
'Page-editor dirty input is not guarded before close or locale changes.');
|
|
|
|
|
$assert(str_contains($javascript,
|
|
|
|
|
"locale: bootstrap.runtime_locale === 'zh-CN'")
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
"? '' : String(bootstrap.runtime_locale || '')")
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
"if (requestedLocale && requestedLocale !== 'zh-CN')"),
|
|
|
|
|
'The first page-editor locale does not follow the non-Chinese runtime locale.');
|
|
|
|
|
$assert(str_contains($saveBody,
|
|
|
|
|
"if (!saved || typeof saved.version !== 'number')")
|
|
|
|
|
&& str_contains($saveBody,
|
|
|
|
|
'草稿可能已保存,但响应协议无效,请刷新页面核对;请勿重复提交。')
|
|
|
|
|
&& str_contains($saveBody, 'entry.draft = saved')
|
|
|
|
|
&& str_contains($saveBody, 'entry.draft_version = saved.version')
|
|
|
|
|
&& substr_count(
|
|
|
|
|
$saveBody,
|
|
|
|
|
'loadWorkspace(state.activeTab, state.locale)'
|
|
|
|
|
) === 1,
|
|
|
|
|
'A confirmed draft save resets pagination or accepts an invalid receipt.');
|
|
|
|
|
$assert(str_contains($javascript,
|
|
|
|
|
"saved = result && result.entry ? result.entry : null")
|
|
|
|
|
&& str_contains($javascript,
|
|
|
|
|
"saved.validation_state !== 'valid'")
|
|
|
|
|
&& str_contains($javascript, '草稿已保存,但校验未通过'),
|
|
|
|
|
'A persisted invalid ICU or parameter draft is presented as successful.');
|
|
|
|
|
|
|
|
|
|
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, '.user-copy-page-editor-tabs')
|
|
|
|
|
&& str_contains($stylesheet,
|
|
|
|
|
'grid-template-columns: repeat(2, minmax(0, 1fr))')
|
|
|
|
|
&& str_contains($stylesheet, 'button[aria-selected="true"]')
|
|
|
|
|
&& 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";
|