diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index e277a00e653d5..dee15b0d84383 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -126,6 +126,11 @@ public function get($app, $lang = null) { * @return string language If nothing works it returns 'en' */ public function findLanguage($app = null) { + $forceLang = $this->config->getSystemValue('force_language', false); + if (is_string($forceLang)) { + $this->requestLanguage = $forceLang; + } + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { return $this->requestLanguage; } diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php index 602967b162620..38d52d7763b32 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -110,7 +110,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndExistingStoredU ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->once()) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -144,7 +149,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->at(0)) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -167,7 +177,7 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -187,7 +197,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->at(0)) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -210,7 +225,7 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -233,7 +248,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'de') ->willReturn(false); $this->config - ->expects($this->at(0)) + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn(false); + $this->config + ->expects($this->at(1)) ->method('getSystemValue') ->with('installed', false) ->willReturn(true); @@ -256,7 +276,7 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor ->with('MyApp', 'jp') ->willReturn(false); $this->config - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('getSystemValue') ->with('default_language', false) ->willReturn('es'); @@ -273,6 +293,22 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor $this->assertSame('en', $factory->findLanguage('MyApp')); } + public function testFindLanguageWithForcedLanguage() { + $factory = $this->getFactory(['languageExists']); + $this->config + ->expects($this->at(0)) + ->method('getSystemValue') + ->with('force_language', false) + ->willReturn('de'); + + $factory->expects($this->once()) + ->method('languageExists') + ->with('MyApp', 'de') + ->willReturn(true); + + $this->assertSame('de', $factory->findLanguage('MyApp')); + } + /** * @dataProvider dataFindAvailableLanguages *