getLocale.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @group l10n
  4. * @group i18n
  5. */
  6. class Tests_L10n_GetLocale extends WP_UnitTestCase {
  7. public function test_should_respect_locale_global() {
  8. global $locale;
  9. $old_locale = $locale;
  10. $locale = 'foo';
  11. $found = get_locale();
  12. $locale = $old_locale;
  13. $this->assertSame( 'foo', $found );
  14. }
  15. /**
  16. * @group ms-required
  17. */
  18. public function test_local_option_should_take_precedence_on_multisite() {
  19. global $locale;
  20. $old_locale = $locale;
  21. $locale = null;
  22. update_option( 'WPLANG', 'en_GB' );
  23. update_site_option( 'WPLANG', 'es_ES' );
  24. $found = get_locale();
  25. $locale = $old_locale;
  26. $this->assertSame( 'en_GB', $found );
  27. }
  28. /**
  29. * @group ms-required
  30. */
  31. public function test_network_option_should_be_fallback_on_multisite() {
  32. if ( ! is_multisite() ) {
  33. $this->markTestSkipped( __METHOD__ . ' requires Multisite.' );
  34. }
  35. global $locale;
  36. $old_locale = $locale;
  37. $locale = null;
  38. update_site_option( 'WPLANG', 'es_ES' );
  39. $found = get_locale();
  40. $locale = $old_locale;
  41. $this->assertSame( 'es_ES', $found );
  42. }
  43. /**
  44. * @group ms-excluded
  45. */
  46. public function test_option_should_be_respected_on_nonmultisite() {
  47. if ( is_multisite() ) {
  48. $this->markTestSkipped( __METHOD__ . ' does not apply to Multisite.' );
  49. }
  50. global $locale;
  51. $old_locale = $locale;
  52. $locale = null;
  53. update_option( 'WPLANG', 'es_ES' );
  54. $found = get_locale();
  55. $locale = $old_locale;
  56. $this->assertSame( 'es_ES', $found );
  57. }
  58. public function test_should_fall_back_on_en_US() {
  59. global $locale;
  60. $old_locale = $locale;
  61. $locale = null;
  62. $found = get_locale();
  63. $locale = $old_locale;
  64. $this->assertSame( 'en_US', $found );
  65. }
  66. public function test_should_respect_get_locale_filter() {
  67. add_filter( 'locale', array( $this, 'filter_get_locale' ) );
  68. $found = get_locale();
  69. remove_filter( 'locale', array( $this, 'filter_get_locale' ) );
  70. $this->assertSame( 'foo', $found );
  71. }
  72. public function filter_get_locale() {
  73. return 'foo';
  74. }
  75. }