[TASK] Shorten the extend class in all unit tests
[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 TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
21
22 /**
23 * Test case
24 */
25 class RenderingContextTest extends UnitTestCase
26 {
27 /**
28 * Parsing state
29 *
30 * @var \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface
31 */
32 protected $renderingContext;
33
34 protected function setUp()
35 {
36 $this->renderingContext = $this->getAccessibleMock(RenderingContextFixture::class, ['dummy']);
37 }
38
39 /**
40 * @test
41 */
42 public function setControllerContextWithSubpackageKeySetsExpectedControllerContext()
43 {
44 $renderingContext = $this->getMockBuilder(RenderingContextFixture::class)
45 ->setMethods(['setControllerAction', 'setControllerName'])
46 ->getMock();
47 $request = $this->getMockBuilder(Request::class)
48 ->setMethods(['getControllerActionName', 'getControllerSubpackageKey', 'getControllerName'])
49 ->getMock();
50 $request->expects($this->exactly(2))->method('getControllerSubpackageKey')->willReturn('test1');
51 $request->expects($this->once())->method('getControllerName')->willReturn('test2');
52 $controllerContext = $this->getMockBuilder(ControllerContext::class)
53 ->setMethods(['getRequest'])
54 ->getMock();
55 $controllerContext->expects($this->once())->method('getRequest')->willReturn($request);
56 $renderingContext->expects($this->once())->method('setControllerName')->with('test1\\test2');
57 $renderingContext->setControllerContext($controllerContext);
58 }
59
60 /**
61 * @test
62 */
63 public function templateVariableContainerCanBeReadCorrectly()
64 {
65 $templateVariableContainer = $this->createMock(StandardVariableProvider::class);
66 $this->renderingContext->setVariableProvider($templateVariableContainer);
67 $this->assertSame($this->renderingContext->getVariableProvider(), $templateVariableContainer, 'Template Variable Container could not be read out again.');
68 }
69
70 /**
71 * @test
72 */
73 public function controllerContextCanBeReadCorrectly()
74 {
75 $controllerContext = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class)
76 ->setMethods(['getRequest'])
77 ->disableOriginalConstructor()
78 ->getMock();
79 $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($this->createMock(Request::class));
80 $this->renderingContext->setControllerContext($controllerContext);
81 $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext);
82 }
83
84 /**
85 * @test
86 */
87 public function viewHelperVariableContainerCanBeReadCorrectly()
88 {
89 $viewHelperVariableContainer = $this->createMock(ViewHelperVariableContainer::class);
90 $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
91 $this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
92 }
93
94 /**
95 * @test
96 * @dataProvider getControllerActionTestValues
97 * @param string $input
98 * @param string $expected
99 */
100 public function setControllerActionProcessesInputCorrectly($input, $expected)
101 {
102 $subject = new RenderingContextFixture();
103 $request = $this->getMockBuilder(Request::class)->setMethods(['setControllerActionName'])->getMock();
104 $request->expects($this->at(0))->method('setControllerActionName')->with('index');
105 $request->expects($this->at(1))->method('setControllerActionName')->with(lcfirst($expected));
106 $controllerContext = $this->getMockBuilder(ControllerContext::class)->setMethods(['getRequest'])->getMock();
107 $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($request);
108 $subject->setControllerContext($controllerContext);
109 $subject->setControllerAction($input);
110 $this->assertAttributeSame($expected, 'controllerAction', $subject);
111 }
112
113 /**
114 * @return array
115 */
116 public function getControllerActionTestValues()
117 {
118 return [
119 ['default', 'default'],
120 ['default.html', 'default'],
121 ['default.sub.html', 'default'],
122 ['Sub/Default', 'Sub/Default'],
123 ['Sub/Default.html', 'Sub/Default'],
124 ['Sub/Default.sub.html', 'Sub/Default']
125 ];
126 }
127 }