refactor(admin): remove download config settings page and chain
- Drop the download config menu entry, route and schema from the settings SPA - Remove the PHP schema section, the server-side alias validation and the reserved-alias list that only served that section - Unregister aksrt_download_config from standalone import/export keys - Drop the contract tests that locked the removed page; the Download.php runtime contracts stay untouched
This commit is contained in:
@@ -8,60 +8,6 @@ const test = require('node:test');
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
|
||||
test('download settings section exists on both schema sides with matching defaults', () => {
|
||||
const php = read('src/Admin/Schema/SchemaPermissions.php');
|
||||
const vue = read('assets/admin/src/schema/sections/permissions/index.js');
|
||||
|
||||
// PHP side is the authoritative contract.
|
||||
assert.match(php, /'download' => \[/);
|
||||
assert.match(php, /'key'\s+=> 'download'/);
|
||||
assert.match(php, /'option_key' => 'aksrt_download_config'/);
|
||||
|
||||
// Field parity: same four keys with the same defaults on both ends.
|
||||
const fields = [
|
||||
['enabled', 'true', 'enabled: true'],
|
||||
['url_alias', "'download'", "url_alias: 'download'"],
|
||||
['default_max_uses', '1', 'default_max_uses: 1'],
|
||||
['ttl_minutes', '10', 'ttl_minutes: 10'],
|
||||
];
|
||||
for (const [key, phpDefault, vueDefault] of fields) {
|
||||
const phpField = new RegExp(`'key' => '${key}'[^\\]]*'default' => ${phpDefault}`);
|
||||
assert.match(php, phpField, `PHP default mismatch for ${key}`);
|
||||
assert.match(vue, new RegExp(`${vueDefault}`), `Vue default mismatch for ${key}`);
|
||||
}
|
||||
|
||||
// The link rules depend on the master switch on both ends.
|
||||
assert.match(php, /'title' => '下载总开关'/);
|
||||
assert.match(php, /'dependsOn' => \['key' => 'enabled', 'value' => true\]/);
|
||||
assert.match(vue, /dependsOn: \{ key: 'enabled', value: true \}/);
|
||||
|
||||
// Vue mirrors labels so admins see the same wording as validation errors.
|
||||
assert.match(vue, /download: \{/);
|
||||
assert.match(vue, /下载链接 URL 别名/);
|
||||
assert.match(vue, /下载链接默认使用次数/);
|
||||
assert.match(vue, /下载链接默认有效期限(分钟)/);
|
||||
});
|
||||
|
||||
test('the download settings page is registered under the permissions menu', () => {
|
||||
const menu = read('assets/admin/src/constants/sections/permissions.js');
|
||||
assert.match(menu, /schemaPage\(\{\s*key: 'permissions-download'/);
|
||||
assert.match(menu, /route: '\/permissions\/download'/);
|
||||
assert.match(menu, /canonicalDomain: 'permissions',\s*section: 'download',/);
|
||||
|
||||
const settings = read('src/Settings/Settings.php');
|
||||
assert.match(settings, /'aksrt_download_config'/);
|
||||
});
|
||||
|
||||
test('invalid url aliases are rejected server-side with admin-facing messages', () => {
|
||||
const provider = read('src/Admin/SchemaProvider.php');
|
||||
assert.match(provider, /\$domain === 'permissions' && \$section === 'download'/);
|
||||
assert.match(provider, /URL 别名不能为空/);
|
||||
assert.match(provider, /\/\^\[A-Za-z0-9_-\]\+\$\//);
|
||||
assert.match(provider, /禁止中文、空格和 \/ \\\\ \? # & 等特殊符号/);
|
||||
assert.match(provider, /reserved_download_aliases/);
|
||||
assert.match(provider, /'wp-json', 'wp-admin', 'wp-content', 'wp-includes'/);
|
||||
});
|
||||
|
||||
test('Download.php derives endpoint, ttl and max uses from configuration', () => {
|
||||
const dl = read('src/Content/Download.php');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user