From ce0f682d044d2cd92c1cfcb53aec7e72bfa33371 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 30 Oct 2022 02:52:04 +0000 Subject: [PATCH] Tests: Correctly restore the `wp_installing()` status in Ajax tests. In the tests for updating a plugin or theme via Ajax, `wp_installing( true )` was called to prevent `wp_update_plugins()` or `wp_update_themes()` from running. Since the subsequent `wp_installing( false )` call was in the same `try { ... }` block, it could not be executed if an exception was thrown, affecting other tests. In this case, after rearranging the Ajax tests in [54722], this started affecting the `get_site_option()` calls in the tests for `wp_ajax_wp_compression_test()`. By moving both `wp_installing()` calls out of the `try`/`catch` block, we can ensure the status is correctly restored. Follow-up to [734/tests], [37150], [38168], [38710], [54722]. See #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@54723 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/ajax/wpAjaxUpdatePlugin.php | 8 +++++--- tests/phpunit/tests/ajax/wpAjaxUpdateTheme.php | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/ajax/wpAjaxUpdatePlugin.php b/tests/phpunit/tests/ajax/wpAjaxUpdatePlugin.php index daae271ef6..08d65879ee 100644 --- a/tests/phpunit/tests/ajax/wpAjaxUpdatePlugin.php +++ b/tests/phpunit/tests/ajax/wpAjaxUpdatePlugin.php @@ -141,16 +141,18 @@ class Tests_Ajax_wpAjaxUpdatePlugin extends WP_Ajax_UnitTestCase { $_POST['plugin'] = 'hello.php'; $_POST['slug'] = 'hello-dolly'; + // Prevent wp_update_plugins() from running. + wp_installing( true ); + // Make the request. try { - // Prevent wp_update_plugins() from running. - wp_installing( true ); $this->_handleAjax( 'update-plugin' ); - wp_installing( false ); } catch ( WPAjaxDieContinueException $e ) { unset( $e ); } + wp_installing( false ); + // Get the response. $response = json_decode( $this->_last_response, true ); diff --git a/tests/phpunit/tests/ajax/wpAjaxUpdateTheme.php b/tests/phpunit/tests/ajax/wpAjaxUpdateTheme.php index 4e3f8a8e6a..c424d7f582 100644 --- a/tests/phpunit/tests/ajax/wpAjaxUpdateTheme.php +++ b/tests/phpunit/tests/ajax/wpAjaxUpdateTheme.php @@ -112,18 +112,18 @@ class Tests_Ajax_wpAjaxUpdateTheme extends WP_Ajax_UnitTestCase { $_POST['_ajax_nonce'] = wp_create_nonce( 'updates' ); $_POST['slug'] = 'twentyten'; + // Prevent wp_update_themes() from running. + wp_installing( true ); + // Make the request. try { - - // Prevent wp_update_themes() from running. - wp_installing( true ); $this->_handleAjax( 'update-theme' ); - wp_installing( false ); - } catch ( WPAjaxDieContinueException $e ) { unset( $e ); } + wp_installing( false ); + // Get the response. $response = json_decode( $this->_last_response, true );