From da128bc5e3d9146c38ad12385c44a6077eb7a2fa Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 26 Feb 2016 20:21:11 +0000 Subject: [PATCH] Add tests for `get_locale()`. Props realloc. Fixes #35965. git-svn-id: https://develop.svn.wordpress.org/trunk@36740 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/l10n/getLocale.php | 95 ++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tests/phpunit/tests/l10n/getLocale.php diff --git a/tests/phpunit/tests/l10n/getLocale.php b/tests/phpunit/tests/l10n/getLocale.php new file mode 100644 index 0000000000..4c4fe8bb02 --- /dev/null +++ b/tests/phpunit/tests/l10n/getLocale.php @@ -0,0 +1,95 @@ +assertSame( 'foo', $found ); + } + + public function test_local_option_should_take_precedence_on_multisite() { + global $locale; + $old_locale = $locale; + $locale = null; + + if ( ! is_multisite() ) { + $this->markTestSkipped( __METHOD__ . ' requires Multisite' ); + } + + update_option( 'WPLANG', 'en_GB' ); + update_site_option( 'WPLANG', 'es_ES' ); + + $found = get_locale(); + $locale = $old_locale; + + $this->assertSame( 'en_GB', $found ); + } + + public function test_network_option_should_be_fallback_on_multisite() { + global $locale; + $old_locale = $locale; + $locale = null; + + if ( ! is_multisite() ) { + $this->markTestSkipped( __METHOD__ . ' requires Multisite' ); + } + + update_site_option( 'WPLANG', 'es_ES' ); + + $found = get_locale(); + $locale = $old_locale; + + $this->assertSame( 'es_ES', $found ); + } + + public function test_option_should_be_respected_on_nonmultisite() { + global $locale; + $old_locale = $locale; + $locale = null; + + if ( is_multisite() ) { + $this->markTestSkipped( __METHOD__ . ' does not apply to Multisite' ); + } + + update_option( 'WPLANG', 'es_ES' ); + + $found = get_locale(); + $locale = $old_locale; + + $this->assertSame( 'es_ES', $found ); + + } + + public function test_should_fall_back_on_en_US() { + global $locale; + $old_locale = $locale; + $locale = null; + + $found = get_locale(); + $locale = $old_locale; + + $this->assertSame( 'en_US', $found ); + } + + public function test_should_respect_get_locale_filter() { + add_filter( 'locale', array( $this, 'filter_get_locale' ) ); + $found = get_locale(); + remove_filter( 'locale', array( $this, 'filter_get_locale' ) ); + + $this->assertSame( 'foo', $found ); + } + + public function filter_get_locale() { + return 'foo'; + } +}