diff options
author | Andreas Fischer <bantu@owncloud.com> | 2013-10-23 15:41:15 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@owncloud.com> | 2013-10-23 15:41:15 +0200 |
commit | 8166aaf82c1e96090e32eb2d8479bd150c12d166 (patch) | |
tree | 9e441c13359d7adf0b8a5e15acea5d477c3b65e1 /tests | |
parent | 06f2ae082eb6fc04b1c6680bd2f35ca1c2032d59 (diff) | |
download | nextcloud-server-8166aaf82c1e96090e32eb2d8479bd150c12d166.tar.gz nextcloud-server-8166aaf82c1e96090e32eb2d8479bd150c12d166.zip |
Some tests for OC_L10N::findLanguage()
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/l10n.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php index 12eac818f84..5ddf2290c35 100644 --- a/tests/lib/l10n.php +++ b/tests/lib/l10n.php @@ -64,4 +64,45 @@ class Test_L10n extends PHPUnit_Framework_TestCase { $l = new OC_L10N('test'); $this->assertSame('February 13, 2009 23:31', $l->l('datetime', 1234567890)); } + + /** + * @dataProvider findLanguageData + */ + public function testFindLanguage($default, $preference, $expected) { + OC_User::setUserId(null); + if (is_null($default)) { + OC_Config::deleteKey('default_language'); + } else { + OC_Config::setValue('default_language', $default); + } + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $preference; + + $reflection = new \ReflectionClass('OC_L10N'); + $prop = $reflection->getProperty('language'); + $prop->setAccessible(1); + $prop->setValue(''); + $prop->setAccessible(0); + + $this->assertSame($expected, OC_L10N::findLanguage()); + } + + public function findLanguageData() { + return array( + // Exact match + array(null, 'de-DE,en;q=0.5', 'de_DE'), + array(null, 'de-DE,en-US;q=0.8,en;q=0.6', 'de_DE'), + + // Best match + array(null, 'de-US,en;q=0.5', 'de'), + array(null, 'de-US,en-US;q=0.8,en;q=0.6', 'de'), + + // The default_language config setting overrides browser preferences. + array('es_AR', 'de-DE,en;q=0.5', 'es_AR'), + array('es_AR', 'de-DE,en-US;q=0.8,en;q=0.6', 'es_AR'), + + // Worst case default to english + array(null, '', 'en'), + array(null, null, 'en'), + ); + } } |