Skip to content

Commit

Permalink
[BUGFIX] Fix issue with missing UriBuilder in uncached rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jun 16, 2022
1 parent abc0318 commit 0b5b8f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Classes/View/UncacheTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Fluid\Compatibility\TemplateParserBuilder;
Expand Down Expand Up @@ -82,6 +83,10 @@ public function callUserFunction($postUserFunc, $conf, $content)
$request = $this->objectManager->get(Request::class);
$controllerContext->setRequest($request);

$uriBuilder = $this->objectManager->get(UriBuilder::class);
$uriBuilder->setRequest($request);
$controllerContext->setUriBuilder($uriBuilder);

if ($conf['controllerContext']) {
$request->setControllerActionName($conf['controllerContext']['actionName']);
$request->setControllerExtensionName($conf['controllerContext']['extensionName']);
Expand Down
9 changes: 8 additions & 1 deletion Tests/Unit/View/UncacheTemplateViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use FluidTYPO3\Development\AbstractTestCase;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;

Expand All @@ -29,9 +30,12 @@ public function callUserFunctionReturnsEarlyIfPartialEmpty()

$context = $this->getMockBuilder(ControllerContext::class)->getMock();

$uriBuilder = $this->getMockBuilder(UriBuilder::class)->getMock();

$objectManager = $this->getMockBuilder(ObjectManager::class)->setMethods(['get'])->getMock();
$objectManager->expects(self::at(0))->method('get')->with(ControllerContext::class)->willReturn($context);
$objectManager->expects(self::at(1))->method('get')->with(Request::class)->willReturn($request);
$objectManager->expects(self::at(2))->method('get')->with(UriBuilder::class)->willReturn($uriBuilder);

$mock = $this->getMockBuilder($this->getClassName())->setMethods(['prepareContextsForUncachedRendering'])->getMock();
$mock->injectObjectManager($objectManager);
Expand All @@ -50,12 +54,15 @@ public function callUserFunctionReturnsCallsExpectedMethodSequence()

$context = $this->getMockBuilder(ControllerContext::class)->getMock();

$uriBuilder = $this->getMockBuilder(UriBuilder::class)->getMock();

$renderingContext = $this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock();

$objectManager = $this->getMockBuilder(ObjectManager::class)->setMethods(['get'])->getMock();
$objectManager->expects(self::at(0))->method('get')->with(ControllerContext::class)->willReturn($context);
$objectManager->expects(self::at(1))->method('get')->with(Request::class)->willReturn($request);
$objectManager->expects(self::at(2))->method('get')->with(RenderingContext::class)->willReturn($renderingContext);
$objectManager->expects(self::at(2))->method('get')->with(UriBuilder::class)->willReturn($uriBuilder);
$objectManager->expects(self::at(3))->method('get')->with(RenderingContext::class)->willReturn($renderingContext);

$mock = $this->getMockBuilder($this->getClassName())->setMethods(['prepareContextsForUncachedRendering', 'setControllerContext', 'renderPartialUncached'])->getMock();
$mock->injectObjectManager($objectManager);
Expand Down

0 comments on commit 0b5b8f3

Please sign in to comment.