[!!!][TASK] Remove deprecated code from ext:fluid
[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\TestingFramework\Core\Unit\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 setControllerContextWithSubpackageKeySetsExpectedControllerContext()
42 {
43 $renderingContext = $this->getMockBuilder(RenderingContextFixture::class)
44 ->setMethods(['setControllerAction', 'setControllerName'])
45 ->getMock();
46 $request = $this->getMockBuilder(Request::class)
47 ->setMethods(['getControllerActionName', 'getControllerSubpackageKey', 'getControllerName'])
48 ->getMock();
49 $request->expects($this->exactly(2))->method('getControllerSubpackageKey')->willReturn('test1');
50 $request->expects($this->once())->method('getControllerName')->willReturn('test2');
51 $controllerContext = $this->getMockBuilder(ControllerContext::class)
52 ->setMethods(['getRequest'])
53 ->getMock();
54 $controllerContext->expects($this->once())->method('getRequest')->willReturn($request);
55 $renderingContext->expects($this->once())->method('setControllerName')->with('test1\\test2');
56 $renderingContext->setControllerContext($controllerContext);
57 }
58
59 /**
60 * @test
61 */
62 public function templateVariableContainerCanBeReadCorrectly()
63 {
64 $templateVariableContainer = $this->createMock(StandardVariableProvider::class);
65 $this->renderingContext->setVariableProvider($templateVariableContainer);
66 $this->assertSame($this->renderingContext->getVariableProvider(), $templateVariableContainer, 'Template Variable Container could not be read out again.');
67 }
68
69 /**
70 * @test
71 */
72 public function controllerContextCanBeReadCorrectly()
73 {
74 $controllerContext = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class)
75 ->setMethods(['getRequest'])
76 ->disableOriginalConstructor()
77 ->getMock();
78 $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($this->createMock(Request::class));
79 $this->renderingContext->setControllerContext($controllerContext);
80 $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext);
81 }
82
83 /**
84 * @test
85 */
86 public function viewHelperVariableContainerCanBeReadCorrectly()
87 {
88 $viewHelperVariableContainer = $this->createMock(ViewHelperVariableContainer::class);
89 $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
90 $this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
91 }
92
93 /**
94 * @test
95 * @dataProvider getControllerActionTestValues
96 * @param string $input
97 * @param string $expected
98 */
99 public function setControllerActionProcessesInputCorrectly($input, $expected)
100 {
101 $subject = new RenderingContextFixture();
102 $request = $this->getMockBuilder(Request::class)->setMethods(['setControllerActionName'])->getMock();
103 $request->expects($this->at(0))->method('setControllerActionName')->with('index');
104 $request->expects($this->at(1))->method('setControllerActionName')->with(lcfirst($expected));
105 $controllerContext = $this->getMockBuilder(ControllerContext::class)->setMethods(['getRequest'])->getMock();
106 $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($request);
107 $subject->setControllerContext($controllerContext);
108 $subject->setControllerAction($input);
109 $this->assertAttributeSame($expected, 'controllerAction', $subject);
110 }
111
112 /**
113 * @return array
114 */
115 public function getControllerActionTestValues()
116 {
117 return [
118 ['default', 'default'],
119 ['default.html', 'default'],
120 ['default.sub.html', 'default'],
121 ['Sub/Default', 'Sub/Default'],
122 ['Sub/Default.html', 'Sub/Default'],
123 ['Sub/Default.sub.html', 'Sub/Default']
124 ];
125 }
126 }