[BUGFIX] Cast fallback language uids to integer 62/59662/7
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 7 Feb 2019 12:04:05 +0000 (13:04 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 7 Feb 2019 23:36:13 +0000 (00:36 +0100)
To prepare a couple of bugfixes regarding the language fallback handling,
the property `SiteLanguage::$fallbackLanguageIds` must be an array of
integer values. The patch ensures that all values are cast to integers.

Resolves: #87673
Releases: master, 9.5
Change-Id: I437a08ce992718f601a612df4cddd9ecac5e1d3a
Reviewed-on: https://review.typo3.org/59662
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Tested-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php
typo3/sysext/core/Tests/Unit/Site/Entity/SiteLanguageTest.php

index d20ea92..033596a 100644 (file)
@@ -152,7 +152,13 @@ class SiteLanguage
             $this->fallbackType = $configuration['fallbackType'];
         }
         if (isset($configuration['fallbacks'])) {
-            $this->fallbackLanguageIds = is_array($configuration['fallbacks']) ? $configuration['fallbacks'] : explode(',', $configuration['fallbacks']);
+            $fallbackLanguageIds = $configuration['fallbacks'];
+
+            if (is_string($fallbackLanguageIds)) {
+                $fallbackLanguageIds = explode(',', $fallbackLanguageIds);
+            }
+
+            $this->fallbackLanguageIds = array_map('intval', $fallbackLanguageIds);
         }
         if (isset($configuration['enabled'])) {
             $this->enabled = (bool)$configuration['enabled'];
index 2008f7a..2935405 100644 (file)
@@ -29,15 +29,18 @@ class SiteLanguageTest extends UnitTestCase
     {
         $configuration = [
             'navigationTitle' => 'NavTitle',
-            'customValue' => 'a custom value'
+            'customValue' => 'a custom value',
+            'fallbacks' => '1,2',
         ];
         $subject = new SiteLanguage(1, 'de', new Uri('/'), $configuration);
         $expected = [
+            'navigationTitle' => 'NavTitle',
+            'customValue' => 'a custom value',
+            'fallbacks' => '1,2',
             'languageId' => 1,
             'locale' => 'de',
             'base' => '/',
             'title' => 'Default',
-            'navigationTitle' => 'NavTitle',
             'twoLetterIsoCode' => 'en',
             'hreflang' => 'en-US',
             'direction' => '',
@@ -45,9 +48,11 @@ class SiteLanguageTest extends UnitTestCase
             'flagIdentifier' => '',
             'fallbackType' => 'strict',
             'enabled' => true,
-            'fallbackLanguageIds' => [],
-            'customValue' => 'a custom value'
+            'fallbackLanguageIds' => [
+                1,
+                2
+            ],
         ];
-        $this->assertEquals($expected, $subject->toArray());
+        $this->assertSame($expected, $subject->toArray());
     }
 }