‪TYPO3CMS  10.4
PageRouterTest.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 
20 use Prophecy\Argument;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 class ‪PageRouterTest extends UnitTestCase
32 {
36  protected ‪$resetSingletonInstances = true;
37 
42  {
43  $this->expectException(RouteNotFoundException::class);
44  $this->expectExceptionCode(1555303496);
45  $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';
46  $request = new ‪ServerRequest($incomingUrl, 'GET');
47  $subject = new ‪PageRouter(new ‪Site('lotus-flower', 13, []));
48  $subject->matchRequest($request, null);
49  }
50 
54  public function ‪properSiteConfigurationFindsRoute(): void
55  {
56  $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';
57  $pageRecord = ['uid' => 13, 'l10n_parent' => 0, 'slug' => '/mr-magpie/bloom'];
58  $site = new ‪Site('lotus-flower', 13, [
59  'base' => '/lotus-flower/',
60  'languages' => [
61  0 => [
62  'languageId' => 0,
63  'locale' => 'en_US.UTF-8',
64  'base' => '/en/'
65  ],
66  ]
67  ]);
68  $language = $site->getDefaultLanguage();
69 
70  $pageSlugCandidateProvider = $this->prophesize(PageSlugCandidateProvider::class);
71  $pageSlugCandidateProvider->getCandidatesForPath('/mr-magpie/bloom', $language)->willReturn([$pageRecord]);
72  GeneralUtility::addInstance(PageSlugCandidateProvider::class, $pageSlugCandidateProvider->reveal());
73 
74  $request = new ‪ServerRequest($incomingUrl, 'GET');
75  $previousResult = new ‪SiteRouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom');
76  $routeResult = (new ‪PageRouter($site))->matchRequest($request, $previousResult);
77 
78  $expectedRouteResult = new ‪PageArguments(13, '0', [], [], []);
79  self::assertEquals($expectedRouteResult, $routeResult);
80  }
81 
87  {
88  $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';
89  $pageRecord = ['uid' => 13, 'l10n_parent' => 0, 'slug' => '/mr-magpie/bloom'];
90  $site = new ‪Site('lotus-flower', 13, [
91  'base' => '/lotus-flower/',
92  'languages' => [
93  0 => [
94  'languageId' => 0,
95  'locale' => 'en_US.UTF-8',
96  'base' => '/en'
97  ],
98  ]
99  ]);
100  $language = $site->getDefaultLanguage();
101  $pageSlugCandidateProvider = $this->prophesize(PageSlugCandidateProvider::class);
102  $pageSlugCandidateProvider->getCandidatesForPath(Argument::cetera())->willReturn([$pageRecord]);
103  GeneralUtility::addInstance(PageSlugCandidateProvider::class, $pageSlugCandidateProvider->reveal());
104 
105  $request = new ‪ServerRequest($incomingUrl, 'GET');
106  $previousResult = new ‪SiteRouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom/');
107  $routeResult = (new ‪PageRouter($site))->matchRequest($request, $previousResult);
108 
109  $expectedRouteResult = new ‪PageArguments((int)$pageRecord['uid'], '0', []);
110  self::assertEquals($expectedRouteResult, $routeResult);
111  }
112 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:26
‪TYPO3\CMS\Core\Routing\PageSlugCandidateProvider
Definition: PageSlugCandidateProvider.php:42
‪TYPO3\CMS\Core\Tests\Unit\Routing
‪TYPO3\CMS\Core\Routing\PageRouter
Definition: PageRouter.php:71
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: PageRouterTest.php:35
‪TYPO3\CMS\Core\Routing\RouteNotFoundException
Definition: RouteNotFoundException.php:26
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\properSiteConfigurationFindsRoute
‪properSiteConfigurationFindsRoute()
Definition: PageRouterTest.php:53
‪TYPO3\CMS\Core\Routing\SiteRouteResult
Definition: SiteRouteResult.php:30
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest
Definition: PageRouterTest.php:32
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\matchRequestThrowsExceptionIfNoPreviousResultGiven
‪matchRequestThrowsExceptionIfNoPreviousResultGiven()
Definition: PageRouterTest.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\properSiteConfigurationWithoutTrailingSlashFindsRoute
‪properSiteConfigurationWithoutTrailingSlashFindsRoute()
Definition: PageRouterTest.php:85