feat(extensions): align Baidu push with reference theme
与参考主题(zibll)1:1 对齐百度推送,并清掉存量双路与死代码: - 新增普通/快速收录通道开关,快速收录走 &type=daily;自动推送 JS 与参考实现一致 - 分类法 saved_term 推送(可推送类型推导公开分类法,排除 post_format,aksrt_baidu_push_taxonomies 可过滤) - 推送结果写入 meta 去重,成功后不重复提交;编辑页 Metabox 展示结果并提供「重新提交」(nonce 校验后强制推送) - 配置面收敛到扩展页单一 canonical 键:删除 SEO 页 seo_baidu_* 重复面与两处合并逻辑,不写迁移兜底 - 清理死代码:push_batch(零调用)及 batch_size、从不写入的 baidu_push_verified、零消费的熊掌号 xzh_* 七键;baidu_push_log_enabled 接入 log() 新增 PHP harness 驱动真实逻辑(通道/去重/重试/重新提交/术语/面板渲染)+ 参考主题契约测试;tests/admin 与 tests/widget-system 全量通过。
This commit is contained in:
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* Baidu push harness.
|
||||
*
|
||||
* Drives the REAL SearchPush / SearchPushMetaBox against WP stubs so the
|
||||
* reference-parity contract is covered end to end:
|
||||
* - normal / daily channels hit data.zz.baidu.com (daily appends type=daily);
|
||||
* - successful pushes are recorded in meta and never re-submitted;
|
||||
* - failed pushes retry on update when baidu_push_on_update is on;
|
||||
* - the 「重新提交」checkbox forces a push only with a valid metabox nonce;
|
||||
* - terms push via saved_term (post_format and other taxonomies excluded);
|
||||
* - the edit panel renders status lines, update time and the resubmit checkbox.
|
||||
*
|
||||
* Usage: php baidu-push-harness.php -> prints "Baidu push harness passed".
|
||||
*/
|
||||
|
||||
namespace {
|
||||
define('ABSPATH', __DIR__ . '/');
|
||||
define('WP_DEBUG', false);
|
||||
|
||||
final class WP_Error {
|
||||
public function __construct(private string $code, private string $message) {}
|
||||
public function get_error_message(): string { return $this->message; }
|
||||
}
|
||||
|
||||
final class WP_Post {
|
||||
public int $ID = 0;
|
||||
public string $post_type = 'post';
|
||||
public string $post_status = 'publish';
|
||||
}
|
||||
|
||||
final class WP_Term {
|
||||
public int $term_id = 0;
|
||||
public string $taxonomy = 'category';
|
||||
}
|
||||
|
||||
// ---------- WP function stubs ----------
|
||||
function add_action(...$args) {}
|
||||
function apply_filters($tag, $value) { return $value; }
|
||||
function __($s, $d = null) { return (string) $s; }
|
||||
function esc_html($s) { return htmlspecialchars((string) $s, ENT_QUOTES); }
|
||||
function esc_attr($s) { return htmlspecialchars((string) $s, ENT_QUOTES); }
|
||||
function esc_html_e($s, $d = null) { echo esc_html($s); }
|
||||
function wp_json_encode($v, $f = 0) { return (string) json_encode($v, $f); }
|
||||
function wp_nonce_field($action, $name) { echo '<input type="hidden" name="' . $name . '" value="nonce" />'; }
|
||||
function wp_unslash($s) { return $s; }
|
||||
function sanitize_text_field($s) { return trim(strip_tags((string) $s)); }
|
||||
function wp_verify_nonce($nonce, $action) { return $nonce === 'valid-nonce' && $action === 'aksrt_push_meta_save'; }
|
||||
function is_wp_error($t) { return $t instanceof WP_Error; }
|
||||
function home_url($path = '/') { return 'https://example.test' . $path; }
|
||||
function current_time($type = 'mysql') { return '2026-10-13 12:00:00'; }
|
||||
function get_permalink($post) { return 'https://example.test/?p=' . (int) $post->ID; }
|
||||
function get_term_link($term, $taxonomy = '') {
|
||||
$id = is_object($term) ? (int) $term->term_id : (int) $term;
|
||||
return 'https://example.test/?cat=' . $id;
|
||||
}
|
||||
function wp_is_post_revision($id) { return false; }
|
||||
function wp_is_post_autosave($id) { return false; }
|
||||
function aksrt_searchable_post_types(): array { return ['post']; }
|
||||
function get_object_taxonomies($types, $output = 'names') { return ['post_tag', 'category', 'post_format']; }
|
||||
|
||||
// Outgoing HTTP: every call is captured so channel/URL/body can be asserted.
|
||||
$GLOBALS['push_requests'] = [];
|
||||
function wp_remote_post($url, $args = []) {
|
||||
$GLOBALS['push_requests'][] = ['url' => (string) $url, 'body' => (string) ($args['body'] ?? '')];
|
||||
return ['response' => ['code' => 200], 'body' => (string) json_encode(['success' => 1, 'remain' => 99])];
|
||||
}
|
||||
function wp_remote_retrieve_body($r) { return is_array($r) ? (string) ($r['body'] ?? '') : ''; }
|
||||
function wp_remote_retrieve_response_code($r) { return is_array($r) ? (int) ($r['response']['code'] ?? 0) : 0; }
|
||||
|
||||
// In-memory meta stores.
|
||||
$GLOBALS['push_post_meta'] = [];
|
||||
$GLOBALS['push_term_meta'] = [];
|
||||
function get_post_meta($id, $key, $single = false) { return $GLOBALS['push_post_meta'][$id][$key] ?? ''; }
|
||||
function update_post_meta($id, $key, $value) { $GLOBALS['push_post_meta'][$id][$key] = $value; return true; }
|
||||
function delete_post_meta($id, $key) { unset($GLOBALS['push_post_meta'][$id][$key]); return true; }
|
||||
function get_term_meta($id, $key, $single = false) { return $GLOBALS['push_term_meta'][$id][$key] ?? ''; }
|
||||
function update_term_meta($id, $key, $value) { $GLOBALS['push_term_meta'][$id][$key] = $value; return true; }
|
||||
function delete_term_meta($id, $key) { unset($GLOBALS['push_term_meta'][$id][$key]); return true; }
|
||||
}
|
||||
|
||||
namespace AKSRT\Settings {
|
||||
class Settings {
|
||||
public static array $config = [];
|
||||
public static function get_search_push_settings(): array { return self::$config; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
require_once dirname(__DIR__, 2) . '/src/Extensions/SearchPush.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/Extensions/SearchPushMetaBox.php';
|
||||
|
||||
use AKSRT\Extensions\SearchPush;
|
||||
use AKSRT\Extensions\SearchPushMetaBox;
|
||||
|
||||
$failures = [];
|
||||
$check = static function (string $label, bool $ok) use (&$failures): void {
|
||||
if (!$ok) {
|
||||
$failures[] = $label;
|
||||
}
|
||||
};
|
||||
|
||||
$reset = static function (array $config): void {
|
||||
\AKSRT\Settings\Settings::$config = $config;
|
||||
$GLOBALS['push_requests'] = [];
|
||||
$GLOBALS['push_post_meta'] = [];
|
||||
$GLOBALS['push_term_meta'] = [];
|
||||
$_POST = [];
|
||||
};
|
||||
|
||||
$post = static function (int $id): WP_Post {
|
||||
$p = new WP_Post();
|
||||
$p->ID = $id;
|
||||
return $p;
|
||||
};
|
||||
|
||||
$defaults = [
|
||||
'baidu_push_enabled' => true,
|
||||
'baidu_push_token' => 'TOKEN',
|
||||
'baidu_push_auto' => true,
|
||||
'baidu_push_on_publish' => true,
|
||||
'baidu_push_on_update' => false,
|
||||
'baidu_push_normal' => true,
|
||||
'baidu_push_fast' => false,
|
||||
'baidu_push_log_enabled' => true,
|
||||
];
|
||||
|
||||
$push = SearchPush::get_instance();
|
||||
$api = 'http://data.zz.baidu.com/urls?site=' . rawurlencode('https://example.test/') . '&token=TOKEN';
|
||||
|
||||
// 1) First publish pushes once through the normal-collection endpoint.
|
||||
$reset($defaults);
|
||||
$push->on_transition_post_status('publish', 'draft', $post(11));
|
||||
$check('首次发布推送一次', count($GLOBALS['push_requests']) === 1);
|
||||
$check('普通收录请求地址正确', ($GLOBALS['push_requests'][0]['url'] ?? '') === $api);
|
||||
$check('普通收录请求体为文章链接', ($GLOBALS['push_requests'][0]['body'] ?? '') === 'https://example.test/?p=11');
|
||||
$record = SearchPush::get_push_record(11);
|
||||
$check('推送记录写入 meta', !empty($record['normal_push']));
|
||||
$check('推送记录带更新时间', !empty($record['update_time']));
|
||||
$check('推送记录不含快速收录', !array_key_exists('daily_push', $record));
|
||||
|
||||
// 2) A completed push is never re-submitted on save.
|
||||
$push->on_transition_post_status('publish', 'publish', $post(11));
|
||||
$check('成功后更新不重复推送', count($GLOBALS['push_requests']) === 1);
|
||||
|
||||
// 3) Failed push retries on update when the update switch is on.
|
||||
$reset(array_merge($defaults, ['baidu_push_on_update' => true]));
|
||||
SearchPush::save_push_record(12, ['normal_push' => false, 'normal_result' => null, 'update_time' => '2026-10-13 09:00:00']);
|
||||
$push->on_transition_post_status('publish', 'publish', $post(12));
|
||||
$check('失败后更新重试一次', count($GLOBALS['push_requests']) === 1);
|
||||
$check('重试后记录为成功', !empty(SearchPush::get_push_record(12)['normal_push']));
|
||||
$push->on_transition_post_status('publish', 'publish', $post(12));
|
||||
$check('重试成功后不重复推送', count($GLOBALS['push_requests']) === 1);
|
||||
|
||||
// 4) 「重新提交」with a valid nonce forces a push even after success.
|
||||
$reset($defaults);
|
||||
$push->on_transition_post_status('publish', 'draft', $post(13));
|
||||
$_POST[SearchPush::RESUBMIT_FIELD] = '1';
|
||||
$_POST[SearchPush::NONCE_FIELD] = 'valid-nonce';
|
||||
$push->on_transition_post_status('publish', 'publish', $post(13));
|
||||
$check('重新提交强制再次推送', count($GLOBALS['push_requests']) === 2);
|
||||
|
||||
// 5) A forged nonce is ignored, dedup still applies.
|
||||
$reset($defaults);
|
||||
$push->on_transition_post_status('publish', 'draft', $post(14));
|
||||
$_POST[SearchPush::RESUBMIT_FIELD] = '1';
|
||||
$_POST[SearchPush::NONCE_FIELD] = 'forged-nonce';
|
||||
$push->on_transition_post_status('publish', 'publish', $post(14));
|
||||
$check('无效 nonce 的重新提交被忽略', count($GLOBALS['push_requests']) === 1);
|
||||
|
||||
// 6) Fast collection appends type=daily and records both channels.
|
||||
$reset(array_merge($defaults, ['baidu_push_fast' => true]));
|
||||
$push->on_transition_post_status('publish', 'draft', $post(15));
|
||||
$check('双通道推送两次', count($GLOBALS['push_requests']) === 2);
|
||||
$check('快速收录走 type=daily', str_contains($GLOBALS['push_requests'][1]['url'] ?? '', '&type=daily'));
|
||||
$record15 = SearchPush::get_push_record(15);
|
||||
$check('双通道记录完整', !empty($record15['normal_push']) && !empty($record15['daily_push']));
|
||||
$push->on_transition_post_status('publish', 'publish', $post(15));
|
||||
$check('双通道成功后不重复推送', count($GLOBALS['push_requests']) === 2);
|
||||
|
||||
// 7) No channel enabled: nothing pushed, nothing recorded.
|
||||
$reset(array_merge($defaults, ['baidu_push_normal' => false]));
|
||||
$push->on_transition_post_status('publish', 'draft', $post(16));
|
||||
$check('通道全关不推送', count($GLOBALS['push_requests']) === 0);
|
||||
$check('通道全关不写记录', SearchPush::get_push_record(16) === []);
|
||||
|
||||
// 8) Feature off / token missing: nothing pushed, nothing recorded.
|
||||
$reset(array_merge($defaults, ['baidu_push_enabled' => false]));
|
||||
$push->on_transition_post_status('publish', 'draft', $post(17));
|
||||
$check('未启用不推送', count($GLOBALS['push_requests']) === 0);
|
||||
$reset(array_merge($defaults, ['baidu_push_token' => '']));
|
||||
$push->on_transition_post_status('publish', 'draft', $post(18));
|
||||
$check('缺少 Token 不推送', count($GLOBALS['push_requests']) === 0);
|
||||
$check('缺少 Token 不写记录', SearchPush::get_push_record(18) === []);
|
||||
|
||||
// 9) Terms push via saved_term with the same dedup / resubmit rules.
|
||||
$reset($defaults);
|
||||
$push->on_saved_term(21, 21, 'category');
|
||||
$check('术语推送一次', count($GLOBALS['push_requests']) === 1);
|
||||
$check('术语推送链接正确', ($GLOBALS['push_requests'][0]['body'] ?? '') === 'https://example.test/?cat=21');
|
||||
$check('术语记录写入', !empty(SearchPush::get_push_record(21, true)['normal_push']));
|
||||
$push->on_saved_term(21, 21, 'category');
|
||||
$check('术语成功后不重复推送', count($GLOBALS['push_requests']) === 1);
|
||||
$push->on_saved_term(22, 22, 'post_format');
|
||||
$check('post_format 术语不推送', count($GLOBALS['push_requests']) === 1);
|
||||
$_POST[SearchPush::RESUBMIT_FIELD] = '1';
|
||||
$_POST[SearchPush::NONCE_FIELD] = 'valid-nonce';
|
||||
$push->on_saved_term(21, 21, 'category');
|
||||
$check('术语重新提交强制推送', count($GLOBALS['push_requests']) === 2);
|
||||
|
||||
// 10) Shared type / taxonomy policy.
|
||||
$check('可推送文章类型', SearchPush::pushable_post_types() === ['post']);
|
||||
$check('可推送分类法排除 post_format', SearchPush::pushable_taxonomies() === ['post_tag', 'category']);
|
||||
|
||||
// 11) Edit panel rendering.
|
||||
$reset($defaults);
|
||||
SearchPush::save_push_record(31, [
|
||||
'normal_push' => true,
|
||||
'normal_result' => ['success' => 1],
|
||||
'daily_push' => false,
|
||||
'daily_result' => null,
|
||||
'update_time' => '2026-10-13 09:00:00',
|
||||
]);
|
||||
SearchPush::save_push_record(31, [
|
||||
'normal_push' => true,
|
||||
'normal_result' => ['success' => 1],
|
||||
'daily_push' => false,
|
||||
'daily_result' => null,
|
||||
'update_time' => '2026-10-13 09:00:00',
|
||||
], true);
|
||||
$box = SearchPushMetaBox::get_instance();
|
||||
|
||||
ob_start();
|
||||
$box->render_post_panel($post(31));
|
||||
$html = (string) ob_get_clean();
|
||||
$check('面板含普通收录成功', str_contains($html, '普通收录:成功'));
|
||||
$check('面板含快速收录失败', str_contains($html, '快速收录:失败'));
|
||||
$check('面板含更新时间', str_contains($html, '2026-10-13 09:00:00'));
|
||||
$check('面板含重新提交勾选', str_contains($html, 'name="aksrt_push_resubmit"'));
|
||||
$check('面板含 nonce 字段', str_contains($html, 'name="aksrt_push_meta_nonce"'));
|
||||
$check('面板转义接口 JSON', str_contains($html, '{"success":1}'));
|
||||
|
||||
ob_start();
|
||||
$box->render_term_panel(null);
|
||||
$addHtml = (string) ob_get_clean();
|
||||
$check('新增术语表单仅提示', str_contains($addHtml, '发布、更新后刷新页面后可查看提交结果') && !str_contains($addHtml, '<tr'));
|
||||
|
||||
$term = new WP_Term();
|
||||
$term->term_id = 31;
|
||||
ob_start();
|
||||
$box->render_term_panel($term);
|
||||
$termHtml = (string) ob_get_clean();
|
||||
$check('术语编辑表单为表单行', str_contains($termHtml, '<tr class="form-field">'));
|
||||
$check('术语编辑表单含重新提交', str_contains($termHtml, 'name="aksrt_push_resubmit"'));
|
||||
|
||||
if ($failures) {
|
||||
echo "Baidu push harness FAILED\n";
|
||||
foreach ($failures as $failure) {
|
||||
echo ' - ' . $failure . "\n";
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "Baidu push harness passed\n";
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 「百度推送」后台设置页契约(对齐参考主题 zibll):
|
||||
* 1) PHP schema(SchemaExtensionsPush.php)与 JS schema(push.js)字段键、顺序、默认值一致;
|
||||
* 2) 参考主题字段全集存在:自动推送 JS、普通收录、快速收录、准入 Token、发布/更新触发;
|
||||
* 3) 双路/迁移字段(SEO 页 seo_baidu_*、熊掌号 xzh_*、批量推送 batch_*)已彻底移除,无双路兼容;
|
||||
* 4) 运行时(SearchPush + ExtensionRuntime)只读取 canonical 键,快速收录走 type=daily;
|
||||
* 5) 分类法 saved_term 推送、meta 去重、「重新提交」nonce 与编辑页面板均已接入,
|
||||
* 并由 PHP harness 驱动真实逻辑验证。
|
||||
*/
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const php = fs.readFileSync(path.join(root, 'src/Admin/Schema/SchemaExtensionsPush.php'), 'utf8');
|
||||
const js = fs.readFileSync(path.join(root, 'assets/admin/src/schema/sections/extensions/push.js'), 'utf8');
|
||||
const runtime = fs.readFileSync(path.join(root, 'src/Extensions/SearchPush.php'), 'utf8');
|
||||
const extensionRuntime = fs.readFileSync(path.join(root, 'src/Settings/ExtensionRuntime.php'), 'utf8');
|
||||
const globalPhp = fs.readFileSync(path.join(root, 'src/Admin/Schema/GlobalSchema.php'), 'utf8');
|
||||
const seoJs = fs.readFileSync(path.join(root, 'assets/admin/src/schema/sections/global/seo.js'), 'utf8');
|
||||
const displayGroups = fs.readFileSync(path.join(root, 'src/Settings/DisplayPageGroups.php'), 'utf8');
|
||||
const metaBox = fs.readFileSync(path.join(root, 'src/Extensions/SearchPushMetaBox.php'), 'utf8');
|
||||
const functions = fs.readFileSync(path.join(root, 'functions.php'), 'utf8');
|
||||
|
||||
// 参考主题(zibll)百度推送字段全集,AKSRT 单一 canonical 配置面(扩展&增强 → 百度推送)。
|
||||
const REFERENCE_KEYS = [
|
||||
'baidu_push_enabled',
|
||||
'baidu_push_token',
|
||||
'baidu_push_auto',
|
||||
'baidu_push_on_publish',
|
||||
'baidu_push_on_update',
|
||||
'baidu_push_normal',
|
||||
'baidu_push_fast',
|
||||
'baidu_push_log_enabled',
|
||||
];
|
||||
|
||||
// 双路 / 迁移 / 死代码字段:SEO 页 seo_baidu_*、熊掌号 xzh_*、批量推送与校验占位。
|
||||
const DUAL_KEYS = [
|
||||
'seo_baidu_push',
|
||||
'seo_baidu_normal',
|
||||
'seo_baidu_fast',
|
||||
'seo_baidu_token',
|
||||
'xzh_on',
|
||||
'xzh_appid',
|
||||
'xzh_render_tail',
|
||||
'xzh_jsonld_single',
|
||||
'xzh_jsonld_page',
|
||||
'xzh_jsonld_img',
|
||||
'baidu_push_batch_size',
|
||||
'baidu_push_verified',
|
||||
'push_batch',
|
||||
'batch_size',
|
||||
];
|
||||
|
||||
function phpFieldKeys(src) {
|
||||
const found = [];
|
||||
const re = /'key'\s*=>\s*'([a-z0-9_]+)',\s*'label'/g;
|
||||
let m;
|
||||
while ((m = re.exec(src)) !== null) found.push(m[1]);
|
||||
return found;
|
||||
}
|
||||
|
||||
function jsFieldKeys(src) {
|
||||
const found = [];
|
||||
const re = /key:\s*'([a-z0-9_]+)',\s*label:/g;
|
||||
let m;
|
||||
while ((m = re.exec(src)) !== null) found.push(m[1]);
|
||||
return found;
|
||||
}
|
||||
|
||||
test('PHP push schema 字段键与顺序对齐参考主题', () => {
|
||||
assert.deepEqual(phpFieldKeys(php), REFERENCE_KEYS);
|
||||
});
|
||||
|
||||
test('JS push schema 字段键与顺序对齐参考主题', () => {
|
||||
assert.deepEqual(jsFieldKeys(js), REFERENCE_KEYS);
|
||||
});
|
||||
|
||||
test('PHP schema 默认值对齐', () => {
|
||||
assert.match(php, /'baidu_push_enabled',\s*'label'\s*=>\s*'启用百度推送',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*false/);
|
||||
assert.match(php, /'baidu_push_token',\s*'label'\s*=>\s*'推送 Token',\s*'type'\s*=>\s*'input',\s*'default'\s*=>\s*''/);
|
||||
assert.match(php, /'baidu_push_auto',\s*'label'\s*=>\s*'自动推送',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*true/);
|
||||
assert.match(php, /'baidu_push_on_publish',\s*'label'\s*=>\s*'发布时主动推送',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*true/);
|
||||
assert.match(php, /'baidu_push_on_update',\s*'label'\s*=>\s*'更新时推送',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*false/);
|
||||
assert.match(php, /'baidu_push_normal',\s*'label'\s*=>\s*'普通收录',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*true/);
|
||||
assert.match(php, /'baidu_push_fast',\s*'label'\s*=>\s*'快速收录',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*false/);
|
||||
assert.match(php, /'baidu_push_log_enabled',\s*'label'\s*=>\s*'记录推送日志',\s*'type'\s*=>\s*'switch',\s*'default'\s*=>\s*true/);
|
||||
});
|
||||
|
||||
test('JS schema 默认值对齐', () => {
|
||||
assert.match(js, /baidu_push_enabled:\s*false/);
|
||||
assert.match(js, /baidu_push_token:\s*''/);
|
||||
assert.match(js, /baidu_push_auto:\s*true/);
|
||||
assert.match(js, /baidu_push_on_publish:\s*true/);
|
||||
assert.match(js, /baidu_push_on_update:\s*false/);
|
||||
assert.match(js, /baidu_push_normal:\s*true/);
|
||||
assert.match(js, /baidu_push_fast:\s*false/);
|
||||
assert.match(js, /baidu_push_log_enabled:\s*true/);
|
||||
});
|
||||
|
||||
test('双路/迁移/死代码字段在 schema、运行时与展示层均已移除(无双路)', () => {
|
||||
for (const legacy of DUAL_KEYS) {
|
||||
assert.ok(!php.includes(legacy), `SchemaExtensionsPush 残留: ${legacy}`);
|
||||
assert.ok(!js.includes(legacy), `push.js 残留: ${legacy}`);
|
||||
assert.ok(!runtime.includes(legacy), `SearchPush 残留: ${legacy}`);
|
||||
assert.ok(!extensionRuntime.includes(legacy), `ExtensionRuntime 残留: ${legacy}`);
|
||||
assert.ok(!globalPhp.includes(legacy), `GlobalSchema 残留: ${legacy}`);
|
||||
assert.ok(!seoJs.includes(legacy), `seo.js 残留: ${legacy}`);
|
||||
assert.ok(!displayGroups.includes(legacy), `DisplayPageGroups 残留: ${legacy}`);
|
||||
assert.ok(!metaBox.includes(legacy), `SearchPushMetaBox 残留: ${legacy}`);
|
||||
assert.ok(!functions.includes(legacy), `functions.php 残留: ${legacy}`);
|
||||
}
|
||||
assert.ok(!globalPhp.includes("'baidu'"), 'GlobalSchema SEO 分组残留百度重复配置面');
|
||||
assert.ok(!seoJs.includes("key: 'baidu'"), 'seo.js 残留百度重复配置面');
|
||||
});
|
||||
|
||||
test('普通/快速收录通道接入百度链接提交接口', () => {
|
||||
assert.match(runtime, /data\.zz\.baidu\.com\/urls\?site=/);
|
||||
assert.match(runtime, /'baidu_push_normal'/);
|
||||
assert.match(runtime, /'baidu_push_fast'/);
|
||||
assert.match(runtime, /&type=daily/);
|
||||
assert.match(extensionRuntime, /'baidu_push_normal'\s*=>/);
|
||||
assert.match(extensionRuntime, /'baidu_push_fast'\s*=>/);
|
||||
});
|
||||
|
||||
test('前台自动推送 JS 与参考主题一致', () => {
|
||||
assert.match(runtime, /zz\.bdstatic\.com\/linksubmit\/push\.js/);
|
||||
assert.match(runtime, /push\.zhanzhang\.baidu\.com\/push\.js/);
|
||||
assert.match(runtime, /add_action\('wp_footer'/);
|
||||
});
|
||||
|
||||
test('发布/更新触发沿用 transition_post_status 且仅限可检索内容类型', () => {
|
||||
assert.match(runtime, /transition_post_status/);
|
||||
assert.match(runtime, /aksrt_searchable_post_types/);
|
||||
assert.match(runtime, /wp_is_post_revision/);
|
||||
assert.match(runtime, /wp_is_post_autosave/);
|
||||
});
|
||||
|
||||
test('推送日志开关接入运行时', () => {
|
||||
assert.match(runtime, /baidu_push_log_enabled/);
|
||||
assert.match(extensionRuntime, /'baidu_push_log_enabled'/);
|
||||
});
|
||||
|
||||
test('服务状态契约保留扩展总览消费的键', () => {
|
||||
for (const key of ['enabled', 'provider', 'configured', 'available', 'verified', 'transport', 'missing_fields']) {
|
||||
assert.ok(runtime.includes(`'${key}'`), `get_status 缺少 ${key}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('分类法推送接入 saved_term 且排除文章形式', () => {
|
||||
assert.match(runtime, /add_action\('saved_term'/);
|
||||
assert.match(runtime, /public static function pushable_taxonomies/);
|
||||
assert.match(runtime, /array_diff\(\(array\) \$taxonomies, \['post_format', 'nav_menu'\]\)/);
|
||||
assert.match(runtime, /aksrt_baidu_push_taxonomies/);
|
||||
assert.match(runtime, /get_term_link\(\$term_id, \$taxonomy\)/);
|
||||
});
|
||||
|
||||
test('推送结果写入 meta 并按记录去重', () => {
|
||||
assert.match(runtime, /META_KEY\s*=\s*'_aksrt_baidu_push_back'/);
|
||||
assert.match(runtime, /private function record_is_complete/);
|
||||
assert.match(runtime, /private function build_record/);
|
||||
assert.match(runtime, /'normal_push'/);
|
||||
assert.match(runtime, /'daily_push'/);
|
||||
assert.match(runtime, /'update_time'/);
|
||||
assert.match(runtime, /update_term_meta\(/);
|
||||
assert.match(runtime, /delete_term_meta\(/);
|
||||
});
|
||||
|
||||
test('「重新提交」勾选需通过 metabox nonce 校验', () => {
|
||||
assert.match(runtime, /NONCE_ACTION\s*=\s*'aksrt_push_meta_save'/);
|
||||
assert.match(runtime, /NONCE_FIELD\s*=\s*'aksrt_push_meta_nonce'/);
|
||||
assert.match(runtime, /RESUBMIT_FIELD\s*=\s*'aksrt_push_resubmit'/);
|
||||
assert.match(runtime, /wp_verify_nonce\(\$nonce, self::NONCE_ACTION\)/);
|
||||
});
|
||||
|
||||
test('编辑页面板与参考主题「百度资源提交」Metabox 对齐', () => {
|
||||
assert.match(metaBox, /add_meta_box\(\s*'aksrt_baidu_push',\s*__\('百度资源提交', 'aksrt'\)/);
|
||||
assert.match(metaBox, /'side',\s*'high'/);
|
||||
assert.match(metaBox, /\{\$taxonomy\}_edit_form_fields/);
|
||||
assert.match(metaBox, /\{\$taxonomy\}_add_form_fields/);
|
||||
assert.match(metaBox, /普通收录:成功/);
|
||||
assert.match(metaBox, /快速收录:失败/);
|
||||
assert.match(metaBox, /更新时间:/);
|
||||
assert.match(metaBox, /重新提交/);
|
||||
assert.match(metaBox, /发布、更新后刷新页面后可查看提交结果/);
|
||||
assert.match(metaBox, /wp_nonce_field\(SearchPush::NONCE_ACTION, SearchPush::NONCE_FIELD\)/);
|
||||
assert.match(metaBox, /esc_html\(\$line\[1\]\)/, '接口结果需转义后输出');
|
||||
});
|
||||
|
||||
test('functions.php 接线推送面板', () => {
|
||||
assert.match(functions, /SearchPushMetaBox::get_instance\(\)->init\(\)/);
|
||||
});
|
||||
|
||||
test('百度推送行为 harness 通过', () => {
|
||||
const harness = path.join(root, 'tests', 'admin', 'baidu-push-harness.php');
|
||||
const output = execFileSync('php', [harness], { encoding: 'utf8' });
|
||||
assert.match(output, /Baidu push harness passed/);
|
||||
});
|
||||
Reference in New Issue
Block a user