[BUGFIX] Don't call mergeRecursiveWithOverrule with null argument 19/59719/4
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 18 Feb 2019 13:56:14 +0000 (14:56 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 23 Feb 2019 17:50:43 +0000 (18:50 +0100)
During the removal of deprecated code in Extbase, a bug has been
introduced which is fixed with this patch.

Releases: master
Resolves: #87732
Relates: #87269
Change-Id: I5739acf64c65ad5eb79bcf16c6e7962366af59f6
Reviewed-on: https://review.typo3.org/c/59719
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Classes/Service/ExtensionService.php
typo3/sysext/extbase/Tests/Unit/Service/ExtensionServiceTest.php

index 4f006e0..d9129c2 100644 (file)
@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Extbase\Service;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
-use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 
@@ -246,9 +245,8 @@ class ExtensionService implements \TYPO3\CMS\Core\SingletonInterface
     {
         // Default behaviour
         $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName);
-        if (isset($settings['view']['formatToPageTypeMapping']) && is_array($settings['view']['formatToPageTypeMapping'])) {
-            ArrayUtility::mergeRecursiveWithOverrule($formatToPageTypeMapping, $settings['view']['formatToPageTypeMapping']);
-        }
+        $formatToPageTypeMapping = $settings['view']['formatToPageTypeMapping'] ?? [];
+        $formatToPageTypeMapping = is_array($formatToPageTypeMapping) ? $formatToPageTypeMapping : [];
         return $formatToPageTypeMapping[$format] ?? 0;
     }
 }
index 21d1675..c5ed19b 100644 (file)
@@ -23,6 +23,8 @@ use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Exception;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -402,4 +404,44 @@ class ExtensionServiceTest extends UnitTestCase
         $actualResult = $this->extensionService->getDefaultActionNameByPluginAndController('SomeOtherExtensionName', 'SecondPlugin', 'SecondControllerName');
         $this->assertEquals($expectedResult, $actualResult);
     }
+
+    /**
+     * @test
+     */
+    public function getTargetPageTypeByFormatReturnsZeroIfNoMappingIsSet(): void
+    {
+        $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
+        $configurationManagerProphecy->getConfiguration(
+            ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
+            'extension'
+        )->willReturn([]);
+        $this->extensionService->injectConfigurationManager($configurationManagerProphecy->reveal());
+
+        $result = $this->extensionService->getTargetPageTypeByFormat('extension', 'json');
+
+        $this->assertSame(0, $result);
+    }
+
+    /**
+     * @test
+     */
+    public function getTargetPageTypeByFormatReturnsMappedPageTypeFromConfiguration(): void
+    {
+        $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
+        $configurationManagerProphecy->getConfiguration(
+            ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
+            'extension'
+        )->willReturn([
+            'view' => [
+                'formatToPageTypeMapping' => [
+                    'json' => 111
+                ]
+            ]
+        ]);
+        $this->extensionService->injectConfigurationManager($configurationManagerProphecy->reveal());
+
+        $result = $this->extensionService->getTargetPageTypeByFormat('extension', 'json');
+
+        $this->assertSame(111, $result);
+    }
 }