diff --git a/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php b/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php index 0f94f47..3256587 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\Component\Utility; use Drupal\Component\Utility\UserAgent; -use Drupal\Core\Language\Language; use Drupal\Tests\UnitTestCase; /** @@ -20,55 +19,42 @@ */ class UserAgentTest extends UnitTestCase { - protected $languages; - protected $mappings; - /** - * {@inheritdoc} + * Helper method to supply language codes to testGetBestMatchingLangcode(). + * + * @return array + * Language codes, ordered by priority. */ - public function setUp() { - parent::setUp(); - - $this->languages = array( + protected function getLanguages() { + return array( // In our test case, 'en' has priority over 'en-US'. - 'en' => new Language(array( - 'id' => 'en', - )), - 'en-US' => new Language(array( - 'id' => 'en-US', - )), + 'en', + 'en-US', // But 'fr-CA' has priority over 'fr'. - 'fr-CA' => new Language(array( - 'id' => 'fr-CA', - )), - 'fr' => new Language(array( - 'id' => 'fr', - )), + 'fr-CA', + 'fr', // 'es-MX' is alone. - 'es-MX' => new Language(array( - 'id' => 'es-MX', - )), + 'es-MX', // 'pt' is alone. - 'pt' => new Language(array( - 'id' => 'pt', - )), + 'pt', // Language codes with more then one dash are actually valid. // eh-oh-laa-laa is the official language code of the Teletubbies. - 'eh-oh-laa-laa' => new Language(array( - 'id' => 'eh-oh-laa-laa', - )), + 'eh-oh-laa-laa', // Chinese languages. - 'zh-hans' => new Language(array( - 'id' => 'zh-hans', - )), - 'zh-hant' => new Language(array( - 'id' => 'zh-hant', - )), - 'zh-hant-tw' => new Language(array( - 'id' => 'zh-hant', - )), + 'zh-hans', + 'zh-hant', + 'zh-hant-tw', ); - $this->mappings = array( + } + + /** + * Helper method to supply language mappings to testGetBestMatchingLangcode(). + * + * @return array + * Language mappings. + */ + protected function getMappings() { + return array( 'no' => 'nb', 'pt' => 'pt-pt', 'zh' => 'zh-hans', @@ -89,7 +75,7 @@ public function setUp() { * @covers ::getBestMatchingLangcode */ public function testGetBestMatchingLangcode($accept_language, $expected) { - $result = UserAgent::getBestMatchingLangcode($accept_language, array_keys($this->languages), $this->mappings); + $result = UserAgent::getBestMatchingLangcode($accept_language, $this->getLanguages(), $this->getMappings()); $this->assertSame($expected, $result, $accept_language); } @@ -153,7 +139,7 @@ public function providerTestGetBestMatchingLangcode() { array('', FALSE), array('de,pl', FALSE), array('iecRswK4eh', FALSE), - array($this->randomName(10), FALSE), + array($this->randomMachineName(10), FALSE), // Chinese langcodes. array('zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'),