48 lines
2.2 KiB
JavaScript
48 lines
2.2 KiB
JavaScript
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')
|
|
|
|
test('every forum page mounts the dedicated runtime and the public write routes require a nonce', () => {
|
|
const core = read('src/Forum/Core.php')
|
|
const rest = read('src/Forum/Rest.php')
|
|
const runtime = read('assets/js/forum-runtime.js')
|
|
for (const template of ['page-forums.php', 'page-forum-list.php', 'page-forum-post.php', 'page-forum-edit.php']) {
|
|
assert.ok(fs.existsSync(path.join(root, 'templates/pages', template)))
|
|
}
|
|
assert.match(core, /wp_enqueue_script\('jio-forum'/)
|
|
assert.match(core, /wp_create_nonce\('wp_rest'\)/)
|
|
assert.match(rest, /'permission_callback' => \$auth/)
|
|
assert.match(rest, /wp_verify_nonce\(\$nonce, 'wp_rest'\)/)
|
|
assert.match(runtime, /'X-WP-Nonce'/)
|
|
})
|
|
|
|
test('paid content has server-side presentation guards beyond its page body', () => {
|
|
const access = read('src/Forum/Access.php')
|
|
const integration = read('src/Forum/Integration.php')
|
|
const view = read('src/Forum/View.php')
|
|
assert.match(access, /function can_view\(/)
|
|
assert.match(integration, /add_filter\('the_content'/)
|
|
assert.match(integration, /add_filter\('get_the_excerpt'/)
|
|
assert.match(integration, /add_filter\('jio_seo_head_payload'/)
|
|
assert.match(view, /Access::can_view\(get_current_user_id\(\), \$post->ID\)/)
|
|
})
|
|
|
|
test('forum management, account, search and responsive styles remain connected', () => {
|
|
const admin = read('assets/admin/src/constants/sections/forum.js')
|
|
const schema = read('src/Admin/Schema/SchemaForum.php')
|
|
const search = read('search.php')
|
|
const css = read('assets/css/routes/forum.css')
|
|
for (const section of ['general', 'home', 'publishing', 'access', 'replies', 'payment', 'urls']) {
|
|
assert.match(admin, new RegExp(`'${section}'`))
|
|
assert.match(schema, new RegExp(`'${section}'`))
|
|
}
|
|
assert.match(search, /search_type === 'forum'/)
|
|
assert.match(css, /@media\(max-width:800px\)/)
|
|
assert.match(css, /@media\(max-width:480px\)/)
|
|
assert.match(read('src/Forum/View.php'), /function user_panel\(/)
|
|
})
|