‪TYPO3CMS  9.5
PageRouterTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 class ‪PageRouterTest extends UnitTestCase
28 {
32  protected ‪$resetSingletonInstances = true;
33 
38  {
39  $this->expectException(RouteNotFoundException::class);
40  $this->expectExceptionCode(1555303496);
41  $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';
42  $request = new ‪ServerRequest($incomingUrl, 'GET');
43  $subject = new ‪PageRouter(new ‪Site('lotus-flower', 13, []));
44  $subject->matchRequest($request, null);
45  }
46 
50  public function ‪properSiteConfigurationFindsRoute()
51  {
52  $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';
53  $slugCandidates = ['/mr-magpie/bloom/', '/mr-magpie/bloom'];
54  $pageRecord = ['uid' => 13, 'l10n_parent' => 0, 'slug' => '/mr-magpie/bloom'];
55  $site = new ‪Site('lotus-flower', 13, [
56  'base' => '/lotus-flower/',
57  'languages' => [
58  0 => [
59  'languageId' => 0,
60  'locale' => 'en_US.UTF-8',
61  'base' => '/en/'
62  ],
63  ]
64  ]);
65  $language = $site->getDefaultLanguage();
66 
67  $request = new ‪ServerRequest($incomingUrl, 'GET');
68  $previousResult = new ‪SiteRouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom');
69  $subject = $this->getAccessibleMock(PageRouter::class, ['getCandidateSlugsFromRoutePath', 'getPagesFromDatabaseForCandidates'], [$site]);
70  $subject->expects($this->once())->method('getCandidateSlugsFromRoutePath')->willReturn($slugCandidates);
71  $subject->expects($this->once())->method('getPagesFromDatabaseForCandidates')->willReturn([$pageRecord]);
72  $routeResult = $subject->matchRequest($request, $previousResult);
73 
74  $expectedRouteResult = new ‪PageArguments(13, '0', [], [], []);
75  $this->assertEquals($expectedRouteResult, $routeResult);
76  }
77 
83  {
84  // @todo Benni: please fix it... ;-)
85  $this->markTestSkipped('Should check for empty result, since tail is not considered anymore');
86 
87  $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom/unknown-code/';
88  $slugCandidates = ['/mr-magpie/bloom/unknown-code/', '/mr-magpie/bloom/unknown-code'];
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  $request = new ‪ServerRequest($incomingUrl, 'GET');
102  $previousResult = new ‪SiteRouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom/unknown-code/');
103  $subject = $this->getAccessibleMock(PageRouter::class, ['getCandidateSlugsFromRoutePath', 'getPagesFromDatabaseForCandidates'], [$site, []]);
104  $subject->expects($this->once())->method('getCandidateSlugsFromRoutePath')->willReturn($slugCandidates);
105  $subject->expects($this->once())->method('getPagesFromDatabaseForCandidates')->willReturn([$pageRecord]);
106  $routeResult = $subject->matchRequest($request, $previousResult);
107 
108  $expectedRouteResult = new ‪SiteRouteResult($request->getUri(), $site, $language, 'unknown-code/', ['page' => $pageRecord]);
109  $this->assertEquals($expectedRouteResult, $routeResult);
110  }
111 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:25
‪TYPO3\CMS\Core\Tests\Unit\Routing
‪TYPO3\CMS\Core\Routing\PageRouter
Definition: PageRouter.php:75
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: PageRouterTest.php:31
‪TYPO3\CMS\Core\Routing\RouteNotFoundException
Definition: RouteNotFoundException.php:23
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\properSiteConfigurationFindsRoute
‪properSiteConfigurationFindsRoute()
Definition: PageRouterTest.php:49
‪TYPO3\CMS\Core\Routing\SiteRouteResult
Definition: SiteRouteResult.php:29
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest
Definition: PageRouterTest.php:28
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\matchRequestThrowsExceptionIfNoPreviousResultGiven
‪matchRequestThrowsExceptionIfNoPreviousResultGiven()
Definition: PageRouterTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Routing\PageRouterTest\properSiteConfigurationWithoutTrailingSlashFindsRoute
‪properSiteConfigurationWithoutTrailingSlashFindsRoute()
Definition: PageRouterTest.php:81