[BUGFIX] Check for string before using strlen 89/24089/2
authorKilian Hann <khann@fconnection.com>
Tue, 24 Sep 2013 13:34:15 +0000 (15:34 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 26 Sep 2013 21:42:28 +0000 (23:42 +0200)
If pi_flexform is converted to an array already, checking via strlen
produces a warning. An additional check via is_string suppresses the
warning.

Resolves: #52091
Resolves: #51684
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Change-Id: I97c41cdedb1afb28e2a9ca39e1d9cfb3921d9f47
Reviewed-on: https://review.typo3.org/24089
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Classes/Configuration/FrontendConfigurationManager.php
typo3/sysext/extbase/Tests/Unit/Configuration/FrontendConfigurationManagerTest.php

index 30f471b..52ae31a 100644 (file)
@@ -169,8 +169,15 @@ class FrontendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abst
         * @return array the framework configuration with overridden data from flexForm
         */
        protected function overrideConfigurationFromFlexForm(array $frameworkConfiguration) {
-               if (strlen($this->contentObject->data['pi_flexform']) > 0) {
-                       $flexFormConfiguration = $this->flexFormService->convertFlexFormContentToArray($this->contentObject->data['pi_flexform']);
+               $flexFormConfiguration = $this->contentObject->data['pi_flexform'];
+               if (is_string($flexFormConfiguration)) {
+                       if (strlen($flexFormConfiguration) > 0) {
+                               $flexFormConfiguration = $this->flexFormService->convertFlexFormContentToArray($flexFormConfiguration);
+                       } else {
+                               $flexFormConfiguration = array();
+                       }
+               }
+               if (is_array($flexFormConfiguration) && count($flexFormConfiguration)) {
                        $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'settings');
                        $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'persistence');
                        $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'view');
@@ -247,4 +254,4 @@ class FrontendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abst
        }
 }
 
-?>
\ No newline at end of file
+?>
index 3f2812a..ff904d5 100644 (file)
@@ -446,19 +446,54 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
 
        /**
         * @test
-        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
         */
-       public function overrideConfigurationFromFlexFormOverridesCorrectly() {
+       public function overrideConfigurationFromFlexFormChecksForDataIsString() {
                /** @var $flexFormService \TYPO3\CMS\Extbase\Service\FlexFormService|\PHPUnit_Framework_MockObject_MockObject */
                $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
-               $flexFormService->expects($this->any())->method('convertFlexFormContentToArray')->will($this->returnValue(array(
+               $flexFormService->expects($this->once())->method('convertFlexFormContentToArray')->will($this->returnValue(array(
                        'persistence' => array(
                                'storagePid' => '0,1,2,3'
                        )
                )));
 
                $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
-               $this->mockContentObject->data = array('pi_flexform' => 'foo');
+               $this->mockContentObject->data = array('pi_flexform' => '<XML_ARRAY>');
+
+               $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
+               $this->assertSame(
+                       array('persistence' => array('storagePid' => '0,1,2,3')),
+                       $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function overrideConfigurationFromFlexFormChecksForDataIsStringAndEmpty() {
+               /** @var $flexFormService \TYPO3\CMS\Extbase\Service\FlexFormService|\PHPUnit_Framework_MockObject_MockObject */
+               $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
+               $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
+
+               $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
+               $this->mockContentObject->data = array('pi_flexform' => '');
+
+               $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
+               $this->assertSame(
+                       array('persistence' => array('storagePid' => '98')),
+                       $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function overrideConfigurationFromFlexFormChecksForDataIsArray() {
+               /** @var $flexFormService \TYPO3\CMS\Extbase\Service\FlexFormService|\PHPUnit_Framework_MockObject_MockObject */
+               $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
+               $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
+
+               $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
+               $this->mockContentObject->data = array('pi_flexform' => array('persistence' => array('storagePid' => '0,1,2,3')));
 
                $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
                $this->assertSame(
@@ -469,6 +504,24 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
 
        /**
         * @test
+        */
+       public function overrideConfigurationFromFlexFormChecksForDataIsArrayAndEmpty() {
+               /** @var $flexFormService \TYPO3\CMS\Extbase\Service\FlexFormService|\PHPUnit_Framework_MockObject_MockObject */
+               $flexFormService = $this->getMock('TYPO3\CMS\Extbase\Service\FlexFormService', array('convertFlexFormContentToArray'));
+               $flexFormService->expects($this->never())->method('convertFlexFormContentToArray');
+
+               $this->frontendConfigurationManager->_set('flexFormService', $flexFormService);
+               $this->mockContentObject->data = array('pi_flexform' => array());
+
+               $frameworkConfiguration = array('persistence' => array('storagePid' => '98'));
+               $this->assertSame(
+                       array('persistence' => array('storagePid' => '98')),
+                       $this->frontendConfigurationManager->_call('overrideConfigurationFromFlexForm', $frameworkConfiguration)
+               );
+       }
+
+       /**
+        * @test
         * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
         */
        public function overrideConfigurationFromPluginOverridesCorrectly() {
@@ -536,4 +589,4 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
        }
 }
 
-?>
\ No newline at end of file
+?>