‪TYPO3CMS  11.5
RouterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 class ‪RouterTest extends FunctionalTestCase
30 {
34  protected ‪$initializeDatabase = false;
35 
39  public function ‪matchRequestFindsProperRoute(): void
40  {
41  $subject = GeneralUtility::makeInstance(Router::class);
42  $request = new ‪ServerRequest('https://example.com/login', 'GET');
43  $request = $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
44  $resultRoute = $subject->matchRequest($request);
45  self::assertInstanceOf(Route::class, $resultRoute);
46  self::assertEquals('/login', $resultRoute->getPath());
47  }
48 
52  public function ‪matchRequestThrowsExceptionOnInvalidRoute(): void
53  {
54  $subject = GeneralUtility::makeInstance(Router::class);
55  $request = new ‪ServerRequest('https://example.com/this-path/does-not-exist', 'GET');
56  $request = $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
57  $this->expectException(ResourceNotFoundException::class);
58  $subject->matchRequest($request);
59  }
60 
65  {
66  $subject = GeneralUtility::makeInstance(Router::class);
67  $request = new ‪ServerRequest('https://example.com/login/password-reset/initiate-reset', 'GET');
68  $request = $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
69  $this->expectException(MethodNotAllowedException::class);
70  $subject->matchRequest($request);
71  }
72 
77  {
78  $subject = GeneralUtility::makeInstance(Router::class);
79  $request = new ‪ServerRequest('https://example.com/login/password-reset/initiate-reset', 'POST');
80  $request = $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
81  $resultRoute = $subject->matchRequest($request);
82  self::assertInstanceOf(Route::class, $resultRoute);
83  self::assertEquals('/login/password-reset/initiate-reset', $resultRoute->getPath());
84  }
85 }
‪TYPO3\CMS\Backend\Tests\Functional\Routing\RouterTest\matchRequestThrowsInvalidMethodForValidRoute
‪matchRequestThrowsInvalidMethodForValidRoute()
Definition: RouterTest.php:63
‪TYPO3\CMS\Backend\Routing\Exception\MethodNotAllowedException
Definition: MethodNotAllowedException.php:23
‪TYPO3\CMS\Backend\Tests\Functional\Routing\RouterTest
Definition: RouterTest.php:30
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Backend\Tests\Functional\Routing\RouterTest\matchRequestThrowsExceptionOnInvalidRoute
‪matchRequestThrowsExceptionOnInvalidRoute()
Definition: RouterTest.php:51
‪TYPO3\CMS\Backend\Tests\Functional\Routing
Definition: RouterTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Routing\RouterTest\$initializeDatabase
‪bool $initializeDatabase
Definition: RouterTest.php:33
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Routing\RouterTest\matchRequestFindsProperRoute
‪matchRequestFindsProperRoute()
Definition: RouterTest.php:38
‪TYPO3\CMS\Backend\Tests\Functional\Routing\RouterTest\matchRequestReturnsRouteWithMethodLimitation
‪matchRequestReturnsRouteWithMethodLimitation()
Definition: RouterTest.php:75
‪TYPO3\CMS\Backend\Routing\Exception\ResourceNotFoundException
Definition: ResourceNotFoundException.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:39
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromRequest
‪static static createFromRequest(ServerRequestInterface $request, array $systemConfiguration=null)
Definition: NormalizedParams.php:843
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35