‪TYPO3CMS  9.5
RequestTest.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  */
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪RequestTest extends UnitTestCase
23 {
28  {
29  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
30  $request->setArgument('someArgumentName', 'theValue');
31  $this->assertEquals('theValue', $request->getArgument('someArgumentName'));
32  }
33 
38  {
39  $this->expectException(InvalidArgumentNameException::class);
40  $this->expectExceptionCode(1210858767);
41  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
42  $request->setArgument(123, 'theValue');
43  }
44 
49  {
50  $this->expectException(InvalidArgumentNameException::class);
51  $this->expectExceptionCode(1210858767);
52  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
53  $request->setArgument('', 'theValue');
54  }
55 
60  {
61  $arguments = ['key1' => 'value1', 'key2' => 'value2'];
62  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
63  $request->setArgument('someKey', 'shouldBeOverridden');
64  $request->setArguments($arguments);
65  $actualResult = $request->getArguments();
66  $this->assertEquals($arguments, $actualResult);
67  }
68 
73  {
74  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
75  ->setMethods(['setArgument'])
76  ->getMock();
77  $request->expects($this->at(0))->method('setArgument')->with('key1', 'value1');
78  $request->expects($this->at(1))->method('setArgument')->with('key2', 'value2');
79  $request->setArguments(['key1' => 'value1', 'key2' => 'value2']);
80  }
81 
86  {
87  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
88  ->setMethods(['setControllerExtensionName'])
89  ->getMock();
90  $request->expects($this->any())->method('setControllerExtensionName')->with('MyExtension');
91  $request->setArgument('@extension', 'MyExtension');
92  $this->assertFalse($request->hasArgument('@extension'));
93  }
94 
99  {
100  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
101  ->setMethods(['setControllerSubpackageKey'])
102  ->getMock();
103  $request->expects($this->any())->method('setControllerSubpackageKey')->with('MySubPackage');
104  $request->setArgument('@subpackage', 'MySubPackage');
105  $this->assertFalse($request->hasArgument('@subpackage'));
106  }
107 
112  {
113  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
114  ->setMethods(['setControllerName'])
115  ->getMock();
116  $request->expects($this->any())->method('setControllerName')->with('MyController');
117  $request->setArgument('@controller', 'MyController');
118  $this->assertFalse($request->hasArgument('@controller'));
119  }
120 
125  {
126  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
127  ->setMethods(['setControllerActionName'])
128  ->getMock();
129  $request->expects($this->any())->method('setControllerActionName')->with('foo');
130  $request->setArgument('@action', 'foo');
131  $this->assertFalse($request->hasArgument('@action'));
132  }
133 
138  {
139  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
140  ->setMethods(['setFormat'])
141  ->getMock();
142  $request->expects($this->any())->method('setFormat')->with('txt');
143  $request->setArgument('@format', 'txt');
144  $this->assertFalse($request->hasArgument('@format'));
145  }
146 
151  {
152  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
153  ->setMethods(['setFormat', 'setVendor'])
154  ->getMock();
155  $request->expects($this->any())->method('setVendor')->with('VENDOR');
156  $request->setArgument('@vendor', 'VENDOR');
157  $this->assertFalse($request->hasArgument('@vendor'));
158  }
159 
164  {
165  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
166  $request->setArgument('__referrer', 'foo');
167  $this->assertFalse($request->hasArgument('__referrer'));
168  }
169 
174  {
175  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
176  $request->setArgument('__referrer', 'foo');
177  $this->assertSame('foo', $request->getInternalArgument('__referrer'));
178  }
179 
184  {
185  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
186  $this->assertNull($request->getInternalArgument('__nonExistingInternalArgument'));
187  }
188 
193  {
194  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
195  $object = new \stdClass();
196  $request->setArgument('__theKey', $object);
197  $this->assertSame($object, $request->getInternalArgument('__theKey'));
198  }
199 
204  {
205  $arguments = [
206  'firstArgument' => 'firstValue',
207  'dænishÅrgument' => 'görman välju',
208  '3a' => '3v'
209  ];
210  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
211  $request->setArguments($arguments);
212  $this->assertEquals($arguments, $request->getArguments());
213  }
214 
219  {
220  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
221  $request->setArgument('existingArgument', 'theValue');
222  $this->assertTrue($request->hasArgument('existingArgument'));
223  $this->assertFalse($request->hasArgument('notExistingArgument'));
224  }
225 
230  {
231  $request = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class)
232  ->setMethods(['getControllerObjectName'])
233  ->disableOriginalConstructor()
234  ->getMock();
235  $request->expects($this->once())->method('getControllerObjectName')->will($this->returnValue(''));
236  $request->setControllerActionName('theAction');
237  $this->assertEquals('theAction', $request->getControllerActionName());
238  }
239 
244  {
245  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
246  $request->setFormat('html');
247  $this->assertEquals('html', $request->getFormat());
248  }
249 
254  {
255  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
256  $this->assertFalse($request->isDispatched());
257  $request->setDispatched(true);
258  $this->assertTrue($request->isDispatched());
259  }
260 
267  {
268  return [
269  'Vendor TYPO3\CMS, extension, controller given' => [
270  [
271  'vendorName' => 'TYPO3\\CMS',
272  'extensionName' => 'Ext',
273  'subpackageKey' => '',
274  'controllerName' => 'Foo',
275  ],
276  'TYPO3\\CMS\\Ext\\Controller\\FooController',
277  ],
278  'Vendor TYPO3\CMS, extension, subpackage, controlle given' => [
279  [
280  'vendorName' => 'TYPO3\\CMS',
281  'extensionName' => 'Fluid',
282  'subpackageKey' => 'ViewHelpers\\Widget',
283  'controllerName' => 'Paginate',
284  ],
285  \TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController::class,
286  ],
287  'Vendor VENDOR, extension, controller given' => [
288  [
289  'vendorName' => 'VENDOR',
290  'extensionName' => 'Ext',
291  'subpackageKey' => '',
292  'controllerName' => 'Foo',
293  ],
294  'VENDOR\\Ext\\Controller\\FooController',
295  ],
296  'Vendor VENDOR, extension subpackage, controller given' => [
297  [
298  'vendorName' => 'VENDOR',
299  'extensionName' => 'Ext',
300  'subpackageKey' => 'ViewHelpers\\Widget',
301  'controllerName' => 'Foo',
302  ],
303  'VENDOR\\Ext\\ViewHelpers\\Widget\\Controller\\FooController',
304  ],
305  ];
306  }
307 
315  public function ‪getControllerObjectNameResolvesControllerObjectNameCorrectly($controllerArguments, $controllerObjectName)
316  {
318  $request = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class, ['dummy']);
319  $request->_set('controllerVendorName', $controllerArguments['vendorName']);
320  $request->_set('controllerExtensionName', $controllerArguments['extensionName']);
321  $request->_set('controllerSubpackageKey', $controllerArguments['subpackageKey']);
322  $request->_set('controllerName', $controllerArguments['controllerName']);
323 
324  $this->assertEquals($controllerObjectName, $request->getControllerObjectName());
325  }
326 
334  public function ‪setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly($controllerArguments, $controllerObjectName)
335  {
337  $request = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Mvc\Request::class, ['dummy']);
338  $request->setControllerObjectName($controllerObjectName);
339 
340  $actualControllerArguments = [
341  'vendorName' => $request->_get('controllerVendorName'),
342  'extensionName' => $request->_get('controllerExtensionName'),
343  'subpackageKey' => $request->_get('controllerSubpackageKey'),
344  'controllerName' => $request->_get('controllerName'),
345  ];
346 
347  $this->assertSame($controllerArguments, $actualControllerArguments);
348  }
349 }
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\internalArgumentsShouldNotBeReturnedAsNormalArgument
‪internalArgumentsShouldNotBeReturnedAsNormalArgument()
Definition: RequestTest.php:163
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetVendorIfVendorIsGiven
‪setArgumentShouldSetVendorIfVendorIsGiven()
Definition: RequestTest.php:150
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\theRepresentationFormatCanBeSetAndRetrieved
‪theRepresentationFormatCanBeSetAndRetrieved()
Definition: RequestTest.php:243
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\aSingleArgumentCanBeSetWithSetArgumentAndRetrievedWithGetArgument
‪aSingleArgumentCanBeSetWithSetArgumentAndRetrievedWithGetArgument()
Definition: RequestTest.php:27
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentsCallsSetArgumentForEveryArrayEntry
‪setArgumentsCallsSetArgumentForEveryArrayEntry()
Definition: RequestTest.php:72
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerNameIfControllerIsGiven
‪setArgumentShouldSetControllerNameIfControllerIsGiven()
Definition: RequestTest.php:111
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerSubpackageKeyIfSubpackageKeyIsGiven
‪setArgumentShouldSetControllerSubpackageKeyIfSubpackageKeyIsGiven()
Definition: RequestTest.php:98
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest
Definition: RequestTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentThrowsExceptionIfTheGivenArgumentNameIsNoString
‪setArgumentThrowsExceptionIfTheGivenArgumentNameIsNoString()
Definition: RequestTest.php:37
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerExtensionNameIfPackageKeyIsGiven
‪setArgumentShouldSetControllerExtensionNameIfPackageKeyIsGiven()
Definition: RequestTest.php:85
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerActionNameIfActionIsGiven
‪setArgumentShouldSetControllerActionNameIfActionIsGiven()
Definition: RequestTest.php:124
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\internalArgumentsShouldBeStoredAsInternalArguments
‪internalArgumentsShouldBeStoredAsInternalArguments()
Definition: RequestTest.php:173
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\getControllerObjectNameResolvesControllerObjectNameCorrectly
‪getControllerObjectNameResolvesControllerObjectNameCorrectly($controllerArguments, $controllerObjectName)
Definition: RequestTest.php:315
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetFormatIfFormatIsGiven
‪setArgumentShouldSetFormatIfFormatIsGiven()
Definition: RequestTest.php:137
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentsOverridesAllExistingArguments
‪setArgumentsOverridesAllExistingArguments()
Definition: RequestTest.php:59
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\multipleArgumentsCanBeSetWithSetArgumentsAndRetrievedWithGetArguments
‪multipleArgumentsCanBeSetWithSetArgumentsAndRetrievedWithGetArguments()
Definition: RequestTest.php:203
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentAcceptsObjectIfArgumentIsInternal
‪setArgumentAcceptsObjectIfArgumentIsInternal()
Definition: RequestTest.php:192
‪TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
Definition: InvalidArgumentNameException.php:21
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\hasArgumentTellsIfAnArgumentExists
‪hasArgumentTellsIfAnArgumentExists()
Definition: RequestTest.php:218
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\controllerArgumentsAndExpectedObjectName
‪array controllerArgumentsAndExpectedObjectName()
Definition: RequestTest.php:266
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentThrowsExceptionIfTheGivenArgumentNameIsAnEmptyString
‪setArgumentThrowsExceptionIfTheGivenArgumentNameIsAnEmptyString()
Definition: RequestTest.php:48
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly
‪setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly($controllerArguments, $controllerObjectName)
Definition: RequestTest.php:334
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\hasInternalArgumentShouldReturnNullIfArgumentNotFound
‪hasInternalArgumentShouldReturnNullIfArgumentNotFound()
Definition: RequestTest.php:183
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\theActionNameCanBeSetAndRetrieved
‪theActionNameCanBeSetAndRetrieved()
Definition: RequestTest.php:229
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\aFlagCanBeSetIfTheRequestNeedsToBeDispatchedAgain
‪aFlagCanBeSetIfTheRequestNeedsToBeDispatchedAgain()
Definition: RequestTest.php:253