[TASK] Make CObjectViewHelperTest notice free 25/56225/5
authorJan Helke <typo3@helke.de>
Fri, 16 Mar 2018 14:12:51 +0000 (15:12 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 16 Mar 2018 19:21:56 +0000 (20:21 +0100)
Releases: master
Resolves: #84345
Change-Id: I845ff3db453eee41fbcaf46f76efdeb406c51c53
Reviewed-on: https://review.typo3.org/56225
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/CObjectViewHelperTest.php

index 012b72a..f04a1a3 100644 (file)
@@ -96,6 +96,7 @@ class CObjectViewHelper extends AbstractViewHelper
      */
     public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
+        $content = '';
         $data = $renderChildrenClosure();
         $typoscriptObjectPath = $arguments['typoscriptObjectPath'];
         $currentValueKey = $arguments['currentValueKey'];
@@ -120,13 +121,18 @@ class CObjectViewHelper extends AbstractViewHelper
         $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath);
         $lastSegment = array_pop($pathSegments);
         $setup = static::getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
-        foreach ($pathSegments as $segment) {
-            if (!array_key_exists($segment . '.', $setup)) {
-                throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist', 1253191023);
+        if (!empty($pathSegments) && \is_array($pathSegments)) {
+            foreach ($pathSegments as $segment) {
+                if (!array_key_exists($segment . '.', $setup)) {
+                    throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
+                        'TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist',
+                        1253191023
+                    );
+                }
+                $setup = $setup[$segment . '.'];
             }
-            $setup = $setup[$segment . '.'];
+            $content = $contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
         }
-        $content = $contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
         if (TYPO3_MODE === 'BE') {
             static::resetFrontendEnvironment();
         }
index 3984bd8..6e695b2 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types=1);
 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
 
 /*
@@ -28,11 +29,6 @@ use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
 class CObjectViewHelperTest extends ViewHelperBaseTestcase
 {
     /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
-    /**
      * @var CObjectViewHelper
      */
     protected $viewHelper;
@@ -114,6 +110,7 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
                 'typoscriptObjectPath' => 'test.path',
             ]
         );
+
         $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
         $this->expectExceptionCode(1253191023);
         $this->viewHelper->initializeArgumentsAndRender();
@@ -127,7 +124,7 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         $this->setArgumentsUnderTest(
             $this->viewHelper,
             [
-                'typoscriptObjectPath' => 'test',
+                'typoscriptObjectPath' => 'plugin.test',
                 'data' => 'foo',
                 'table' => 'table',
             ]
@@ -139,8 +136,12 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         ];
 
         $configArray = [
-            'test' => 'TEXT',
-            'test.' => $subConfigArray,
+            'olugin' => 'COA',
+            'plugin.' => [
+                'test' => 'TEXT',
+                'test.' => $subConfigArray,
+
+            ]
         ];
 
         $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
@@ -152,7 +153,7 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         $objectManager = $this->prophesize(ObjectManager::class);
         $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
         GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
-        $GLOBALS['TSFE'] = (object) ['cObj' => $this->contentObjectRenderer->reveal()];
+        $GLOBALS['TSFE'] = (object)['cObj' => $this->contentObjectRenderer->reveal()];
 
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $expectedResult = 'Hello World';
@@ -170,6 +171,6 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         $objectManager = $this->prophesize(ObjectManager::class);
         $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
         GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
-        $GLOBALS['TSFE'] = (object) ['cObj' => $this->contentObjectRenderer->reveal()];
+        $GLOBALS['TSFE'] = (object)['cObj' => $this->contentObjectRenderer->reveal()];
     }
 }