‪TYPO3CMS  9.5
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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪WidgetRequestBuilderTest extends UnitTestCase
29 {
33  protected ‪$widgetRequestBuilder;
34 
38  protected ‪$mockObjectManager;
39 
43  protected ‪$mockWidgetRequest;
44 
49 
54 
58  protected function ‪setUp()
59  {
60  $this->widgetRequestBuilder = $this->getAccessibleMock(WidgetRequestBuilder::class, ['setArgumentsFromRawRequestData']);
61  $this->mockWidgetRequest = $this->createMock(WidgetRequest::class);
62  $this->mockObjectManager = $this->createMock(ObjectManagerInterface::class);
63  $this->mockObjectManager->expects($this->once())->method('get')->with(WidgetRequest::class)->will($this->returnValue($this->mockWidgetRequest));
64  $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager);
65  $this->mockWidgetContext = $this->createMock(WidgetContext::class);
66  $this->mockAjaxWidgetContextHolder = $this->createMock(AjaxWidgetContextHolder::class);
67  $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder);
68  }
69 
74  {
75  $_SERVER = [
76  'REMOTE_ADDR' => 'foo',
77  'SSL_SESSION_ID' => 'foo',
78  'REQUEST_URI' => 'foo',
79  'ORIG_SCRIPT_NAME' => 'foo',
80  'REQUEST_METHOD' => 'foo'
81  ];
82  $_GET = [
83  'not-the-fluid-widget-id' => 'foo'
84  ];
85  $this->expectException(\InvalidArgumentException::class);
86  $this->expectExceptionCode(1521190675);
87  $this->widgetRequestBuilder->build();
88  }
89 
93  public function ‪buildSetsRequestUri()
94  {
95  $_SERVER = [
96  'REMOTE_ADDR' => 'foo',
97  'SSL_SESSION_ID' => 'foo',
98  'REQUEST_URI' => 'foo',
99  'ORIG_SCRIPT_NAME' => 'foo',
100  'REQUEST_METHOD' => 'foo'
101  ];
102  $_GET = [
103  'fluid-widget-id' => 'foo'
104  ];
105  $requestUri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
106  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
107  $this->mockWidgetRequest->expects($this->once())->method('setRequestURI')->with($requestUri);
108  $this->widgetRequestBuilder->build();
109  }
110 
114  public function ‪buildSetsBaseUri()
115  {
116  $_SERVER = [
117  'REMOTE_ADDR' => 'foo',
118  'SSL_SESSION_ID' => 'foo',
119  'REQUEST_URI' => 'foo',
120  'ORIG_SCRIPT_NAME' => 'foo',
121  'REQUEST_METHOD' => 'foo'
122  ];
123  $_GET = [
124  'fluid-widget-id' => 'foo'
125  ];
126  $baseUri = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
127  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
128  $this->mockWidgetRequest->expects($this->once())->method('setBaseURI')->with($baseUri);
129  $this->widgetRequestBuilder->build();
130  }
131 
135  public function ‪buildSetsRequestMethod()
136  {
137  $_SERVER = [
138  'REMOTE_ADDR' => 'foo',
139  'SSL_SESSION_ID' => 'foo',
140  'REQUEST_URI' => 'foo',
141  'ORIG_SCRIPT_NAME' => 'foo',
142  'REQUEST_METHOD' => 'POST'
143  ];
144  $_GET = [
145  'fluid-widget-id' => 'foo'
146  ];
147  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
148  $this->mockWidgetRequest->expects($this->once())->method('setMethod')->with('POST');
149  $this->widgetRequestBuilder->build();
150  }
151 
155  public function ‪buildSetsPostArgumentsFromRequest()
156  {
157  $_SERVER = [
158  'REMOTE_ADDR' => 'foo',
159  'SSL_SESSION_ID' => 'foo',
160  'REQUEST_URI' => 'foo',
161  'ORIG_SCRIPT_NAME' => 'foo',
162  'REQUEST_METHOD' => 'POST'
163  ];
164  $_GET = [
165  'get' => 'foo',
166  'fluid-widget-id' => 'foo'
167  ];
168  $_POST = [
169  'post' => 'bar'
170  ];
171  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
172  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_POST);
173  $this->widgetRequestBuilder->build();
174  }
175 
179  public function ‪buildSetsGetArgumentsFromRequest()
180  {
181  $_SERVER = [
182  'REMOTE_ADDR' => 'foo',
183  'SSL_SESSION_ID' => 'foo',
184  'REQUEST_URI' => 'foo',
185  'ORIG_SCRIPT_NAME' => 'foo',
186  'REQUEST_METHOD' => 'GET'
187  ];
188  $_GET = [
189  'get' => 'foo',
190  'fluid-widget-id' => 'foo'
191  ];
192  $_POST = [
193  'post' => 'bar'
194  ];
195  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
196  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_GET);
197  $this->widgetRequestBuilder->build();
198  }
199 
204  {
205  $_SERVER = [
206  'REMOTE_ADDR' => 'foo',
207  'SSL_SESSION_ID' => 'foo',
208  'REQUEST_URI' => 'foo',
209  'ORIG_SCRIPT_NAME' => 'foo',
210  'REQUEST_METHOD' => 'foo'
211  ];
212  $_GET = [
213  'action' => 'myAction',
214  'fluid-widget-id' => 'foo'
215  ];
216  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
217  $this->mockWidgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction');
218  $this->widgetRequestBuilder->build();
219  }
220 
224  public function ‪buildSetsWidgetContext()
225  {
226  $_SERVER = [
227  'REMOTE_ADDR' => 'foo',
228  'SSL_SESSION_ID' => 'foo',
229  'REQUEST_URI' => 'foo',
230  'ORIG_SCRIPT_NAME' => 'foo',
231  'REQUEST_METHOD' => 'foo'
232  ];
233  $_GET = [
234  'fluid-widget-id' => '123'
235  ];
236  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
237  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext));
238  $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext);
239  $this->widgetRequestBuilder->build();
240  }
241 
245  public function ‪buildReturnsRequest()
246  {
247  $_SERVER = [
248  'REMOTE_ADDR' => 'foo',
249  'SSL_SESSION_ID' => 'foo',
250  'REQUEST_URI' => 'foo',
251  'ORIG_SCRIPT_NAME' => 'foo',
252  'REQUEST_METHOD' => 'foo'
253  ];
254  $_GET = [
255  'fluid-widget-id' => 'foo'
256  ];
257  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
258  $expected = ‪$this->mockWidgetRequest;
259  $actual = $this->widgetRequestBuilder->build();
260  $this->assertSame($expected, $actual);
261  }
262 }
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
Definition: WidgetRequest.php:22
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\setUp
‪setUp()
Definition: WidgetRequestBuilderTest.php:53
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder
Definition: WidgetRequestBuilder.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildThrowsIfNoFluidWidgetIdWasSet
‪buildThrowsIfNoFluidWidgetIdWasSet()
Definition: WidgetRequestBuilderTest.php:68
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsGetArgumentsFromRequest
‪buildSetsGetArgumentsFromRequest()
Definition: WidgetRequestBuilderTest.php:174
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\$mockWidgetRequest
‪WidgetRequest $mockWidgetRequest
Definition: WidgetRequestBuilderTest.php:40
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsControllerActionNameFromGetArguments
‪buildSetsControllerActionNameFromGetArguments()
Definition: WidgetRequestBuilderTest.php:198
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:23
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsPostArgumentsFromRequest
‪buildSetsPostArgumentsFromRequest()
Definition: WidgetRequestBuilderTest.php:150
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsBaseUri
‪buildSetsBaseUri()
Definition: WidgetRequestBuilderTest.php:109
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\$mockAjaxWidgetContextHolder
‪AjaxWidgetContextHolder $mockAjaxWidgetContextHolder
Definition: WidgetRequestBuilderTest.php:44
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildReturnsRequest
‪buildReturnsRequest()
Definition: WidgetRequestBuilderTest.php:240
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsRequestMethod
‪buildSetsRequestMethod()
Definition: WidgetRequestBuilderTest.php:130
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget
Definition: AbstractWidgetControllerTest.php:2
‪TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder
Definition: AjaxWidgetContextHolder.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsWidgetContext
‪buildSetsWidgetContext()
Definition: WidgetRequestBuilderTest.php:219
‪TYPO3\CMS\Fluid\Core\Widget\WidgetContext
Definition: WidgetContext.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\$mockWidgetContext
‪WidgetContext $mockWidgetContext
Definition: WidgetRequestBuilderTest.php:48
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\$mockObjectManager
‪ObjectManagerInterface $mockObjectManager
Definition: WidgetRequestBuilderTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\buildSetsRequestUri
‪buildSetsRequestUri()
Definition: WidgetRequestBuilderTest.php:88
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest\$widgetRequestBuilder
‪WidgetRequestBuilder $widgetRequestBuilder
Definition: WidgetRequestBuilderTest.php:32
‪TYPO3\CMS\Fluid\Tests\Unit\Core\Widget\WidgetRequestBuilderTest
Definition: WidgetRequestBuilderTest.php:29