'use strict'; 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 read = (file) => fs.readFileSync(path.join(root, file), 'utf8'); const SYSTEM_FIELDS = [ 'hide_admin_bar', 'remove_emoji', 'remove_open_sans', 'remove_more_wp_head', 'remove_dashboard_widgets', 'display_wp_update', 'split_upload_s', 'split_minimum_size', 'newfilename', 'newfilename_type', 'disabled_large_thumbnail', 'admin_user_del_fields', 'admin_frontend_set', 'close_gutenberg', 'disabled_autoembed', 'mce_float_toolbar', 'time_ago_s', 'time_format', ]; test('system tools schema registers the 系统工具 page under 扩展&增强', () => { const schema = read('src/Admin/Schema/SchemaExtensionsSystem.php'); const registry = read('src/Admin/Schema/SchemaExtensions.php'); const clientMirror = read('assets/admin/src/schema/sections/extensions/system.js'); const clientIndex = read('assets/admin/src/schema/sections/extensions/index.js'); const nav = read('assets/admin/src/constants/sections/extensions.js'); const sectionDefaults = read('assets/admin/src/constants/sections/index.js'); assert.match(registry, /'system'\s+=> SchemaExtensionsSystem::build\(\)/); assert.match(schema, /'key'\s+=> 'system'/); assert.match(schema, /'title'\s+=> '系统工具'/); for (const key of SYSTEM_FIELDS) { assert.match(schema, new RegExp(`'${key}'`), `missing schema field ${key}`); assert.match(clientMirror, new RegExp(`${key}`), `missing client mirror field ${key}`); } // Conditional fields mirror the reference theme's dependency rules. assert.match(schema, /'newfilename_type'[^[]*'dependsOn'\s+=> \['key' => 'newfilename', 'value' => true\]/s); assert.match(schema, /'split_minimum_size'[^[]*'dependsOn'\s+=> \['key' => 'split_upload_s', 'value' => true\]/s); assert.match(schema, /'time_format'[^[]*'dependsOn'\s+=> \['key' => 'time_ago_s', 'operator' => 'falsy'\]/s); assert.match(clientMirror, /split_minimum_size[\s\S]*dependsOn:\s*\{\s*key:\s*'split_upload_s',\s*value:\s*true\s*\}/); assert.match(clientMirror, /time_format[\s\S]*dependsOn:\s*\{\s*key:\s*'time_ago_s',\s*operator:\s*'falsy'\s*\}/); assert.match(clientIndex, /import \{ systemSchema \} from '\.\/system\.js'/); assert.match(clientIndex, /system: systemSchema/); assert.match(nav, /key: 'extensions-system'/); assert.match(nav, /route: '\/extensions\/system'/); assert.match(nav, /section: 'system'/); // 系统工具 is the first child of 扩展&增强 (reference theme order) and the default landing page. assert.ok(nav.indexOf('extensions-system') < nav.indexOf('extensions-ip'), '系统工具 should precede IP归属地'); assert.match(sectionDefaults, /extensions:\s*'extensions-system'/); }); test('system tools settings are consumed at runtime and initialized on boot', () => { const runtime = read('src/Settings/ExtensionRuntime.php'); const bootstrap = read('functions.php'); assert.match(runtime, /public static function get_system_tools_settings\(\): array/); assert.match(runtime, /'newfilename_type'\s+=> \$rename_type/); assert.match(runtime, /'split_minimum_size'\s+=> max\(4, min\(100, \(int\) \(\$settings\['split_minimum_size'\] \?\? 20\)\)\)/); assert.match(bootstrap, /\\AKSRT\\Extensions\\SystemTools::get_instance\(\)->init\(\)/); assert.match(bootstrap, /\\AKSRT\\Frontend\\PageAdminSet::get_instance\(\)->init\(\)/); }); test('system tools switches wire the reference theme hook suite', () => { const tools = read('src/Extensions/SystemTools.php'); assert.match(tools, /!empty\(\$settings\['hide_admin_bar'\]\) \|\| !is_super_admin\(\)/); assert.match(tools, /remove_action\('wp_head', 'print_emoji_detection_script', 7\)/); assert.match(tools, /remove_filter\('wp_mail', 'wp_staticize_emoji_for_email'\)/); assert.match(tools, /add_action\('init', \[\$this, 'remove_open_sans'\]\)/); assert.match(tools, /wp_deregister_style\('open-sans'\)/); assert.match(tools, /add_action\('after_setup_theme', \[\$this, 'remove_more_wp_head'\]\)/); assert.match(tools, /remove_action\('wp_head', 'wp_generator'\)/); assert.match(tools, /add_action\('do_meta_boxes', \[\$this, 'remove_dashboard_widgets'\], 10, 3\)/); assert.match(tools, /unset\(\$wp_meta_boxes\['dashboard'\]\['normal'\]\['high'\]\['dashboard_php_nag'\]\)/); assert.match(tools, /add_filter\('site_status_tests', \[\$this, 'filter_site_status_tests'\]\)/); assert.match(tools, /add_filter\('pre_http_request', \[\$this, 'block_site_health_requests'\], 10, 3\)/); assert.match(tools, /'api\.wordpress\.org\/core\/serve-happy\/'/); assert.match(tools, /remove_action\('admin_init', '_maybe_update_core'\)/); assert.match(tools, /add_filter\('automatic_updater_disabled', '__return_true'\)/); assert.match(tools, /remove_action\('wp_version_check', 'wp_version_check'\)/); assert.match(tools, /add_action\('admin_menu', \[\$this, 'hide_update_notices'\]\)/); assert.match(tools, /remove_action\('admin_notices', 'update_nag', 3\)/); assert.match(tools, /remove_image_size\('1536x1536'\)/); assert.match(tools, /add_filter\('intermediate_image_sizes', static function \(\$sizes\)/); assert.match(tools, /add_filter\('use_block_editor_for_post', '__return_false'\)/); assert.match(tools, /remove_filter\('the_content', \[\$GLOBALS\['wp_embed'\], 'autoembed'\], 8\)/); assert.match(tools, /add_action\('show_user_profile', \[\$this, 'hide_user_profile_fields'\]\)/); assert.match(tools, /add_action\('edit_user_profile', \[\$this, 'hide_user_profile_fields'\]\)/); }); test('upload rename settings are canonical to 系统工具 and consumed by the upload pipeline', () => { const permissionsSchema = read('src/Admin/Schema/SchemaPermissions.php'); const permissionsMirror = read('assets/admin/src/schema/sections/permissions/index.js'); const systemSchema = read('src/Admin/Schema/SchemaExtensionsSystem.php'); const uploadLimits = read('src/Attachment/UploadLimits.php'); assert.doesNotMatch(permissionsSchema, /newfilename/); assert.doesNotMatch(permissionsMirror, /newfilename/); assert.match(systemSchema, /'newfilename'/); assert.match(uploadLimits, /add_filter\('wp_handle_upload_prefilter', \[\$this, 'rename_upload_file'\]/); assert.match(uploadLimits, /\$settings\['newfilename_type'\] \?\? 'time'\) === 'random'/); }); test('split upload ships a full chunk protocol: routes, merge pipeline, and client uploader', () => { const chunk = read('src/Core/FrontSubmitChunk.php'); const frontSubmit = read('src/Core/FrontSubmit.php'); const editorJs = read('assets/js/front-submit-editor.js'); const submitPage = read('templates/pages/page-submit.php'); const schema = read('src/Admin/Schema/SchemaExtensionsSystem.php'); // The submit class consumes the chunk trait and registers its routes. assert.match(frontSubmit, /use FrontSubmitChunk;/); assert.match(frontSubmit, /\$this->register_chunk_routes\(\)/); assert.match(frontSubmit, /public function persist_uploaded_file\(string \$kind, array \$file, bool \$sideload = false\)/); // Backend mirrors the reference theme's user_split_upload protocol. assert.match(chunk, /\/front-submit\/upload-chunk\/\(\?Pimage\|video\|resource\)/); assert.match(chunk, /\/front-submit\/upload-merge\(\?Pimage\|video\|resource\)|\/front-submit\/upload-merge\/\(\?Pimage\|video\|resource\)/); assert.match(chunk, /\/front-submit\/upload-status\/\(\?Pimage\|video\|resource\)/); assert.match(chunk, /permission_callback' => \[\$this, 'can_upload_attachment'\]/); assert.match(chunk, /const CHUNK_SIZE_BYTES = 2 \* 1048576;/); assert.match(chunk, /md5\(get_current_blog_id\(\) \. '\|' \. get_current_user_id\(\) \. '\|' \. \$name\)/); assert.match(chunk, /\$this->persist_uploaded_file\(\$params\['kind'\], \[/); assert.match(chunk, /apply_filters\('aksrt_temp_dir', WP_CONTENT_DIR \. '\/aksrt-temp'\)/); assert.match(chunk, /\$this->chunk_temp_cleanup\(\$temp_dir\)/); // Whole-file upload and chunk merge share one persistence pipeline; merged // files are not HTTP uploads, so the pipeline must use the sideload action. assert.match(frontSubmit, /return \$this->persist_uploaded_file\(\$kind, \$file, false\);/); assert.match(frontSubmit, /'action' => 'wp_handle_sideload'/); assert.match(frontSubmit, /media_handle_upload\('aksrt_front_submit_file', 0, \[\], \$overrides\)/); // Client uploader picks the chunked path past the threshold and resumes from status. assert.match(editorJs, /function uploadInChunks\(file, type\)/); assert.match(editorJs, /splitUploadConfig\(\)/); assert.match(editorJs, /file\.size > split\.minSize \* 1048576/); assert.match(editorJs, /chunkUrl\('upload-status'\)/); assert.match(editorJs, /chunkUrl\('upload-chunk'\)/); assert.match(editorJs, /chunkUrl\('upload-merge'\)/); assert.match(editorJs, /'\/front-submit\/' \+ action \+ '\/' \+ uploadKey/); // Config flows from the settings page into aksrtSubmitData. assert.match(submitPage, /'splitUpload' => \[/); assert.match(submitPage, /'enabled' => !empty\(\$system_tools\['split_upload_s'\]\)/); assert.match(submitPage, /'minSize' => \(int\) \(\$system_tools\['split_minimum_size'\] \?\? 20\)/); assert.match(schema, /'split_upload_s'/); assert.match(schema, /'split_minimum_size'/); // The legacy dead config keys stay out of the shared script payload. assert.doesNotMatch(read('src/Core/ScriptsPart1c.php'), /is_split_upload|split_minimum_size/); }); test('frontend page edit ships gate, footer modal, and legacy ajax-save contract', () => { const pageAdminSet = read('src/Frontend/PageAdminSet.php'); const floatButtons = read('inc/helpers/aksrt-float-buttons.php'); const bootstrap = read('functions.php'); const mainJs = read('assets/js/runtime/main.js'); assert.match(bootstrap, /\\AKSRT\\Frontend\\PageAdminSet::get_instance\(\)->init\(\)/); assert.match(pageAdminSet, /public static function enabled\(\): bool/); assert.match(pageAdminSet, /empty\(\$settings\['admin_frontend_set'\]/); assert.match(pageAdminSet, /current_user_can\('manage_options'\)/); assert.match(pageAdminSet, /is_page_template\('templates\/pages\/page-submit\.php'\)/); assert.match(pageAdminSet, /is_page_template\('templates\/pages\/page-posts-navs\.php'\)/); // Reference parity: the gear float button opens the footer-rendered bootstrap modal. assert.match(floatButtons, /apply_filters\('aksrt_float_right_buttons', \$btn, \$is_mobile\)/); assert.match(pageAdminSet, /add_filter\('aksrt_float_right_buttons', \[\$this, 'float_button'\], 10, 2\)/); assert.match(pageAdminSet, /add_action\('wp_footer', \[\$this, 'render_modal'\], 10\)/); assert.match(pageAdminSet, /data-toggle="modal" data-target="#modal_admin_set"/); assert.match(pageAdminSet, /class="modal fade" id="modal_admin_set" tabindex="-1" role="dialog" aria-hidden="false" win-ajax-replace="modal_admin_set"/); assert.match(pageAdminSet, /class="modal-content page-set-modal"/); assert.match(pageAdminSet, /wp_nonce_field\('aksrt_frontend_set', '_wpnonce', true, false\)/); // Reference hidden inputs: type + taxonomy + post_type + id travel with the submit. assert.match(pageAdminSet, /name="action" value="aksrt_frontend_set_save"/); assert.match(pageAdminSet, /name="type" value="' . esc_attr\(\$type\)/); assert.match(pageAdminSet, /name="taxonomy" value="' . esc_attr\(\$taxonomy\)/); assert.match(pageAdminSet, /name="post_type" value="' . esc_attr\(\$post_type\)/); // 模块布局 opens the customizer widgets panel and returns to the current URL. assert.match(pageAdminSet, /admin_url\('customize\.php'\)/); assert.match(pageAdminSet, /'autofocus' => \['panel' => 'widgets'\]/); // Modal footer mirrors the reference: 模块布局 / 后台编辑 / 确认修改 (wp-ajax-submit). assert.match(pageAdminSet, /esc_html__\('模块布局', 'aksrt'\)/); assert.match(pageAdminSet, /esc_html__\('后台编辑', 'aksrt'\)/); assert.match(pageAdminSet, /esc_html__\('确认修改', 'aksrt'\)/); assert.match(pageAdminSet, /class="but c-yellow-2 padding-lg"/); assert.match(pageAdminSet, /class="but c-yellow padding-lg"/); assert.match(pageAdminSet, /class="but jb-blue padding-lg wp-ajax-submit"/); // Fields replicate the reference input construct and map to AKSRT's post meta. assert.match(pageAdminSet, /private function render_inputs\(array \$inputs\): string/); assert.match(pageAdminSet, /class="heading col-xs-3 text-right"/); assert.match(pageAdminSet, /class="option col-xs-8"/); assert.match(pageAdminSet, /\\AKSRT\\Core\\PostMetaBox::META_KEY/); assert.match(pageAdminSet, /\\AKSRT\\Core\\DomainModel::POST_VIEW_COUNT_KEY/); assert.match(pageAdminSet, /update_post_meta\(\$post_id, '_aksrt_like_count', max\(0, \(int\) \$_POST\['like'\]\)\)/); assert.match(pageAdminSet, /wp_update_term\(\$term_id, \(string\) \$term->taxonomy, \$data\)/); assert.match(pageAdminSet, /set_post_format\(\$post_id, \$format === 'standard' \? '' : \$format\)/); // Page branch: 标题样式 + 模块布局(widgets_register) + 容器位置. assert.match(pageAdminSet, /esc_attr\(\(string\) \(\$meta\['id'\] \?\? ''\)\) \. '\[\]" id="'/); assert.match(pageAdminSet, /'page_header_style'/); assert.match(pageAdminSet, /update_post_meta\(\$post_id, 'widgets_register', \$register \? '1' : ''\)/); assert.match(pageAdminSet, /update_post_meta\(\$post_id, 'widgets_register_container', \$containers\)/); // Reference checkbox semantics: unchecked boxes never submit, so both are written unconditionally. assert.match(pageAdminSet, /\$meta\['no_article-navs'\] = !empty\(\$_POST\['no_article-navs'\]\)/); assert.match(pageAdminSet, /\$meta\['article_maxheight_xz'\] = !empty\(\$_POST\['article_maxheight_xz'\]\)/); // The geometry mirrors the reference construct (row + heading + option, \n separators). assert.match(pageAdminSet, /'
' \. "\\n"/); // Save runs under the vendored main.js aksrt_ajax contract ({msg,reload}). assert.match(pageAdminSet, /add_action\('wp_ajax_aksrt_frontend_set_save', \[\$this, 'ajax_save'\]\)/); assert.match(pageAdminSet, /check_ajax_referer\('aksrt_frontend_set', '_wpnonce'\)/); assert.match(pageAdminSet, /wp_send_json\(\['msg' => __\('保存成功,正在刷新页面', 'aksrt'\), 'reload' => true\]\)/); assert.match(mainJs, /jQuery\.fn\.serializeObject = function/); assert.match(mainJs, /if \(n\.reload\) \{/); // The dedicated fetch-submit client is gone: vendored main.js owns the flow. assert.equal(fs.existsSync(path.join(root, 'assets/js/page-admin-set.js')), false); }); test('frontend page edit icons follow the FA5 convention and the hint bar fades like the reference', () => { const pageAdminSet = read('src/Frontend/PageAdminSet.php'); const hintJs = read('assets/js/front-page-admin-set.js'); const floatingCss = read('assets/css/frontend/floating-buttons.css'); const publicCss = read('assets/css/build/public.css'); const publicMinCss = read('assets/css/build/public.min.css'); // Site-wide icon convention is aksrt_icon_markup()'s normalized `fa fas fa-*`: // the gear, the modal header, both footer links and the submit button. // FA5 renames the reference's FA4 glyphs (sliders→sliders-h, pie-chart→chart-pie). assert.match(pageAdminSet, /