TYPO3 CMS  TYPO3_8-7
WidgetRequestBuilderTest.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 
20 class WidgetRequestBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
26 
30  protected $mockObjectManager;
31 
35  protected $mockWidgetRequest;
36 
41 
45  protected $mockWidgetContext;
46 
47  protected function setUp()
48  {
49  $this->widgetRequestBuilder = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder::class, ['setArgumentsFromRawRequestData']);
50  $this->mockWidgetRequest = $this->createMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
51  $this->mockObjectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
52  $this->mockObjectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)->will($this->returnValue($this->mockWidgetRequest));
53  $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager);
54  $this->mockWidgetContext = $this->createMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
55  $this->mockAjaxWidgetContextHolder = $this->createMock(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class);
56  $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder);
57  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
58  }
59 
63  public function buildSetsRequestUri()
64  {
65  $requestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
66  $this->mockWidgetRequest->expects($this->once())->method('setRequestURI')->with($requestUri);
67  $this->widgetRequestBuilder->build();
68  }
69 
73  public function buildSetsBaseUri()
74  {
75  $baseUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
76  $this->mockWidgetRequest->expects($this->once())->method('setBaseURI')->with($baseUri);
77  $this->widgetRequestBuilder->build();
78  }
79 
83  public function buildSetsRequestMethod()
84  {
85  $_SERVER['REQUEST_METHOD'] = 'POST';
86  $this->mockWidgetRequest->expects($this->once())->method('setMethod')->with('POST');
87  $this->widgetRequestBuilder->build();
88  }
89 
94  {
95  $_SERVER['REQUEST_METHOD'] = 'POST';
96  $_GET = ['get' => 'foo'];
97  $_POST = ['post' => 'bar'];
98  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_POST);
99  $this->widgetRequestBuilder->build();
100  }
101 
106  {
107  $_SERVER['REQUEST_METHOD'] = 'GET';
108  $_GET = ['get' => 'foo'];
109  $_POST = ['post' => 'bar'];
110  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_GET);
111  $this->widgetRequestBuilder->build();
112  }
113 
118  {
119  $_GET = ['action' => 'myAction'];
120  $this->mockWidgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction');
121  $this->widgetRequestBuilder->build();
122  }
123 
127  public function buildSetsWidgetContext()
128  {
129  $_GET = ['fluid-widget-id' => '123'];
130  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext));
131  $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext);
132  $this->widgetRequestBuilder->build();
133  }
134 
138  public function buildReturnsRequest()
139  {
140  $expected = $this->mockWidgetRequest;
141  $actual = $this->widgetRequestBuilder->build();
142  $this->assertSame($expected, $actual);
143  }
144 }