‪TYPO3CMS  10.4
RequestTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪RequestTest extends UnitTestCase
27 {
32  {
33  $request = new ‪Request();
34  $request->setArgument('someArgumentName', 'theValue');
35  self::assertEquals('theValue', $request->getArgument('someArgumentName'));
36  }
37 
42  {
43  $this->expectException(InvalidArgumentNameException::class);
44  $this->expectExceptionCode(1210858767);
45  $request = new ‪Request();
46  $request->setArgument(123, 'theValue');
47  }
48 
53  {
54  $this->expectException(InvalidArgumentNameException::class);
55  $this->expectExceptionCode(1210858767);
56  $request = new ‪Request();
57  $request->setArgument('', 'theValue');
58  }
59 
64  {
65  $arguments = ['key1' => 'value1', 'key2' => 'value2'];
66  $request = new ‪Request();
67  $request->setArgument('someKey', 'shouldBeOverridden');
68  $request->setArguments($arguments);
69  $actualResult = $request->getArguments();
70  self::assertEquals($arguments, $actualResult);
71  }
72 
77  {
78  $request = $this->getMockBuilder(Request::class)
79  ->onlyMethods(['setArgument'])
80  ->getMock();
81  $request->expects(self::exactly(2))->method('setArgument')
82  ->withConsecutive(
83  ['key1', 'value1'],
84  ['key2', 'value2']
85  );
86  $request->setArguments(['key1' => 'value1', 'key2' => 'value2']);
87  }
88 
93  {
94  $request = $this->getMockBuilder(Request::class)
95  ->onlyMethods(['setControllerExtensionName'])
96  ->getMock();
97  $request->method('setControllerExtensionName')->with('MyExtension');
98  $request->setArgument('@extension', 'MyExtension');
99  self::assertFalse($request->hasArgument('@extension'));
100  }
101 
106  {
107  $request = $this->getMockBuilder(Request::class)
108  ->onlyMethods(['setControllerSubpackageKey'])
109  ->getMock();
110  $request->method('setControllerSubpackageKey')->with('MySubPackage');
111  $request->setArgument('@subpackage', 'MySubPackage');
112  self::assertFalse($request->hasArgument('@subpackage'));
113  }
114 
119  {
120  $request = $this->getMockBuilder(Request::class)
121  ->onlyMethods(['setControllerName'])
122  ->getMock();
123  $request->method('setControllerName')->with('MyController');
124  $request->setArgument('@controller', 'MyController');
125  self::assertFalse($request->hasArgument('@controller'));
126  }
127 
132  {
133  $request = $this->getMockBuilder(Request::class)
134  ->onlyMethods(['setControllerActionName'])
135  ->getMock();
136  $request->method('setControllerActionName')->with('foo');
137  $request->setArgument('@action', 'foo');
138  self::assertFalse($request->hasArgument('@action'));
139  }
140 
145  {
146  $request = $this->getMockBuilder(Request::class)
147  ->onlyMethods(['setFormat'])
148  ->getMock();
149  $request->method('setFormat')->with('txt');
150  $request->setArgument('@format', 'txt');
151  self::assertFalse($request->hasArgument('@format'));
152  }
153 
158  {
159  $request = new ‪Request();
160  $request->setArgument('__referrer', 'foo');
161  self::assertFalse($request->hasArgument('__referrer'));
162  }
163 
168  {
169  $request = new ‪Request();
170  $request->setArgument('__referrer', 'foo');
171  self::assertSame('foo', $request->getInternalArgument('__referrer'));
172  }
173 
178  {
179  $request = new ‪Request();
180  self::assertNull($request->getInternalArgument('__nonExistingInternalArgument'));
181  }
182 
187  {
188  $request = new ‪Request();
189  $object = new \stdClass();
190  $request->setArgument('__theKey', $object);
191  self::assertSame($object, $request->getInternalArgument('__theKey'));
192  }
193 
198  {
199  $arguments = [
200  'firstArgument' => 'firstValue',
201  'dænishÅrgument' => 'görman välju',
202  '3a' => '3v'
203  ];
204  $request = new ‪Request();
205  $request->setArguments($arguments);
206  self::assertEquals($arguments, $request->getArguments());
207  }
208 
213  {
214  $request = new ‪Request();
215  $request->setArgument('existingArgument', 'theValue');
216  self::assertTrue($request->hasArgument('existingArgument'));
217  self::assertFalse($request->hasArgument('notExistingArgument'));
218  }
219 
224  {
225  $request = $this->getMockBuilder(Request::class)
226  ->onlyMethods(['getControllerObjectName'])
227  ->disableOriginalConstructor()
228  ->getMock();
229  $request->expects(self::once())->method('getControllerObjectName')->willReturn('');
230  $request->setControllerActionName('theAction');
231  self::assertEquals('theAction', $request->getControllerActionName());
232  }
233 
238  {
239  $request = new ‪Request();
240  $request->setFormat('html');
241  self::assertEquals('html', $request->getFormat());
242  }
243 
248  {
249  $request = new ‪Request();
250  self::assertFalse($request->isDispatched());
251  $request->setDispatched(true);
252  self::assertTrue($request->isDispatched());
253  }
254 
261  {
262  return [
263  'Vendor TYPO3\CMS, extension, controller given' => [
264  [
265  'extensionName' => 'Ext',
266  'subpackageKey' => '',
267  'controllerName' => 'Foo',
268  ],
269  'TYPO3\\CMS\\Ext\\Controller\\FooController',
270  ],
271  'Vendor TYPO3\CMS, extension, subpackage, controller given' => [
272  [
273  'extensionName' => 'Fluid',
274  'subpackageKey' => 'ViewHelpers\\Widget',
275  'controllerName' => 'Paginate',
276  ],
277  PaginateController::class,
278  ],
279  'Vendor VENDOR, extension, controller given' => [
280  [
281  'extensionName' => 'Ext',
282  'subpackageKey' => '',
283  'controllerName' => 'Foo',
284  ],
285  'VENDOR\\Ext\\Controller\\FooController',
286  ],
287  'Vendor VENDOR, extension subpackage, controller given' => [
288  [
289  'extensionName' => 'Ext',
290  'subpackageKey' => 'ViewHelpers\\Widget',
291  'controllerName' => 'Foo',
292  ],
293  'VENDOR\\Ext\\ViewHelpers\\Widget\\Controller\\FooController',
294  ],
295  ];
296  }
297 
305  public function ‪setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly($controllerArguments, $controllerObjectName): void
306  {
308  $request = new ‪Request();
309  $request->setControllerObjectName($controllerObjectName);
310 
311  $actualControllerArguments = [
312  'extensionName' => $request->getControllerExtensionName(),
313  'subpackageKey' => $request->getControllerSubpackageKey(),
314  'controllerName' => $request->getControllerName(),
315  ];
316 
317  self::assertSame($controllerArguments, $actualControllerArguments);
318  }
319 }
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\internalArgumentsShouldNotBeReturnedAsNormalArgument
‪internalArgumentsShouldNotBeReturnedAsNormalArgument()
Definition: RequestTest.php:157
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\theRepresentationFormatCanBeSetAndRetrieved
‪theRepresentationFormatCanBeSetAndRetrieved()
Definition: RequestTest.php:237
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\aSingleArgumentCanBeSetWithSetArgumentAndRetrievedWithGetArgument
‪aSingleArgumentCanBeSetWithSetArgumentAndRetrievedWithGetArgument()
Definition: RequestTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentsCallsSetArgumentForEveryArrayEntry
‪setArgumentsCallsSetArgumentForEveryArrayEntry()
Definition: RequestTest.php:76
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerNameIfControllerIsGiven
‪setArgumentShouldSetControllerNameIfControllerIsGiven()
Definition: RequestTest.php:118
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerSubpackageKeyIfSubpackageKeyIsGiven
‪setArgumentShouldSetControllerSubpackageKeyIfSubpackageKeyIsGiven()
Definition: RequestTest.php:105
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest
Definition: RequestTest.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentThrowsExceptionIfTheGivenArgumentNameIsNoString
‪setArgumentThrowsExceptionIfTheGivenArgumentNameIsNoString()
Definition: RequestTest.php:41
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerExtensionNameIfPackageKeyIsGiven
‪setArgumentShouldSetControllerExtensionNameIfPackageKeyIsGiven()
Definition: RequestTest.php:92
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetControllerActionNameIfActionIsGiven
‪setArgumentShouldSetControllerActionNameIfActionIsGiven()
Definition: RequestTest.php:131
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\internalArgumentsShouldBeStoredAsInternalArguments
‪internalArgumentsShouldBeStoredAsInternalArguments()
Definition: RequestTest.php:167
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentShouldSetFormatIfFormatIsGiven
‪setArgumentShouldSetFormatIfFormatIsGiven()
Definition: RequestTest.php:144
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentsOverridesAllExistingArguments
‪setArgumentsOverridesAllExistingArguments()
Definition: RequestTest.php:63
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\multipleArgumentsCanBeSetWithSetArgumentsAndRetrievedWithGetArguments
‪multipleArgumentsCanBeSetWithSetArgumentsAndRetrievedWithGetArguments()
Definition: RequestTest.php:197
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentAcceptsObjectIfArgumentIsInternal
‪setArgumentAcceptsObjectIfArgumentIsInternal()
Definition: RequestTest.php:186
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController
Definition: PaginateController.php:27
‪TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
Definition: InvalidArgumentNameException.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\hasArgumentTellsIfAnArgumentExists
‪hasArgumentTellsIfAnArgumentExists()
Definition: RequestTest.php:212
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\controllerArgumentsAndExpectedObjectName
‪array controllerArgumentsAndExpectedObjectName()
Definition: RequestTest.php:260
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setArgumentThrowsExceptionIfTheGivenArgumentNameIsAnEmptyString
‪setArgumentThrowsExceptionIfTheGivenArgumentNameIsAnEmptyString()
Definition: RequestTest.php:52
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly
‪setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly($controllerArguments, $controllerObjectName)
Definition: RequestTest.php:305
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\hasInternalArgumentShouldReturnNullIfArgumentNotFound
‪hasInternalArgumentShouldReturnNullIfArgumentNotFound()
Definition: RequestTest.php:177
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\theActionNameCanBeSetAndRetrieved
‪theActionNameCanBeSetAndRetrieved()
Definition: RequestTest.php:223
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\RequestTest\aFlagCanBeSetIfTheRequestNeedsToBeDispatchedAgain
‪aFlagCanBeSetIfTheRequestNeedsToBeDispatchedAgain()
Definition: RequestTest.php:247