91a697c1155a09aebcf7f37b5d2e8aa8b076b2c6
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Site / Entity / SiteTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Tests\Unit\Site\Entity;
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
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Error\PageErrorHandler\FluidPageErrorHandler;
21 use TYPO3\CMS\Core\Error\PageErrorHandler\InvalidPageErrorHandlerException;
22 use TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler;
23 use TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface;
24 use TYPO3\CMS\Core\Site\Entity\Site;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27
28 class SiteTest extends UnitTestCase
29 {
30 /**
31 * @test
32 */
33 public function getErrorHandlerReturnsConfiguredErrorHandler()
34 {
35 $subject = new Site('aint-misbehaving', 13, [
36 'languages' => [],
37 'errorHandling' => [
38 [
39 'errorCode' => 123,
40 'errorHandler' => 'Fluid',
41 ],
42 [
43 'errorCode' => 124,
44 'errorContentSource' => 123,
45 'errorHandler' => 'Page'
46 ],
47 [
48 'errorCode' => 125,
49 'errorHandler' => 'PHP',
50 'errorContentSource' => 123,
51 'errorPhpClassFQCN' => PageContentErrorHandler::class
52 ]
53 ]
54 ]);
55
56 $fluidProphecy = $this->prophesize(FluidPageErrorHandler::class);
57 GeneralUtility::addInstance(FluidPageErrorHandler::class, $fluidProphecy->reveal());
58
59 $this->assertEquals(true, $subject->getErrorHandler(123) instanceof PageErrorHandlerInterface);
60 $this->assertEquals(true, $subject->getErrorHandler(124) instanceof PageErrorHandlerInterface);
61 $this->assertEquals(true, $subject->getErrorHandler(125) instanceof PageErrorHandlerInterface);
62 }
63
64 /**
65 * @test
66 */
67 public function getErrorHandlerThrowsExceptionOnInvalidErrorHandler()
68 {
69 $this->expectException(InvalidPageErrorHandlerException::class);
70 $this->expectExceptionCode(1527432330);
71 $this->expectExceptionMessage('The configured error handler "' . BackendUtility::class . '" for status code 404 must implement the PageErrorHandlerInterface.');
72 $subject = new Site('aint-misbehaving', 13, [
73 'languages' => [],
74 'errorHandling' => [
75 [
76 'errorCode' => 404,
77 'errorHandler' => 'PHP',
78 'errorPhpClassFQCN' => BackendUtility::class
79 ],
80 ]
81 ]);
82 $subject->getErrorHandler(404);
83 }
84
85 /**
86 * @test
87 */
88 public function getErrorHandlerThrowsExceptionWhenNoErrorHandlerIsConfigured()
89 {
90 $this->expectException(\RuntimeException::class);
91 $this->expectExceptionCode(1522495914);
92 $this->expectExceptionMessage('No error handler given for the status code "404".');
93 $subject = new Site('aint-misbehaving', 13, ['languages' => []]);
94 $subject->getErrorHandler(404);
95 }
96
97 /**
98 * @test
99 */
100 public function getErrorHandlerThrowsExceptionWhenNoErrorHandlerForStatusCodeIsConfigured()
101 {
102 $this->expectException(\RuntimeException::class);
103 $this->expectExceptionCode(1522495914);
104 $this->expectExceptionMessage('No error handler given for the status code "404".');
105 $subject = new Site('aint-misbehaving', 13, [
106 'languages' => [],
107 'errorHandling' => [
108 [
109 'errorCode' => 403,
110 'errorHandler' => 'Does it really matter?'
111 ],
112 ]
113 ]);
114 $subject->getErrorHandler(404);
115 }
116 }