diff --git a/scripts/lib/fixture-environment.php b/scripts/lib/fixture-environment.php index ef7b1e9..8f050c2 100644 --- a/scripts/lib/fixture-environment.php +++ b/scripts/lib/fixture-environment.php @@ -80,6 +80,9 @@ function chrnx_fixture_environment_restore_raw_option( string $name, array $stat // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Exact option nonexistence is required for reversible local fixtures. $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name = %s", $name ) ); } + wp_cache_delete( $name, 'options' ); + wp_cache_delete( 'alloptions', 'options' ); + wp_cache_delete( 'notoptions', 'options' ); } /** Synchronize the live permalink structure, optionally preserving an exact raw option row. */ @@ -88,7 +91,6 @@ function chrnx_fixture_environment_sync_permalink_structure( string $permalink_s $wp_rewrite->set_permalink_structure( $permalink_structure ); if ( is_array( $raw_state ) ) { chrnx_fixture_environment_restore_raw_option( 'permalink_structure', $raw_state ); - wp_cache_delete( 'permalink_structure', 'options' ); } flush_rewrite_rules( false ); } diff --git a/tests/php/FixtureEnvironmentTest.php b/tests/php/FixtureEnvironmentTest.php index 5dd3803..7ae527b 100644 --- a/tests/php/FixtureEnvironmentTest.php +++ b/tests/php/FixtureEnvironmentTest.php @@ -47,6 +47,14 @@ class FixtureEnvironmentTest extends WP_UnitTestCase { $this->assertNull( $restored ); } $this->assertSame( $outer_exists ? $outer_value : '', $wp_rewrite->permalink_structure ); + if ( ! $outer_exists ) { + $missing_sentinel = 'chrnx-missing-permalink'; + $this->assertSame( $missing_sentinel, get_option( 'permalink_structure', $missing_sentinel ) ); + $this->assertTrue( update_option( 'permalink_structure', '/reinserted/%post_id%/' ) ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- A subsequent Options API insert must persist after exact raw absence is restored. + $reinserted = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", 'permalink_structure' ) ); + $this->assertSame( '/reinserted/%post_id%/', $reinserted ); + } } /** Snapshot/restore preserves exact options, unrelated stickies, and owned status. */