[BUGFIX] Avoid overwriting page context in TSFE->cObj by f:cObject 61/58661/11
authorThorben Nissen <thorben.nissen@kapp-hamburg.de>
Fri, 19 Oct 2018 09:03:58 +0000 (11:03 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 7 Dec 2018 22:12:30 +0000 (23:12 +0100)
Change `CObjectViewHelper::getContentObjectRenderer` to return a new
instance of `ContentObjectRenderer` instead of returning a reference to
`TSFE->cObj`.

Change unit test and add prepared instance of `ContentObjectRenderer`
to `GeneralUtility` via `addInstance` method.

Resolves: #86979
Releases: master
Change-Id: Ibdb8fd1d974a525f3583929a743447a8650ca1ab
Reviewed-on: https://review.typo3.org/58661
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/CObjectViewHelperTest.php

index e2332ff..ad8d021 100644 (file)
@@ -156,7 +156,10 @@ class CObjectViewHelper extends AbstractViewHelper
      */
     protected static function getContentObjectRenderer()
     {
-        return $GLOBALS['TSFE']->cObj;
+        return GeneralUtility::makeInstance(
+            ContentObjectRenderer::class,
+            $GLOBALS['TSFE'] ?? GeneralUtility::makeInstance(TypoScriptFrontendController::class, null, 0, 0)
+        );
     }
 
     /**
index a411c24..6eb19c6 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
 
 /**
@@ -202,6 +203,7 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
      */
     public function renderReturnsSimpleTypoScriptValue(string $objectPath, array $configArray, array $subConfigArray)
     {
+        $this->stubBaseDependencies();
         $this->setArgumentsUnderTest(
             $this->viewHelper,
             [
@@ -219,8 +221,8 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
 
         $objectManager = $this->prophesize(ObjectManager::class);
         $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
+        GeneralUtility::addInstance(ContentObjectRenderer::class, $this->contentObjectRenderer->reveal());
         GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
-        $GLOBALS['TSFE'] = (object)['cObj' => $this->contentObjectRenderer->reveal()];
 
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $expectedResult = 'Hello World';
@@ -238,6 +240,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'] = $this->getAccessibleMock(TypoScriptFrontendController::class, ['initCaches'], [], '', false);
     }
 }