Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion tests/phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/l10n/loadScriptTextdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -96,6 +100,8 @@ public function tear_down() {
reset_phpmailer_instance();
restore_previous_locale();
parent::tear_down();

unset( $GLOBALS['locale'] );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -92,6 +96,8 @@ public function tear_down() {
reset_phpmailer_instance();
restore_previous_locale();
parent::tear_down();

unset( $GLOBALS['locale'] );
}

/**
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/tests/user/wpSendUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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'] );
}

/**
Expand Down
Loading