Changeset 55224
- Timestamp:
- 02/04/2023 08:45:36 PM (20 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-locale-switcher.php
r55161 r55224 93 93 * @since 6.2.0 The `$user_id` parameter was added. 94 94 * 95 * @param string $locale The new locale.96 * @param null|int $user_id User ID for context if available.95 * @param string $locale The new locale. 96 * @param false|int $user_id User ID for context if available. 97 97 */ 98 98 do_action( 'switch_locale', $locale, $user_id ); … … 187 187 * @return string|false Locale if the locale has been switched, false otherwise. 188 188 */ 189 public function get_ current_locale() {189 public function get_switched_locale() { 190 190 $entry = end( $this->stack ); 191 191 … … 204 204 * @return int|false User ID if set and if the locale has been switched, false otherwise. 205 205 */ 206 public function get_ current_user_id() {206 public function get_switched_user_id() { 207 207 $entry = end( $this->stack ); 208 208 … … 223 223 */ 224 224 public function filter_locale( $locale ) { 225 $switched_locale = $this->get_ current_locale();225 $switched_locale = $this->get_switched_locale(); 226 226 227 227 if ( $switched_locale ) { -
trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php
r55161 r55224 55 55 $wp_textdomain_registry = new WP_Textdomain_Registry(); 56 56 57 // Clean up after any tests that don't restore the locale afterwards, 58 // before resetting $wp_locale_switcher. 59 restore_current_locale(); 60 57 61 remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) ); 58 62 $wp_locale_switcher = new WP_Locale_Switcher(); … … 599 603 * @covers ::switch_to_locale 600 604 * @covers ::switch_to_user_locale 601 * @covers WP_Locale_Switcher::get_ current_locale602 * @covers WP_Locale_Switcher::get_ current_user_id605 * @covers WP_Locale_Switcher::get_switched_locale 606 * @covers WP_Locale_Switcher::get_switched_user_id 603 607 */ 604 608 public function test_returns_current_locale_and_user_after_switching() { … … 612 616 ); 613 617 614 $locale_1 = $wp_locale_switcher->get_ current_locale();615 $user_id_1 = $wp_locale_switcher->get_ current_user_id();618 $locale_1 = $wp_locale_switcher->get_switched_locale(); 619 $user_id_1 = $wp_locale_switcher->get_switched_user_id(); 616 620 617 621 switch_to_user_locale( self::$user_id ); 618 622 619 $locale_2 = $wp_locale_switcher->get_ current_locale();620 $user_id_2 = $wp_locale_switcher->get_ current_user_id();621 622 switch_to_locale( 'en_GB' ); 623 624 $locale_3 = $wp_locale_switcher->get_ current_locale();625 $user_id_3 = $wp_locale_switcher->get_ current_user_id();623 $locale_2 = $wp_locale_switcher->get_switched_locale(); 624 $user_id_2 = $wp_locale_switcher->get_switched_user_id(); 625 626 switch_to_locale( 'en_GB' ); 627 628 $locale_3 = $wp_locale_switcher->get_switched_locale(); 629 $user_id_3 = $wp_locale_switcher->get_switched_user_id(); 626 630 627 631 switch_to_user_locale( $user_2 ); 628 632 629 $locale_4 = $wp_locale_switcher->get_ current_locale();630 $user_id_4 = $wp_locale_switcher->get_ current_user_id();631 632 restore_current_locale(); 633 634 $locale_5 = $wp_locale_switcher->get_ current_locale();635 $user_id_5 = $wp_locale_switcher->get_ current_user_id();633 $locale_4 = $wp_locale_switcher->get_switched_locale(); 634 $user_id_4 = $wp_locale_switcher->get_switched_user_id(); 635 636 restore_current_locale(); 637 638 $locale_5 = $wp_locale_switcher->get_switched_locale(); 639 $user_id_5 = $wp_locale_switcher->get_switched_user_id(); 636 640 637 641 $this->assertFalse( $locale_1, 'Locale should be false before switching' ); … … 649 653 $this->assertFalse( $locale_5, 'Locale should be false after restoring' ); 650 654 $this->assertFalse( $user_id_5, 'User ID should be false after restoring' ); 651 655 } 656 657 /** 658 * @ticket 57123 659 * 660 * @covers ::switch_to_locale 661 * @covers ::switch_to_user_locale 662 * @covers WP_Locale_Switcher::get_switched_locale 663 * @covers WP_Locale_Switcher::get_switched_user_id 664 */ 665 public function test_returns_previous_locale_and_user_after_switching() { 666 global $wp_locale_switcher; 667 668 $locale_1 = $wp_locale_switcher->get_switched_locale(); 669 $user_id_1 = $wp_locale_switcher->get_switched_user_id(); 670 671 switch_to_user_locale( self::$user_id ); 672 673 $locale_2 = $wp_locale_switcher->get_switched_locale(); 674 $user_id_2 = $wp_locale_switcher->get_switched_user_id(); 675 676 switch_to_locale( 'en_GB' ); 677 678 $locale_3 = $wp_locale_switcher->get_switched_locale(); 679 $user_id_3 = $wp_locale_switcher->get_switched_user_id(); 680 681 restore_previous_locale(); 682 683 $locale_4 = $wp_locale_switcher->get_switched_locale(); 684 $user_id_4 = $wp_locale_switcher->get_switched_user_id(); 685 686 $this->assertFalse( $locale_1, 'Locale should be false before switching' ); 687 $this->assertFalse( $user_id_1, 'User ID should be false before switching' ); 688 689 $this->assertSame( 'de_DE', $locale_2, 'The locale was not changed to de_DE' ); 690 $this->assertSame( self::$user_id, $user_id_2, 'User ID should match the main admin ID' ); 691 692 $this->assertSame( 'en_GB', $locale_3, 'The locale was not changed to en_GB' ); 693 $this->assertFalse( $user_id_3, 'User ID should be false after normal locale switching' ); 694 695 $this->assertSame( 'de_DE', $locale_4, 'The locale was not changed back to de_DE' ); 696 $this->assertSame( self::$user_id, $user_id_4, 'User ID should match the main admin ID again' ); 652 697 } 653 698
Note: See TracChangeset
for help on using the changeset viewer.