diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index c87e5e7fd077c..c94c944b39da1 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -25,6 +25,13 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { protected static $hooks_saved = array(); protected static $ignore_files; + /** + * Site locale before each test. + * + * @var string + */ + protected $original_locale = 'en_US'; + /** * Fixture factory. * @@ -122,6 +129,14 @@ public function set_up() { $this->clean_up_global_scope(); + /* + * Capture the site locale after resetting the runtime cache so it can be + * restored without querying the database after the test transaction rolls back. + */ + unset( $GLOBALS['locale'] ); + $this->original_locale = determine_locale(); + WP_Translation_Controller::get_instance()->set_locale( $this->original_locale ); + /* * When running core tests, ensure that post types and taxonomies * are reset for each test. We skip this step for non-core tests, @@ -229,7 +244,9 @@ public function tear_down() { remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); $this->_restore_hooks(); wp_set_current_user( 0 ); - + // Synchronize the locale globals with the site locale captured before the test. + $GLOBALS['locale'] = $this->original_locale; + WP_Translation_Controller::get_instance()->set_locale( $this->original_locale ); $this->reset_lazyload_queue(); WP_Style_Engine_CSS_Rules_Store::remove_all_stores(); diff --git a/tests/phpunit/tests/l10n/loadScriptTextdomain.php b/tests/phpunit/tests/l10n/loadScriptTextdomain.php index b84527e1f1757..7ceb2e3d2cc5a 100644 --- a/tests/phpunit/tests/l10n/loadScriptTextdomain.php +++ b/tests/phpunit/tests/l10n/loadScriptTextdomain.php @@ -19,6 +19,8 @@ class Tests_L10n_LoadScriptTextdomain extends WP_UnitTestCase { * @dataProvider data_resolve_relative_path */ public function test_resolve_relative_path( $translation_path, $handle, $src, $textdomain, $filter = array() ) { + wp_scripts(); + if ( ! empty( $filter ) ) { add_filter( $filter[0], $filter[1], 10, $filter[2] ?? 1 ); } diff --git a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php index bb6195912e233..448e5be5a6b50 100644 --- a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php +++ b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php @@ -84,6 +84,10 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { */ public function set_up() { parent::set_up(); + + unset( $GLOBALS['locale'] ); + get_locale(); + reset_phpmailer_instance(); } @@ -96,6 +100,8 @@ public function tear_down() { reset_phpmailer_instance(); restore_previous_locale(); parent::tear_down(); + + unset( $GLOBALS['locale'] ); } /** diff --git a/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php b/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php index 37e2e4c282bd5..036f9b2aefe74 100644 --- a/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php +++ b/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php @@ -80,6 +80,10 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { */ public function set_up() { parent::set_up(); + + unset( $GLOBALS['locale'] ); + get_locale(); + reset_phpmailer_instance(); } @@ -92,6 +96,8 @@ public function tear_down() { reset_phpmailer_instance(); restore_previous_locale(); parent::tear_down(); + + unset( $GLOBALS['locale'] ); } /** diff --git a/tests/phpunit/tests/user/wpSendUserRequest.php b/tests/phpunit/tests/user/wpSendUserRequest.php index 11e3130f225a5..be73c1eaafbd3 100644 --- a/tests/phpunit/tests/user/wpSendUserRequest.php +++ b/tests/phpunit/tests/user/wpSendUserRequest.php @@ -60,6 +60,9 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { public function set_up() { parent::set_up(); + unset( $GLOBALS['locale'] ); + get_locale(); + set_current_screen( 'dashboard' ); reset_phpmailer_instance(); } @@ -72,10 +75,10 @@ public function set_up() { public function tear_down() { reset_phpmailer_instance(); - unset( $GLOBALS['locale'] ); - restore_previous_locale(); parent::tear_down(); + + unset( $GLOBALS['locale'] ); } /**