From 7801268f9453225f635571ed66ebf3896219ad00 Mon Sep 17 00:00:00 2001 From: Mayank Majeji <2611064+mayankmajeji@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:22:33 +0530 Subject: [PATCH] Tests: Log out the current user after class fixtures that need one. When one of these classes runs first, the hooks are saved with the kses filters removed for an administrator or editor, and later tests for a logged out user run without kses. Reset the user at the end of `wpSetUpBeforeClass()`, as the REST revisions controller tests do. See #66755. --- tests/phpunit/tests/ajax/wpAjaxHeartbeat.php | 1 + tests/phpunit/tests/post/wpGetAutoSave.php | 1 + tests/phpunit/tests/rest-api/rest-autosaves-controller.php | 1 + .../phpunit/tests/rest-api/wpRestTemplateAutosavesController.php | 1 + .../phpunit/tests/rest-api/wpRestTemplateRevisionsController.php | 1 + 5 files changed, 5 insertions(+) diff --git a/tests/phpunit/tests/ajax/wpAjaxHeartbeat.php b/tests/phpunit/tests/ajax/wpAjaxHeartbeat.php index 87d49987b5752..01e5e63c6de60 100644 --- a/tests/phpunit/tests/ajax/wpAjaxHeartbeat.php +++ b/tests/phpunit/tests/ajax/wpAjaxHeartbeat.php @@ -39,6 +39,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { self::$post_id = $factory->post->create( array( 'post_status' => 'draft' ) ); self::$post = get_post( self::$post_id ); + wp_set_current_user( 0 ); } /** diff --git a/tests/phpunit/tests/post/wpGetAutoSave.php b/tests/phpunit/tests/post/wpGetAutoSave.php index db27d25fad58d..a3449820fc4e7 100644 --- a/tests/phpunit/tests/post/wpGetAutoSave.php +++ b/tests/phpunit/tests/post/wpGetAutoSave.php @@ -37,6 +37,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { wp_set_current_user( self::$admin_id ); self::$post_id = $factory->post->create( array( 'post_status' => 'publish' ) ); + wp_set_current_user( 0 ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-autosaves-controller.php b/tests/phpunit/tests/rest-api/rest-autosaves-controller.php index be6a1996ee98a..42f76b931de02 100644 --- a/tests/phpunit/tests/rest-api/rest-autosaves-controller.php +++ b/tests/phpunit/tests/rest-api/rest-autosaves-controller.php @@ -108,6 +108,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 'post_author' => self::$editor_id, ) ); + wp_set_current_user( 0 ); } public static function wpTearDownAfterClass() { diff --git a/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php b/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php index 972cdccdb034d..246c7562a6be6 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php @@ -131,6 +131,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { ); wp_set_post_terms( self::$template_part_post->ID, self::TEST_THEME, 'wp_theme' ); wp_set_post_terms( self::$template_part_post->ID, WP_TEMPLATE_PART_AREA_HEADER, 'wp_template_part_area' ); + wp_set_current_user( 0 ); } /** diff --git a/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php b/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php index 3475c87d68750..88a4b548bfa9f 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php @@ -222,6 +222,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { ); wp_set_post_terms( self::$template_part_post_2->ID, self::TEST_THEME, 'wp_theme' ); wp_set_post_terms( self::$template_part_post_2->ID, WP_TEMPLATE_PART_AREA_HEADER, 'wp_template_part_area' ); + wp_set_current_user( 0 ); } /**