‪TYPO3CMS  10.4
RenderingContextTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
24 
28 class ‪RenderingContextTest extends UnitTestCase
29 {
35  protected ‪$renderingContext;
36 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $this->renderingContext = $this->getMockBuilder(RenderingContext::class)
41  ->addMethods(['dummy'])
42  ->disableOriginalConstructor()
43  ->getMock();
44  }
45 
50  {
51  ‪$renderingContext = $this->getMockBuilder(RenderingContext::class)
52  ->onlyMethods(['setControllerAction', 'setControllerName'])
53  ->disableOriginalConstructor()
54  ->getMock();
55  $request = $this->getMockBuilder(Request::class)
56  ->setMethods(['getControllerActionName', 'getControllerSubpackageKey', 'getControllerName'])
57  ->getMock();
58  $request->expects(self::exactly(2))->method('getControllerSubpackageKey')->willReturn('test1');
59  $request->expects(self::once())->method('getControllerName')->willReturn('test2');
60  $controllerContext = $this->getMockBuilder(ControllerContext::class)
61  ->setMethods(['getRequest'])
62  ->getMock();
63  $controllerContext->expects(self::once())->method('getRequest')->willReturn($request);
64  ‪$renderingContext->expects(self::once())->method('setControllerName')->with('test1\\test2');
65  ‪$renderingContext->‪setControllerContext($controllerContext);
66  }
67 
72  {
73  $templateVariableContainer = $this->createMock(StandardVariableProvider::class);
74  $this->renderingContext->setVariableProvider($templateVariableContainer);
75  self::assertSame($this->renderingContext->getVariableProvider(), $templateVariableContainer, 'Template Variable Container could not be read out again.');
76  }
77 
82  {
83  $controllerContext = $this->getMockBuilder(ControllerContext::class)
84  ->disableOriginalConstructor()
85  ->getMock();
86  $controllerContext->expects(self::atLeastOnce())->method('getRequest')->willReturn($this->createMock(Request::class));
87  $this->renderingContext->setControllerContext($controllerContext);
88  self::assertSame($this->renderingContext->getControllerContext(), $controllerContext);
89  }
90 
95  {
96  $viewHelperVariableContainer = $this->createMock(ViewHelperVariableContainer::class);
97  $this->renderingContext->setViewHelperVariableContainer($viewHelperVariableContainer);
98  self::assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
99  }
100 
107  public function ‪setControllerActionProcessesInputCorrectly($input, $expected)
108  {
109  $subject = $this->getMockBuilder(RenderingContext::class)
110  ->addMethods(['dummy'])
111  ->disableOriginalConstructor()
112  ->getMock();
113  $request = $this->getMockBuilder(Request::class)->getMock();
114  $request->expects(self::exactly(2))->method('setControllerActionName')->with(lcfirst($expected));
115  $request->expects(self::exactly(2))->method('getControllerActionName')->willReturn(lcfirst($expected));
116  $controllerContext = $this->getMockBuilder(ControllerContext::class)->setMethods(['getRequest'])->getMock();
117  $controllerContext->expects(self::atLeastOnce())->method('getRequest')->willReturn($request);
118  $subject->setControllerContext($controllerContext);
119  $subject->setControllerAction($input);
120  self::assertSame(lcfirst($expected), $subject->getControllerAction());
121  }
122 
126  public function ‪getControllerActionTestValues()
127  {
128  return [
129  ['default', 'default'],
130  ['default.html', 'default'],
131  ['default.sub.html', 'default'],
132  ['Sub/Default', 'Sub/Default'],
133  ['Sub/Default.html', 'Sub/Default'],
134  ['Sub/Default.sub.html', 'Sub/Default']
135  ];
136  }
137 }
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\$renderingContext
‪RenderingContext $renderingContext
Definition: RenderingContextTest.php:34
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest
Definition: RenderingContextTest.php:29
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\setControllerActionProcessesInputCorrectly
‪setControllerActionProcessesInputCorrectly($input, $expected)
Definition: RenderingContextTest.php:106
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\setUp
‪setUp()
Definition: RenderingContextTest.php:36
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering
Definition: RenderingContextTest.php:16
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\getControllerActionTestValues
‪array getControllerActionTestValues()
Definition: RenderingContextTest.php:125
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerContext
‪setControllerContext(ControllerContext $controllerContext)
Definition: RenderingContext.php:199
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\viewHelperVariableContainerCanBeReadCorrectly
‪viewHelperVariableContainerCanBeReadCorrectly()
Definition: RenderingContextTest.php:93
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\setControllerContextWithSubpackageKeySetsExpectedControllerContext
‪setControllerContextWithSubpackageKeySetsExpectedControllerContext()
Definition: RenderingContextTest.php:48
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\controllerContextCanBeReadCorrectly
‪controllerContextCanBeReadCorrectly()
Definition: RenderingContextTest.php:80
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:39
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\templateVariableContainerCanBeReadCorrectly
‪templateVariableContainerCanBeReadCorrectly()
Definition: RenderingContextTest.php:70