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