fix: normalize CHRNX unicode titles
This commit is contained in:
6 files changed
+67
-10
No files matched your search
+1
-1
@@ -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. */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 } );
|
||||
|
||||
@@ -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' },
|
||||
);
|
||||
}
|
||||
@@ -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. */
|
||||
|
||||
@@ -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/ );
|
||||
} );
|
||||
Reference in new issue
Block a user