fix: synchronize CHRNX fixture permalinks

This commit is contained in:
chrnx committed 2026-08-12 14:14:47 -05:00
1 parent f4e122f52e
commit 05dfe83a49
4 files changed
+79 -3

No files matched your search

+20
View File
@@ -35,6 +35,26 @@ test( 'home remains coherent at all approved review viewports', async ( { page }
}
} );
test( 'seeded post permalink resolves its single template', async ( { page } ) => {
const title = 'The save file remembers what the hero pretends to forget';
const expectedPath = '/the-save-file-remembers-what-the-hero-pretends-to-forget/';
await page.goto( '/' );
const fixtureCard = page.locator( '.chrnx-featured-story', { hasText: title } );
await expect( fixtureCard.getByRole( 'heading', { name: title, exact: true } ) ).toBeVisible();
const fixtureLink = fixtureCard.getByRole( 'link' );
const [ navigationResponse ] = await Promise.all( [
page.waitForNavigation(),
fixtureLink.click(),
] );
expect( navigationResponse ).not.toBeNull();
expect( navigationResponse.status() ).toBe( 200 );
await expect( page ).toHaveURL( new RegExp( `${ expectedPath }$` ) );
await expect( page.locator( 'main.chrnx-entry--single' ) ).toBeVisible();
await expect( page.getByRole( 'heading', { level: 1, name: title, exact: true } ) ).toBeVisible();
} );
test( 'topic, music, podcast, and about surfaces use real content and approved art', async ( {
page,
} ) => {
+40
View File
@@ -9,6 +9,46 @@ require_once dirname( __DIR__, 2 ) . '/scripts/lib/fixture-environment.php';
/** Verify the seeder environment lifecycle in the isolated WordPress test DB. */
class FixtureEnvironmentTest extends WP_UnitTestCase {
/** Provide exact raw permalink option states that fixture restore must preserve. */
public function permalink_option_states_provider(): array {
return array(
'present row' => array( true, '/outer/%post_id%/' ),
'absent row' => array( false, null ),
);
}
/**
* Applying and restoring fixtures synchronize the option row and live rewrite state.
*
* @dataProvider permalink_option_states_provider
*/
public function test_permalink_apply_and_restore_synchronize_raw_option_and_live_rewrite( bool $outer_exists, ?string $outer_value ): void {
global $wpdb, $wp_rewrite;
if ( $outer_exists ) {
update_option( 'permalink_structure', $outer_value );
} else {
delete_option( 'permalink_structure' );
}
$wp_rewrite->permalink_structure = $outer_exists ? $outer_value : '';
$this->assertTrue( chrnx_fixture_environment_snapshot() );
chrnx_fixture_environment_apply( array( 'permalink_structure' => '/%postname%/' ) );
$this->assertSame( '/%postname%/', get_option( 'permalink_structure' ) );
$this->assertSame( '/%postname%/', $wp_rewrite->permalink_structure );
$this->assertTrue( chrnx_fixture_environment_restore() );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Exact raw option existence and bytes are the restore contract.
$restored = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", 'permalink_structure' ), ARRAY_A );
if ( $outer_exists ) {
$this->assertIsArray( $restored );
$this->assertSame( $outer_value, $restored['option_value'] );
} else {
$this->assertNull( $restored );
}
$this->assertSame( $outer_exists ? $outer_value : '', $wp_rewrite->permalink_structure );
}
/** Snapshot/restore preserves exact options, unrelated stickies, and owned status. */
public function test_environment_snapshot_scenarios_and_restore_are_exact() {
global $wpdb;