json('GET', '/', [], ['Accept-Language' => null]); $this->assertEquals(self::IS_FR, App::getLocale()); } #[Test] public function test_it_applies_fallback_locale_if_header_ask_for_unsupported() { Config::set('app.fallback_locale', self::IS_FR); $this->json('GET', '/', [], ['Accept-Language' => self::UNSUPPORTED_LANGUAGE]); $this->assertEquals(self::IS_FR, App::getLocale()); } #[Test] public function test_it_applies_fallback_locale_if_header_ask_for_several_unsupported() { Config::set('app.fallback_locale', self::IS_FR); $this->json('GET', '/', [], ['Accept-Language' => self::UNSUPPORTED_LANGUAGES]); $this->assertEquals(self::IS_FR, App::getLocale()); } #[Test] public function test_it_applies_fallback_locale_if_header_ask_for_wildcard() { Config::set('app.fallback_locale', self::IS_FR); $this->json('GET', '/', [], ['Accept-Language' => '*']); $this->assertEquals(self::IS_FR, App::getLocale()); } #[Test] public function test_it_applies_accepted_language_from_header() { $this->json('GET', '/', [], ['Accept-Language' => self::IS_FR]); $this->assertEquals(self::IS_FR, App::getLocale()); } #[Test] public function test_it_applies_first_accepted_language_from_header() { $this->json('GET', '/', [], ['Accept-Language' => self::ACCEPTED_LANGUAGES_DE_FR]); $this->assertEquals('de', App::getLocale()); } #[Test] public function test_it_applies_heaviest_language_from_header() { $this->json('GET', '/', [], ['Accept-Language' => self::ACCEPTED_LANGUAGES_WEIGHTED_DE_FR]); $this->assertEquals('de', App::getLocale()); } #[Test] public function test_it_applies_heaviest_language_with_variant_from_header() { $this->json('GET', '/', [], ['Accept-Language' => self::ACCEPTED_LANGUAGES_WEIGHTED_FR_VARIANTS]); $this->assertEquals('fr', App::getLocale()); } #[Test] public function test_it_ignores_unsupported_language_from_header() { $this->json('GET', '/', [], ['Accept-Language' => self::ACCEPTED_LANGUAGES_UNSUPPORTED_DE]); $this->assertEquals('de', App::getLocale()); } #[Test] public function test_user_preference_overrides_header() { $this->user = new User; $this->user['preferences->lang'] = self::IS_FR; $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]); $this->assertEquals(self::IS_FR, App::getLocale()); } #[Test] public function test_user_preference_applies_header() { $this->user = new User; $this->user['preferences->lang'] = 'browser'; $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => self::IS_DE]); $this->assertEquals(self::IS_DE, App::getLocale()); } #[Test] public function test_user_preference_overrides_fallback() { Config::set('app.fallback_locale', self::IS_DE); $this->user = new User; $this->user['preferences->lang'] = self::IS_FR; $this->actingAs($this->user)->json('GET', '/', [], ['Accept-Language' => null]); $this->assertEquals(self::IS_FR, App::getLocale()); } }