diff --git a/inc/queries.php b/inc/queries.php index dc6379c..7d5a468 100644 --- a/inc/queries.php +++ b/inc/queries.php @@ -17,7 +17,7 @@ function chrnx_is_eligible_editorial_post( $post ) { return $post instanceof WP_Post && 'post' === $post->post_type && 'publish' === $post->post_status - && 1 === preg_match( '/[^[:space:]]/', $post->post_title ); + && 1 === preg_match( '/\S/u', $post->post_title ); } /** Clear request-local editorial query results after relevant mutations. */ diff --git a/playwright.config.mjs b/playwright.config.mjs index 7126812..0ed59c0 100644 --- a/playwright.config.mjs +++ b/playwright.config.mjs @@ -2,6 +2,7 @@ import { defineConfig, devices } from '@playwright/test'; export default defineConfig({ testDir: './tests/e2e', + globalSetup: './tests/e2e/global-setup.mjs', fullyParallel: true, forbidOnly: Boolean(process.env.CI), retries: process.env.CI ? 2 : 0, diff --git a/tests/e2e/editorial-editor.spec.mjs b/tests/e2e/editorial-editor.spec.mjs index 34ae33d..7dd1ae6 100644 --- a/tests/e2e/editorial-editor.spec.mjs +++ b/tests/e2e/editorial-editor.spec.mjs @@ -1,14 +1,5 @@ -import { execFileSync } from 'node:child_process'; import { expect, test } from '@playwright/test'; -test.beforeAll( () => { - execFileSync( - 'npm', - [ 'exec', '--', 'wp-env', 'run', 'cli', 'wp', 'eval', 'chrnx_seed_editorial_terms();' ], - { cwd: process.cwd(), env: process.env, stdio: 'inherit' }, - ); -} ); - test( 'editorial and podcast controls initialize in the real post editor', async ( { page } ) => { const openPanel = async ( name ) => { const button = page.getByRole( 'button', { name, exact: true } ); diff --git a/tests/e2e/global-setup.mjs b/tests/e2e/global-setup.mjs new file mode 100644 index 0000000..d4a3876 --- /dev/null +++ b/tests/e2e/global-setup.mjs @@ -0,0 +1,9 @@ +import { execFileSync } from 'node:child_process'; + +export default function globalSetup() { + execFileSync( + 'npm', + [ 'exec', '--', 'wp-env', 'run', 'cli', 'wp', 'eval', 'chrnx_seed_editorial_terms();' ], + { cwd: process.cwd(), env: process.env, stdio: 'inherit' }, + ); +} diff --git a/tests/php/EditorialQueriesTest.php b/tests/php/EditorialQueriesTest.php index 628d531..2d8e635 100644 --- a/tests/php/EditorialQueriesTest.php +++ b/tests/php/EditorialQueriesTest.php @@ -298,6 +298,48 @@ class EditorialQueriesTest extends WP_UnitTestCase { $this->assertFalse( chrnx_is_eligible_editorial_post( $post ) ); $post->post_title = "\fX"; $this->assertTrue( chrnx_is_eligible_editorial_post( $post ) ); + $post->post_title = "\xC3\x28"; + $this->assertFalse( chrnx_is_eligible_editorial_post( $post ), 'Invalid UTF-8 fails closed.' ); + } + + /** Unicode whitespace eligibility agrees between canonical PHP and the real database query. */ + public function test_unicode_title_eligibility_matches_database_matrix_without_underfill() { + $cases = array( + 'ascii spaces' => array( ' ', false ), + 'control spaces' => array( "\t\n\f", false ), + 'nbsp' => array( "\u{00A0}", false ), + 'em space' => array( "\u{2003}", false ), + 'mixed whitespace' => array( " \t\u{00A0}\u{2003}", false ), + 'ascii content' => array( " \tA", true ), + 'nbsp with content' => array( "\u{00A0}A", true ), + 'em with unicode' => array( "\u{2003}字", true ), + 'mixed with text' => array( "\u{00A0}\u{2003} x", true ), + ); + $expected_ids = array(); + $all_ids = array(); + foreach ( $cases as $label => $case ) { + $post_id = $this->create_post( $case[0], '2026-06-08 10:00:00' ); + $all_ids[] = $post_id; + $this->assertSame( $case[1], chrnx_is_eligible_editorial_post( $post_id ), $label . ' PHP eligibility' ); + if ( $case[1] ) { + $expected_ids[] = $post_id; + } + } + + $query = chrnx_run_eligible_query( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post__in' => $all_ids, + 'posts_per_page' => count( $all_ids ), + 'fields' => 'ids', + 'orderby' => 'ID', + 'order' => 'ASC', + 'chrnx_require_nonempty_title' => true, + ) + ); + $this->assertSame( $expected_ids, array_map( 'absint', $query->posts ) ); + $this->assertCount( 3, chrnx_get_featured_story_ids( 3 ) ); } /** Journal and Show SQL use the same literal stored-title contract as PHP. */ diff --git a/tests/smoke/e2e-harness.test.mjs b/tests/smoke/e2e-harness.test.mjs new file mode 100644 index 0000000..46767a6 --- /dev/null +++ b/tests/smoke/e2e-harness.test.mjs @@ -0,0 +1,14 @@ +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import test from 'node:test'; + +test( 'Playwright seeds editorial prerequisites once outside browser workers', async () => { + const config = await readFile( 'playwright.config.mjs', 'utf8' ); + const setup = await readFile( 'tests/e2e/global-setup.mjs', 'utf8' ); + const spec = await readFile( 'tests/e2e/editorial-editor.spec.mjs', 'utf8' ); + + assert.match( config, /globalSetup:\s*['"]\.\/tests\/e2e\/global-setup\.mjs['"]/ ); + assert.match( setup, /wp-env.*chrnx_seed_editorial_terms\(\);/s ); + assert.equal( setup.match( /chrnx_seed_editorial_terms/g )?.length, 1 ); + assert.doesNotMatch( spec, /wp-env|execFileSync|beforeAll/ ); +} );