‪TYPO3CMS  9.5
SiteTest.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 
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 class ‪SiteTest extends UnitTestCase
31 {
33  {
34  return [
35  'URL with scheme and domain' => ['https://www.typo3.org', 'https://www.typo3.org'],
36  'URL with scheme and domain and path' => ['https://www.typo3.org/howdy', 'https://www.typo3.org/howdy'],
37  'URL with scheme and domain and path with trailing slash' => ['https://www.typo3.org/howdy/', 'https://www.typo3.org/howdy/'],
38  'URL without scheme, but with domain' => ['www.typo3.org', '//www.typo3.org'],
39  'URL without scheme, but with domain and path' => ['www.typo3.org/partner', '//www.typo3.org/partner'],
40  'URL without scheme, but with domain and path and trailing slash' => ['www.typo3.org/partner/', '//www.typo3.org/partner/'],
41  'URL without scheme and domain but with absolute path' => ['/partner', '/partner'],
42  'URL without scheme and domain but with absolute path and trailing slash' => ['/partner/', '/partner/'],
43  'URL without scheme, domain but with random path receives a scheme divider' => ['partner/', '/partner/'],
44  'URL with ID query parameter' => ['/partner/?id=nice-to-see-you', '/partner/?id=nice-to-see-you'],
45  'URL with unknown query parameter' => ['/partner/?in-crime=nice-to-see-you', '/partner/?in-crime=nice-to-see-you'],
46  ];
47  }
48 
53  public function ‪getBaseReturnsProperUri($input, $expected)
54  {
55  $subject = new ‪Site('all-your-base-belongs-to-us', 13, [
56  'base' => $input,
57  'languages' => []
58  ]);
59  $this->assertEquals(new ‪Uri($expected), $subject->getBase());
60  }
61 
69  {
70  return [
71  'Language as a regular path segment' => [
72  'https://www.typo3.org',
73  'en',
74  'https://www.typo3.org/en',
75  ],
76  'Language with two path segments' => [
77  'https://www.typo3.org',
78  'us/en',
79  'https://www.typo3.org/us/en',
80  ],
81  'Site base is added to absolute path segment' => [
82  'https://www.typo3.com/microsites/',
83  '/onboarding/',
84  'https://www.typo3.com/microsites/onboarding/',
85  ],
86  'Site base is prefixed to absolute path segment' => [
87  'https://www.typo3.com/microsites/',
88  'onboarding/',
89  'https://www.typo3.com/microsites/onboarding/',
90  ],
91  'Language with domain and scheme, do not care about site base' => [
92  'https://www.typo3.org',
93  'https://www.typo3.it',
94  'https://www.typo3.it',
95  ],
96  'Language with domain but no scheme, do not care about site base' => [
97  'blabla.car',
98  'www.typo3.fr',
99  '//www.typo3.fr',
100  ],
101  ];
102  }
103 
111  public function ‪getBaseForSiteLanguageReturnsProperUri($siteBase, $languageBase, $expected)
112  {
113  $subject = new ‪Site('all-of-base', 13, [
114  'base' => $siteBase,
115  'languages' => [
116  [
117  'languageId' => 0,
118  'base' => $languageBase,
119  'locale' => 'it_IT.UTF-8',
120  ]
121  ]
122  ]);
123  $this->assertEquals(new ‪Uri($expected), $subject->getLanguageById(0)->getBase());
124  }
125 
130  {
131  $subject = new ‪Site('aint-misbehaving', 13, [
132  'languages' => [],
133  'errorHandling' => [
134  [
135  'errorCode' => 123,
136  'errorHandler' => 'Fluid',
137  ],
138  [
139  'errorCode' => 124,
140  'errorContentSource' => 123,
141  'errorHandler' => 'Page'
142  ],
143  [
144  'errorCode' => 125,
145  'errorHandler' => 'PHP',
146  'errorContentSource' => 123,
147  'errorPhpClassFQCN' => PageContentErrorHandler::class
148  ]
149  ]
150  ]);
151 
152  $fluidProphecy = $this->prophesize(FluidPageErrorHandler::class);
153  GeneralUtility::addInstance(FluidPageErrorHandler::class, $fluidProphecy->reveal());
154 
155  $this->assertEquals(true, $subject->getErrorHandler(123) instanceof ‪PageErrorHandlerInterface);
156  $this->assertEquals(true, $subject->getErrorHandler(124) instanceof ‪PageErrorHandlerInterface);
157  $this->assertEquals(true, $subject->getErrorHandler(125) instanceof ‪PageErrorHandlerInterface);
158  }
159 
164  {
165  $this->expectException(InvalidPageErrorHandlerException::class);
166  $this->expectExceptionCode(1527432330);
167  $this->expectExceptionMessage('The configured error handler "' . Random::class . '" for status code 404 must implement the PageErrorHandlerInterface.');
168  $subject = new ‪Site('aint-misbehaving', 13, [
169  'languages' => [],
170  'errorHandling' => [
171  [
172  'errorCode' => 404,
173  'errorHandler' => 'PHP',
174  'errorPhpClassFQCN' => Random::class
175  ],
176  ]
177  ]);
178  $subject->getErrorHandler(404);
179  }
180 
185  {
186  $this->expectException(PageErrorHandlerNotConfiguredException::class);
187  $this->expectExceptionCode(1522495914);
188  $this->expectExceptionMessage('No error handler given for the status code "404".');
189  $subject = new ‪Site('aint-misbehaving', 13, ['languages' => []]);
190  $subject->getErrorHandler(404);
191  }
192 
197  {
198  $this->expectException(PageErrorHandlerNotConfiguredException::class);
199  $this->expectExceptionCode(1522495914);
200  $this->expectExceptionMessage('No error handler given for the status code "404".');
201  $subject = new ‪Site('aint-misbehaving', 13, [
202  'languages' => [],
203  'errorHandling' => [
204  [
205  'errorCode' => 403,
206  'errorHandler' => 'Does it really matter?'
207  ],
208  ]
209  ]);
210  $subject->getErrorHandler(404);
211  }
212 }
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getErrorHandlerThrowsExceptionOnInvalidErrorHandler
‪getErrorHandlerThrowsExceptionOnInvalidErrorHandler()
Definition: SiteTest.php:163
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getBaseForSiteLanguageReturnsProperUriDataProvider
‪getBaseForSiteLanguageReturnsProperUriDataProvider()
Definition: SiteTest.php:68
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getErrorHandlerReturnsConfiguredErrorHandler
‪getErrorHandlerReturnsConfiguredErrorHandler()
Definition: SiteTest.php:129
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity
Definition: PseudoSiteTest.php:4
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getBaseReturnsProperUriDataProvider
‪getBaseReturnsProperUriDataProvider()
Definition: SiteTest.php:32
‪TYPO3\CMS\Core\Error\PageErrorHandler\FluidPageErrorHandler
Definition: FluidPageErrorHandler.php:31
‪TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerNotConfiguredException
Definition: PageErrorHandlerNotConfiguredException.php:26
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getErrorHandlerThrowsExceptionWhenNoErrorHandlerForStatusCodeIsConfigured
‪getErrorHandlerThrowsExceptionWhenNoErrorHandlerForStatusCodeIsConfigured()
Definition: SiteTest.php:196
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:27
‪TYPO3\CMS\Core\Error\PageErrorHandler\InvalidPageErrorHandlerException
Definition: InvalidPageErrorHandlerException.php:26
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getBaseForSiteLanguageReturnsProperUri
‪getBaseForSiteLanguageReturnsProperUri($siteBase, $languageBase, $expected)
Definition: SiteTest.php:111
‪TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler
Definition: PageContentErrorHandler.php:38
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest
Definition: SiteTest.php:31
‪TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface
Definition: PageErrorHandlerInterface.php:28
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getBaseReturnsProperUri
‪getBaseReturnsProperUri($input, $expected)
Definition: SiteTest.php:53
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:22
‪TYPO3\CMS\Core\Tests\Unit\Site\Entity\SiteTest\getErrorHandlerThrowsExceptionWhenNoErrorHandlerIsConfigured
‪getErrorHandlerThrowsExceptionWhenNoErrorHandlerIsConfigured()
Definition: SiteTest.php:184
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45