[TASK] Remove usages of getTemplateVariableContainer
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Rendering / RenderingContextTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
17 use TYPO3\CMS\Extbase\Mvc\Request;
18 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
20
21 /**
22 * Test case
23 */
24 class RenderingContextTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
25 {
26 /**
27 * Parsing state
28 *
29 * @var \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface
30 */
31 protected $renderingContext;
32
33 protected function setUp()
34 {
35 $this->renderingContext = $this->getAccessibleMock(RenderingContextFixture::class, ['dummy']);
36 }
37
38 /**
39 * @test
40 */
41 public function getObjectManagerReturnsObjectManagerPropertyValue()
42 {
43 $this->renderingContext->_set('objectManager', 'test');
44 $this->assertEquals('test', $this->renderingContext->getObjectManager());
45 }
46
47 /**
48 * @test
49 */
50 public function setControllerContextWithSubpackageKeySetsExpectedControllerContext()
51 {
52 $renderingContext = $this->getMockBuilder(RenderingContextFixture::class)
53 ->setMethods(['setControllerAction', 'setControllerName'])
54 ->getMock();
55 $request = $this->getMockBuilder(Request::class)
56 ->setMethods(['getControllerActionName', 'getControllerSubpackageKey', 'getControllerName'])
57 ->getMock();
58 $request->expects($this->exactly(2))->method('getControllerSubpackageKey')->willReturn('test1');
59 $request->expects($this->once())->method('getControllerName')->willReturn('test2');
60 $controllerContext = $this->getMockBuilder(ControllerContext::class)
61 ->setMethods(['getRequest'])
62 ->getMock();
63 $controllerContext->expects($this->once())->method('getRequest')->willReturn($request);
64 $renderingContext->expects($this->once())->method('setControllerName')->with('test1\\test2');
65 $renderingContext->setControllerContext($controllerContext);
66 }
67
68 /**
69 * @test
70 */
71 public function templateVariableContainerCanBeReadCorrectly()
72 {
73 $templateVariableContainer = $this->createMock(StandardVariableProvider::class);
74 $this->renderingContext->setVariableProvider($templateVariableContainer);
75 $this->assertSame($this->renderingContext->getVariableProvider(), $templateVariableContainer, 'Template Variable Container could not be read out again.');
76 }
77
78 /**
79 * @test
80 */
81 public function controllerContextCanBeReadCorrectly()
82 {
83 $controllerContext = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class)
84 ->setMethods(['getRequest'])
85 ->disableOriginalConstructor()
86 ->getMock();
87 $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($this->createMock(Request::class));
88 $this->renderingContext->setControllerContext($controllerContext);
89 $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext);
90 }
91
92 /**
93 * @test
94 */
95 public function viewHelperVariableContainerCanBeReadCorrectly()
96 {
97 $viewHelperVariableContainer = $this->createMock(ViewHelperVariableContainer::class);
98 $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
99 $this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
100 }
101 }