From 2bf14c926f771ad5fa90c11c10c43a627ded0ba8 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 19 Aug 2026 21:35:47 +0400 Subject: [PATCH] Tests: Restore Ajax hooks for each test --- tests/phpunit/includes/testcase-ajax.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/testcase-ajax.php b/tests/phpunit/includes/testcase-ajax.php index 2e86c29e67284..dcba2e58c3a5c 100644 --- a/tests/phpunit/includes/testcase-ajax.php +++ b/tests/phpunit/includes/testcase-ajax.php @@ -122,7 +122,13 @@ public static function set_up_before_class() { remove_action( 'admin_init', '_maybe_update_plugins' ); remove_action( 'admin_init', '_maybe_update_themes' ); - // Register the core actions. + self::register_core_actions(); + } + + /** + * Registers the core Ajax actions. + */ + protected static function register_core_actions() { foreach ( array_merge( self::$_core_actions_get, self::$_core_actions_post ) as $action ) { if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) ) { add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 ); @@ -138,6 +144,15 @@ public static function set_up_before_class() { public function set_up() { parent::set_up(); + /* + * The shared hook snapshot may have been captured before an Ajax test case + * registered these callbacks, then restored after another randomized test. + */ + self::register_core_actions(); + remove_action( 'admin_init', '_maybe_update_core' ); + remove_action( 'admin_init', '_maybe_update_plugins' ); + remove_action( 'admin_init', '_maybe_update_themes' ); + add_filter( 'wp_doing_ajax', '__return_true' ); add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );