[BUGFIX] Fix preferred browser language detection 54/46954/2
authorHelmut Hummel <info@helhum.io>
Mon, 29 Feb 2016 08:04:13 +0000 (09:04 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 29 Feb 2016 17:57:52 +0000 (18:57 +0100)
Fix variable name, which was wrong after the refactoring.

Resolves: #73731
Related: #73511
Releases: master
Change-Id: I631592547e885732264d72803839f24ee804557d
Reviewed-on: https://review.typo3.org/46954
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Localization/Locales.php
typo3/sysext/core/Tests/Unit/Localization/LocalesTest.php [new file with mode: 0644]

index 25ff995..e8be8da 100644 (file)
@@ -244,14 +244,14 @@ class Locales implements \TYPO3\CMS\Core\SingletonInterface
         // Loop through the languages, with the highest priority first
         arsort($sortedPreferredLanguages, SORT_NUMERIC);
         foreach ($sortedPreferredLanguages as $preferredLanguage => $quality) {
-            if (isset($allLanguageCodes[$preferredLanguage])) {
-                $selectedLanguage = $allLanguageCodes[$preferredLanguage];
+            if (isset($allLanguageCodesFromLocales[$preferredLanguage])) {
+                $selectedLanguage = $allLanguageCodesFromLocales[$preferredLanguage];
                 break;
             }
             // Strip the country code from the end
             list($preferredLanguage, ) = explode('-', $preferredLanguage);
-            if (isset($allLanguageCodes[$preferredLanguage])) {
-                $selectedLanguage = $allLanguageCodes[$preferredLanguage];
+            if (isset($allLanguageCodesFromLocales[$preferredLanguage])) {
+                $selectedLanguage = $allLanguageCodesFromLocales[$preferredLanguage];
                 break;
             }
         }
diff --git a/typo3/sysext/core/Tests/Unit/Localization/LocalesTest.php b/typo3/sysext/core/Tests/Unit/Localization/LocalesTest.php
new file mode 100644 (file)
index 0000000..a830a6e
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Localization;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Localization\Locales;
+use TYPO3\CMS\Core\Localization\LocalizationFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Test case
+ */
+class LocalesTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+{
+    /**
+     * @var Locales
+     */
+    protected $subject;
+
+    protected function setUp()
+    {
+        $this->subject = GeneralUtility::makeInstance(Locales::class);
+        Locales::initialize();
+    }
+
+    /**
+     * @test
+     */
+    public function browserLanguageDetectionWorks()
+    {
+        $browserPreferredLanguageHeader = 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4';
+        $detectedLanguage = $this->subject->getPreferredClientLanguage($browserPreferredLanguageHeader);
+        $this->assertSame('de', $detectedLanguage);
+    }
+}