From 2c2ae50db6ab7d651ade7566dcf25245da1c34ea Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 19 Aug 2026 12:43:19 +0400 Subject: [PATCH] Tests: Reset permalinks before database rollback --- tests/phpunit/includes/abstract-testcase.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index c87e5e7fd077c..ef98b96a70b39 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -162,13 +162,22 @@ public function wp_hash_password_options( array $options, string $algorithm ): a /** * After a test method runs, resets any state in WordPress the test method might have changed. * - * @global wpdb $wpdb WordPress database abstraction object. - * @global WP_Query $wp_the_query Main WordPress query object. - * @global WP_Query $wp_query WordPress query object. - * @global WP $wp WordPress environment object. + * @global wpdb $wpdb WordPress database abstraction object. + * @global WP_Query $wp_the_query Main WordPress query object. + * @global WP_Query $wp_query WordPress query object. + * @global WP $wp WordPress environment object. + * @global WP_Rewrite $wp_rewrite WordPress rewrite rules object. */ public function tear_down() { - global $wpdb, $wp_the_query, $wp_query, $wp; + global $wpdb, $wp_the_query, $wp_query, $wp, $wp_rewrite; + + /* + * Reset permalinks before the transaction rolls back so the in-memory rewrite state + * remains synchronized with the restored database option for subsequent class fixtures. + */ + if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && $wp_rewrite->permalink_structure ) { + $this->set_permalink_structure( '' ); + } $wpdb->query( 'ROLLBACK' );