Changeset 55010 for trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php
- Timestamp:
- 12/20/2022 03:10:35 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php
r54669 r55010 25 25 unset( $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 26 26 27 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 28 global $wp_textdomain_registry; 27 global $wp_textdomain_registry, $wp_locale_switcher; 29 28 30 29 $wp_textdomain_registry = new WP_Textdomain_Registry(); 30 31 remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) ); 32 $wp_locale_switcher = new WP_Locale_Switcher(); 33 $wp_locale_switcher->init(); 31 34 } 32 35 … … 34 37 unset( $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 35 38 36 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 37 global $wp_textdomain_registry; 39 global $wp_textdomain_registry, $wp_locale_switcher; 38 40 39 41 $wp_textdomain_registry = new WP_Textdomain_Registry(); 42 43 remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) ); 44 $wp_locale_switcher = new WP_Locale_Switcher(); 45 $wp_locale_switcher->init(); 40 46 41 47 parent::tear_down(); … … 337 343 set_current_screen( 'dashboard' ); 338 344 339 $locale_switcher = clone $wp_locale_switcher;340 345 // Reset $wp_locale_switcher so it thinks es_ES is the original locale. 346 remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) ); 341 347 $wp_locale_switcher = new WP_Locale_Switcher(); 342 348 $wp_locale_switcher->init(); … … 357 363 358 364 $language_header_after_restore = $l10n['default']->headers['Language']; // de_DE 359 360 $wp_locale_switcher = $locale_switcher;361 365 362 366 $this->assertFalse( $locale_switched_user_locale ); … … 389 393 set_current_screen( 'dashboard' ); 390 394 391 $locale_switcher = clone $wp_locale_switcher;392 395 // Reset $wp_locale_switcher so it thinks es_ES is the original locale. 396 remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) ); 393 397 $wp_locale_switcher = new WP_Locale_Switcher(); 394 398 $wp_locale_switcher->init(); … … 409 413 410 414 $language_header_after_restore = $l10n['default']->headers['Language']; // de_DE 411 412 $wp_locale_switcher = $locale_switcher;413 415 414 416 remove_filter( 'locale', array( $this, 'filter_locale' ) ); … … 427 429 */ 428 430 public function test_multiple_switches_to_site_locale_and_user_locale() { 429 global $wp_locale_switcher;430 431 431 $site_locale = get_locale(); 432 432 … … 441 441 set_current_screen( 'dashboard' ); 442 442 443 $locale_switcher = clone $wp_locale_switcher;444 445 $wp_locale_switcher = new WP_Locale_Switcher();446 $wp_locale_switcher->init();447 448 443 $user_locale = get_user_locale(); 449 444 … … 458 453 459 454 restore_current_locale(); 460 461 $wp_locale_switcher = $locale_switcher;462 455 463 456 $this->assertSame( 'en_US', get_locale() ); … … 470 463 public function test_switch_reloads_plugin_translations_outside_wp_lang_dir() { 471 464 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 472 global $wp_locale_switcher, $wp_textdomain_registry; 473 474 $locale_switcher = clone $wp_locale_switcher; 475 476 $wp_locale_switcher = new WP_Locale_Switcher(); 477 $wp_locale_switcher->init(); 465 global $wp_textdomain_registry; 478 466 479 467 require_once DIR_TESTDATA . '/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php'; … … 494 482 495 483 restore_current_locale(); 496 497 $wp_locale_switcher = $locale_switcher;498 484 499 485 $this->assertSame( 'This is a dummy plugin', $actual ); … … 504 490 505 491 /** 492 * @ticket 57116 493 */ 494 public function test_switch_reloads_plugin_translations() { 495 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 496 global $wp_textdomain_registry; 497 498 $has_translations_1 = $wp_textdomain_registry->has( 'internationalized-plugin' ); 499 500 require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; 501 502 $actual = i18n_plugin_test(); 503 504 switch_to_locale( 'es_ES' ); 505 506 $lang_path_es_es = $wp_textdomain_registry->get( 'internationalized-plugin', determine_locale() ); 507 508 switch_to_locale( 'de_DE' ); 509 510 $actual_de_de = i18n_plugin_test(); 511 512 $has_translations_3 = $wp_textdomain_registry->has( 'internationalized-plugin' ); 513 514 restore_previous_locale(); 515 516 $actual_es_es = i18n_plugin_test(); 517 518 restore_current_locale(); 519 520 $lang_path_en_us = $wp_textdomain_registry->get( 'internationalized-plugin', determine_locale() ); 521 522 $this->assertSame( 'This is a dummy plugin', $actual ); 523 $this->assertSame( 'Das ist ein Dummy Plugin', $actual_de_de ); 524 $this->assertSame( 'Este es un plugin dummy', $actual_es_es ); 525 $this->assertTrue( $has_translations_1 ); 526 $this->assertTrue( $has_translations_3 ); 527 $this->assertSame( WP_LANG_DIR . '/plugins/', $lang_path_es_es ); 528 $this->assertFalse( $lang_path_en_us ); 529 } 530 531 /** 506 532 * @ticket 39210 507 533 */ 508 534 public function test_switch_reloads_theme_translations_outside_wp_lang_dir() { 509 535 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 510 global $wp_locale_switcher, $wp_textdomain_registry; 511 512 $locale_switcher = clone $wp_locale_switcher; 513 514 $wp_locale_switcher = new WP_Locale_Switcher(); 515 $wp_locale_switcher->init(); 536 global $wp_textdomain_registry; 516 537 517 538 switch_theme( 'custom-internationalized-theme' ); … … 534 555 535 556 restore_current_locale(); 536 537 $wp_locale_switcher = $locale_switcher;538 557 539 558 $this->assertSame( get_template_directory() . '/languages/', $registry_value ); … … 543 562 } 544 563 564 /** 565 * @ticket 57116 566 */ 567 public function test_switch_to_locale_should_work() { 568 global $wp_textdomain_registry; 569 require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; 570 571 $has_translations = $wp_textdomain_registry->has( 'internationalized-plugin' ); 572 $path = $wp_textdomain_registry->get( 'internationalized-plugin', 'es_ES' ); 573 574 $actual = i18n_plugin_test(); 575 576 switch_to_locale( 'es_ES' ); 577 578 $actual_es_es = i18n_plugin_test(); 579 580 $this->assertTrue( $has_translations ); 581 $this->assertNotEmpty( $path ); 582 $this->assertSame( 'This is a dummy plugin', $actual ); 583 $this->assertSame( 'Este es un plugin dummy', $actual_es_es ); 584 } 585 545 586 public function filter_locale() { 546 587 return 'es_ES';
Note: See TracChangeset
for help on using the changeset viewer.