TYPO3 CMS  TYPO3_8-7
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  */
20 
24 class RenderingContextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
31  protected $renderingContext;
32 
33  protected function setUp()
34  {
35  $this->renderingContext = $this->getAccessibleMock(RenderingContextFixture::class, ['dummy']);
36  }
37 
42  {
43  $this->renderingContext->_set('objectManager', 'test');
44  $this->assertEquals('test', $this->renderingContext->getObjectManager());
45  }
46 
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 
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 
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 
96  {
97  $viewHelperVariableContainer = $this->createMock(ViewHelperVariableContainer::class);
98  $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
99  $this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
100  }
101 
108  public function setControllerActionProcessesInputCorrectly($input, $expected)
109  {
110  $subject = new RenderingContextFixture();
111  $request = $this->getMockBuilder(Request::class)->setMethods(['setControllerActionName'])->getMock();
112  $request->expects($this->at(0))->method('setControllerActionName')->with('index');
113  $request->expects($this->at(1))->method('setControllerActionName')->with(lcfirst($expected));
114  $controllerContext = $this->getMockBuilder(ControllerContext::class)->setMethods(['getRequest'])->getMock();
115  $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($request);
116  $subject->setControllerContext($controllerContext);
117  $subject->setControllerAction($input);
118  $this->assertAttributeSame($expected, 'controllerAction', $subject);
119  }
120 
125  {
126  return [
127  ['default', 'default'],
128  ['default.html', 'default'],
129  ['default.sub.html', 'default'],
130  ['Sub/Default', 'Sub/Default'],
131  ['Sub/Default.html', 'Sub/Default'],
132  ['Sub/Default.sub.html', 'Sub/Default']
133  ];
134  }
135 }