Some tests for OC_L10N::findLanguage()

This commit is contained in:
Andreas Fischer 2013-10-23 15:41:15 +02:00
parent 06f2ae082e
commit 8166aaf82c
1 changed files with 41 additions and 0 deletions

View File

@ -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'),
);
}
}