修复了一些问题

This commit is contained in:
kate522 committed 2026-08-25 18:11:26 +08:00
1 parent dbb1f776f2
commit 0109a59922
10 files changed
+121 -33

No files matched your search

@@ -1,32 +1,50 @@
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const test = require('node:test');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
test('message center exposes only the four canonical parameter-free routes', () => {
test('message center exposes only the four configured-alias parameter-free routes', () => {
const routing = read('inc/modules/user-parts/routing.php');
const urls = read('inc/modules/user-parts/urls.php');
const registry = read('inc/modules/user-parts/template-registry.php');
assert.match(routing, /add_rewrite_rule\('\^message\/\?\$',[\s\S]*?aksrt_message_view=unread/);
assert.match(routing, /add_rewrite_rule\('\^message\/\(posts\|like\|system\)\/\?\$'/);
assert.match(urls, /function aksrt_get_messages_rewrite_slug[\s\S]*?Settings::notification_settings\(\)[\s\S]*?\['slug'\]/);
assert.match(routing, /\$message_slug = preg_quote\(aksrt_get_messages_rewrite_slug\(\), '#'\)/);
assert.match(routing, /add_rewrite_rule\('\^' \. \$message_slug \. '\/\?\$',[\s\S]*?aksrt_message_view=unread/);
assert.match(routing, /add_rewrite_rule\('\^' \. \$message_slug \. '\/\(posts\|like\|system\)\/\?\$'/);
assert.match(routing, /message-routing:' \. aksrt_get_messages_rewrite_slug\(\)/);
assert.doesNotMatch(routing, /add_rewrite_rule\('\^message/);
assert.doesNotMatch(routing, /message\/\(\[0-9]|aksrt_message_id/);
for (const route of ['/message/', '/message/posts/', '/message/like/', '/message/system/']) {
assert.ok(urls.includes(route), `${route} should be canonical`);
}
const messageUrlFunction = urls.slice(
urls.indexOf('function aksrt_get_messages_page_url'),
urls.indexOf('endif;', urls.indexOf('function aksrt_get_messages_page_url')),
);
assert.doesNotMatch(messageUrlFunction, /add_query_arg|\/messages\//);
assert.match(messageUrlFunction, /aksrt_get_messages_rewrite_slug\(\)/);
assert.doesNotMatch(messageUrlFunction, /add_query_arg|\/messages\/|\/message\//);
assert.doesNotMatch(registry, /'messages'\s*=>/);
assert.match(registry, /page-messages\.php'\)\s*\{[\s\S]*?return ''/);
assert.match(routing, /get_page_template_slug[\s\S]*?page-messages\.php[\s\S]*?set_404/);
});
test('message center URL helper builds every view from the configured alias', () => {
const result = spawnSync(process.env.PHP_BINARY || 'php', [path.join(__dirname, 'message-center-url-harness.php')], {
cwd: root,
encoding: 'utf8',
});
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.deepEqual(JSON.parse(result.stdout), {
slug: 'inbox-center',
unread: 'https://example.test/inbox-center/',
posts: 'https://example.test/inbox-center/posts/',
like: 'https://example.test/inbox-center/like/',
system: 'https://example.test/inbox-center/system/',
});
});
test('tabs, pagination, actions, and detail all replace DOM fragments', () => {
const center = read('inc/modules/message-center.php');
const script = read('assets/js/messages.js');
@@ -46,6 +64,16 @@ test('tabs, pagination, actions, and detail all replace DOM fragments', () => {
assert.doesNotMatch(script, /pushState\([^\n]+detail/);
});
test('message detail does not expose a related-content button or target link', () => {
const center = read('inc/modules/message-center.php');
const detailStart = center.indexOf('function aksrt_render_message_center_detail');
const detailEnd = center.indexOf("add_action('wp_ajax_aksrt_load_message_center'", detailStart);
const detail = center.slice(detailStart, detailEnd);
assert.doesNotMatch(detail, /查看相关内容|message-detail__primary|target_url|\['url'\]/);
assert.doesNotMatch(detail, /<a\s/i);
});
test('asset notifications are absent and interaction notification hooks are present', () => {
const notifications = read('inc/modules/user-notifications.php');
const settings = read('src/Settings/Integration.php');
@@ -0,0 +1,42 @@
<?php
/**
* Lightweight message-center URL alias harness.
*/
namespace {
define('ABSPATH', __DIR__);
class AKSRT_User_Notifications {}
function sanitize_key($value): string {
return preg_replace('/[^a-z0-9_\-]/', '', strtolower((string) $value)) ?? '';
}
function home_url(string $path = ''): string {
return 'https://example.test' . $path;
}
}
namespace AKSRT\Settings {
final class Settings {
public static function notification_settings(): array {
return ['slug' => 'inbox-center'];
}
public static function message_enabled(): bool {
return true;
}
}
}
namespace {
require_once dirname(__DIR__, 2) . '/inc/modules/user-parts/urls.php';
echo json_encode([
'slug' => aksrt_get_messages_rewrite_slug(),
'unread' => aksrt_get_messages_page_url(),
'posts' => aksrt_get_messages_page_url('posts'),
'like' => aksrt_get_messages_page_url('like'),
'system' => aksrt_get_messages_page_url('system'),
], JSON_UNESCAPED_SLASHES);
}
@@ -369,6 +369,8 @@ test('save contract rejects invalid input and round-trips canonical nested value
templated_public_user_home: true,
templated_user_center: true,
home_excludes_page: false,
message_uses_other_page: true,
message_excludes_home: false,
home_excludes_public_home: false,
home_excludes_user_center: false,
})
@@ -77,6 +77,13 @@ namespace {
return array_key_exists($key, $GLOBALS['aksrt_test_options']) ? $GLOBALS['aksrt_test_options'][$key] : $default;
}
function get_query_var(string $key) {
if ($key === 'aksrt_message_view' && $GLOBALS['aksrt_visibility_query'] === 'message') {
return 'unread';
}
return '';
}
function update_option($key, $value): bool {
$GLOBALS['aksrt_test_options'][$key] = $value;
return true;
@@ -92,7 +99,7 @@ namespace {
// Custom rewrites can leave WordPress's posts-page flag set even though
// the theme resolves the request to another front-end surface.
return in_array($GLOBALS['aksrt_visibility_query'], [
'home', 'page', 'user_home', 'user_center', 'user_home_page', 'user_center_page',
'home', 'page', 'message', 'user_home', 'user_center', 'user_home_page', 'user_center_page',
], true);
}
function is_front_page(): bool { return $GLOBALS['aksrt_visibility_query'] === 'home'; }
@@ -233,6 +240,8 @@ namespace {
'templated_public_user_home' => aksrt_visibility_case('user_home_page', ['user_home']),
'templated_user_center' => aksrt_visibility_case('user_center_page', ['user_center']),
'home_excludes_page' => aksrt_visibility_case('page', ['home']),
'message_uses_other_page' => aksrt_visibility_case('message', ['page']),
'message_excludes_home' => aksrt_visibility_case('message', ['home']),
'home_excludes_public_home' => aksrt_visibility_case('user_home', ['home']),
'home_excludes_user_center' => aksrt_visibility_case('user_center', ['home']),
];