const test = require('node:test') const assert = require('node:assert/strict') const fs = require('node:fs') const path = require('node:path') const root = path.resolve(__dirname, '../..') const read = file => fs.readFileSync(path.join(root, file), 'utf8') const list = read('src/Admin/Native/PostListEnhance.php') const fields = read('src/Admin/Native/PostListEditFields.php') const domain = read('src/Core/DomainModel.php') const pay = read('inc/helpers/aksrt-pay.php') const metabox = read('src/Core/PostMetaBox.php') const resourceBox = read('src/Core/ResourceMetaBox.php') test('quick and bulk edit boxes hook the post list with no topics column', () => { // 参考主题把配置项挂在「专题」分类法列上;本项目没有专题,统一挂在互动数据列。 assert.match(list, /quick_edit_custom_box/) assert.match(list, /bulk_edit_custom_box/) assert.match(list, /COLUMN_STATS/) // 代码里不得再出现专题分类法列(类文档块的说明除外,只看 namespace 之后的部分)。 const code = list.slice(list.indexOf('namespace AKSRT')) assert.doesNotMatch(code, /taxonomy-topics/) assert.doesNotMatch(code, /topics/) }) test('every quick-edit field group is rendered', () => { // 四组字段的入口函数与分组标识都要存在,缺一组该列就少一块配置。 assert.match(list, /render_edit_boxes/) assert.match(list, /PostListEditFields::extended\(\)/) assert.match(list, /PostListEditFields::pay\(\$this->currency_symbol\(\)\)/) assert.match(list, /filter_fields_html\(\)/) assert.match(list, /'pay'/) assert.match(list, /'filter'/) // 字段定义本体放在独立的 PostListEditFields,两个静态方法必须真的存在。 assert.match(fields, /function extended\(\): array/) assert.match(fields, /function pay\(string \$currency\): array/) }) test('quick-edit inputs are namespaced under aksrt_bulk_edit', () => { // 字段名统一 aksrt_bulk_edit[{id}][{field}],避免与 WP 原生数据冲突。 assert.match(list, /aksrt_bulk_edit\[' \. \$id \. '\]\[' \. \$field\['id'\] \. '\]/) // number 类型带运算子字段。 assert.match(list, /\[operation\]/) assert.match(list, /\[val\]/) }) test('quick-edit markup is emitted without kses stripping the controls', () => { // select/option/input/fieldset/legend 不在 wp_kses_post 的文章白名单里, // 一旦用它包上面板,所有控件会被剥成纯文本(表现为「新增的操作都不可用」)。 // 字段值均已在生成时 esc_attr/esc_html 转义,这里必须原样输出。 assert.doesNotMatch(list, /wp_kses_post\(\$this->edit_boxes_html\(\)\)/) // 面板必须真的产生表单控件,而不是纯文本。 assert.match(list, /