‪TYPO3CMS  9.5
RenderingContextTest.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 use TYPO3\TestingFramework\Fluid\Unit\Core\Rendering\RenderingContextFixture;
21 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
23 
27 class ‪RenderingContextTest extends UnitTestCase
28 {
34  protected ‪$renderingContext;
35 
36  protected function ‪setUp()
37  {
38  $this->renderingContext = $this->getAccessibleMock(RenderingContextFixture::class, ['dummy']);
39  }
40 
45  {
46  ‪$renderingContext = $this->getMockBuilder(RenderingContextFixture::class)
47  ->setMethods(['setControllerAction', 'setControllerName'])
48  ->getMock();
49  $request = $this->getMockBuilder(Request::class)
50  ->setMethods(['getControllerActionName', 'getControllerSubpackageKey', 'getControllerName'])
51  ->getMock();
52  $request->expects($this->exactly(2))->method('getControllerSubpackageKey')->willReturn('test1');
53  $request->expects($this->once())->method('getControllerName')->willReturn('test2');
54  $controllerContext = $this->getMockBuilder(ControllerContext::class)
55  ->setMethods(['getRequest'])
56  ->getMock();
57  $controllerContext->expects($this->once())->method('getRequest')->willReturn($request);
58  ‪$renderingContext->expects($this->once())->method('setControllerName')->with('test1\\test2');
59  ‪$renderingContext->setControllerContext($controllerContext);
60  }
61 
66  {
67  $templateVariableContainer = $this->createMock(StandardVariableProvider::class);
68  $this->renderingContext->setVariableProvider($templateVariableContainer);
69  $this->assertSame($this->renderingContext->getVariableProvider(), $templateVariableContainer, 'Template Variable Container could not be read out again.');
70  }
71 
76  {
77  $controllerContext = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Controller\ControllerContext::class)
78  ->setMethods(['getRequest'])
79  ->disableOriginalConstructor()
80  ->getMock();
81  $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($this->createMock(Request::class));
82  $this->renderingContext->setControllerContext($controllerContext);
83  $this->assertSame($this->renderingContext->getControllerContext(), $controllerContext);
84  }
85 
90  {
91  $viewHelperVariableContainer = $this->createMock(ViewHelperVariableContainer::class);
92  $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
93  $this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
94  }
95 
102  public function ‪setControllerActionProcessesInputCorrectly($input, $expected)
103  {
104  $subject = new RenderingContextFixture();
105  $request = $this->getMockBuilder(Request::class)->setMethods(['setControllerActionName'])->getMock();
106  $request->expects($this->at(0))->method('setControllerActionName')->with('index');
107  $request->expects($this->at(1))->method('setControllerActionName')->with(lcfirst($expected));
108  $controllerContext = $this->getMockBuilder(ControllerContext::class)->setMethods(['getRequest'])->getMock();
109  $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($request);
110  $subject->setControllerContext($controllerContext);
111  $subject->setControllerAction($input);
112  $this->assertAttributeSame($expected, 'controllerAction', $subject);
113  }
114 
118  public function ‪getControllerActionTestValues()
119  {
120  return [
121  ['default', 'default'],
122  ['default.html', 'default'],
123  ['default.sub.html', 'default'],
124  ['Sub/Default', 'Sub/Default'],
125  ['Sub/Default.html', 'Sub/Default'],
126  ['Sub/Default.sub.html', 'Sub/Default']
127  ];
128  }
129 }
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\$renderingContext
‪TYPO3Fluid Fluid Core Rendering RenderingContextInterface $renderingContext
Definition: RenderingContextTest.php:33
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest
Definition: RenderingContextTest.php:28
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:21
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\setControllerActionProcessesInputCorrectly
‪setControllerActionProcessesInputCorrectly($input, $expected)
Definition: RenderingContextTest.php:101
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\setUp
‪setUp()
Definition: RenderingContextTest.php:35
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering
Definition: RenderingContextTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\getControllerActionTestValues
‪array getControllerActionTestValues()
Definition: RenderingContextTest.php:117
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\viewHelperVariableContainerCanBeReadCorrectly
‪viewHelperVariableContainerCanBeReadCorrectly()
Definition: RenderingContextTest.php:88
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\setControllerContextWithSubpackageKeySetsExpectedControllerContext
‪setControllerContextWithSubpackageKeySetsExpectedControllerContext()
Definition: RenderingContextTest.php:43
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\controllerContextCanBeReadCorrectly
‪controllerContextCanBeReadCorrectly()
Definition: RenderingContextTest.php:74
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:23
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextTest\templateVariableContainerCanBeReadCorrectly
‪templateVariableContainerCanBeReadCorrectly()
Definition: RenderingContextTest.php:64