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.
102 lines
3.2 KiB
PHP
102 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\UserCopy\UserCopyManifest;
|
|
|
|
$root = dirname(__DIR__);
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
$read = static function (string $path) use ($root): string {
|
|
$source = file_get_contents($root . '/' . $path);
|
|
if (!is_string($source)) {
|
|
throw new RuntimeException('Cannot read ' . $path . '.');
|
|
}
|
|
return $source;
|
|
};
|
|
|
|
$entries = [];
|
|
foreach (UserCopyManifest::load()['entries'] as $entry) {
|
|
$entries[(string) $entry['key']] = $entry;
|
|
}
|
|
|
|
$bindings = [
|
|
'public/cloud/backups.js' => [
|
|
'backups.facts.created',
|
|
'backups.facts.consistency',
|
|
'backups.facts.object_size',
|
|
'backups.facts.disk_capacity',
|
|
'backups.action.restore',
|
|
'backups.action.view_snapshot',
|
|
'backups.action.promote',
|
|
],
|
|
'public/cloud/cloud-snapshots.js' => [
|
|
'snapshots.facts.saved',
|
|
'snapshots.facts.os',
|
|
'snapshots.facts.object_size',
|
|
'snapshots.facts.disk_capacity',
|
|
'snapshots.action.create',
|
|
'snapshots.action.delete',
|
|
],
|
|
'public/cloud/traffic.js' => [
|
|
'traffic.instances.title',
|
|
'traffic.instance.period_quota',
|
|
'traffic.instance.used',
|
|
'traffic.instance.download',
|
|
'traffic.instance.upload',
|
|
'traffic.fact.entitlement',
|
|
'traffic.fact.consumed',
|
|
'traffic.fact.available',
|
|
'traffic.fact.overage',
|
|
'traffic.fact.next_expiry',
|
|
'traffic.fact.last_observed',
|
|
],
|
|
'public/cloud/invoices.js' => [
|
|
'billing.list.detail',
|
|
'billing.list.amount',
|
|
],
|
|
'public/cloud/ssh-keys.js' => [
|
|
'ssh_keys.action.delete',
|
|
],
|
|
'public/cloud/instances.js' => [
|
|
'instances.spec.compute',
|
|
],
|
|
];
|
|
|
|
foreach ($bindings as $path => $keys) {
|
|
$source = $read($path);
|
|
$assert(str_contains($source, 'i18n.bind('),
|
|
'Dynamic copy bindings are missing from ' . $path . '.');
|
|
foreach ($keys as $key) {
|
|
$assert(isset($entries[$key]),
|
|
'Dynamic binding references an unknown copy key: ' . $key);
|
|
$assert($entries[$key]['editor_surface'] === 'page',
|
|
'Advanced copy was exposed as a dynamic page binding: ' . $key);
|
|
$assert(str_contains($source, "'" . $key . "'"),
|
|
'Dynamic page binding key is absent from ' . $path . ': ' . $key);
|
|
}
|
|
}
|
|
|
|
foreach ([
|
|
'public/cloud/task-center.js',
|
|
'public/cloud/task-observer.js',
|
|
'public/cloud/toast.js',
|
|
'public/cloud/user-dialog.js',
|
|
] as $path) {
|
|
$assert(!str_contains($read($path), 'i18n.bind('),
|
|
'Advanced task, Toast or dialog copy received a page binding: ' . $path);
|
|
}
|
|
|
|
$runtime = $read('public/cloud/user-copy-runtime.js');
|
|
$assert(str_contains($runtime, "querySelector('[data-user-copy-key]')")
|
|
&& str_contains($runtime, "node.setAttribute('data-user-copy-key', key)")
|
|
&& str_contains($runtime, 'locale, text, bind, number'),
|
|
'Browser copy runtime does not expose guarded dynamic binding.');
|
|
|
|
echo "User copy dynamic page binding contracts passed.\n";
|