[BUGFIX] Use GeneralUtility for initialization of PageRenderer 33/62033/3
authorDaniel Goerz <daniel.goerz@posteo.de>
Mon, 21 Oct 2019 09:50:14 +0000 (11:50 +0200)
committerSusanne Moog <look@susi.dev>
Mon, 21 Oct 2019 12:38:50 +0000 (14:38 +0200)
The PageRenderer is set via GeneralUtility::setSingletonInstance()
by TSFE. This circumvents the DI concept and has to be removed in
the long term. It leads to the situation where makeInstance()
returns a different instance of the PageRenderer than the global DI
does.

To restore the functionality we instanciate the PageRenderer with
makeInstance() for now and will follow-up with another patch later
on to remove setSingletonInstance() usages outside of tests.

Resolves: #89445
Releases: master
Change-Id: I08846cb6592f40e5853f1ca9476969d64b7c4cce
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62033
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Susanne Moog <look@susi.dev>
typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
typo3/sysext/extbase/Tests/Unit/Mvc/Controller/ActionControllerTest.php

index b93128b..dc45aef 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
 
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
@@ -191,7 +192,7 @@ class ActionController extends AbstractController
             // asset processing if the View doesn't match, so we don't risk breaking custom Views.
             return;
         }
-        $pageRenderer = $this->objectManager->get(PageRenderer::class);
+        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
         $variables = ['request' => $request, 'arguments' => $this->arguments];
         $headerAssets = $this->view->renderSection('HeaderAssets', $variables, true);
         $footerAssets = $this->view->renderSection('FooterAssets', $variables, true);
index 7cafa63..4785e32 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
 
 use Prophecy\Argument;
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
@@ -25,7 +26,6 @@ use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException;
 use TYPO3\CMS\Extbase\Mvc\Request;
 use TYPO3\CMS\Extbase\Mvc\RequestInterface;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Extbase\Reflection\ClassSchema;
 use TYPO3\CMS\Extbase\Reflection\ReflectionService;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
@@ -520,13 +520,8 @@ class ActionControllerTest extends UnitTestCase
      */
     public function rendersAndAssignsAssetsFromViewIntoPageRenderer($viewMock, $expectedHeader, $expectedFooter)
     {
-        $objectManager = $this->prophesize(ObjectManager::class);
         $pageRenderer = $this->prophesize(PageRenderer::class);
-        if (!$viewMock instanceof FluidTemplateView) {
-            $objectManager->get(Argument::any())->shouldNotBeCalled();
-        } else {
-            $objectManager->get(PageRenderer::class)->willReturn($pageRenderer->reveal());
-        }
+        GeneralUtility::setSingletonInstance(PageRenderer::class, $pageRenderer->reveal());
         if (!empty(trim($expectedHeader ?? ''))) {
             $pageRenderer->addHeaderData($expectedHeader)->shouldBeCalled();
         } else {
@@ -542,9 +537,6 @@ class ActionControllerTest extends UnitTestCase
         $viewProperty = new \ReflectionProperty($subject, 'view');
         $viewProperty->setAccessible(true);
         $viewProperty->setValue($subject, $viewMock);
-        $objectManagerProperty = new \ReflectionProperty($subject, 'objectManager');
-        $objectManagerProperty->setAccessible(true);
-        $objectManagerProperty->setValue($subject, $objectManager->reveal());
 
         $method = new \ReflectionMethod($subject, 'renderAssetsForRequest');
         $method->setAccessible(true);