‪TYPO3CMS  10.4
ErrorControllerTest.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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪ErrorControllerTest extends UnitTestCase
30 {
31  protected ‪$resetSingletonInstances = true;
32 
37  {
38  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
39  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
40  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
41  ‪$GLOBALS['TYPO3_REQUEST'] = [];
42  $subject = new ‪ErrorController();
43  $response = $subject->pageNotFoundAction(new ‪ServerRequest(), 'This test page was not found!');
44  self::assertSame(404, $response->getStatusCode());
45  self::assertStringContainsString('This test page was not found!', $response->getBody()->getContents());
46  }
47 
52  {
53  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
54  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
55  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
56  ‪$GLOBALS['TYPO3_REQUEST'] = [];
57  $subject = new ‪ErrorController();
58  $response = $subject->unavailableAction(new ‪ServerRequest(), 'This page is temporarily unavailable.');
59  self::assertSame(503, $response->getStatusCode());
60  self::assertStringContainsString('This page is temporarily unavailable.', $response->getBody()->getContents());
61  }
62 
67  {
68  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
69  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
70 
71  $this->expectExceptionMessage('All your system are belong to us!');
72  $this->expectExceptionCode(1518472181);
73  $subject = new ‪ErrorController();
74  $subject->unavailableAction(new ‪ServerRequest(), 'All your system are belong to us!');
75  }
76 
81  {
82  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
83  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
84  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
85  $subject = new ‪ErrorController();
86  $response = $subject->internalErrorAction(new ‪ServerRequest(), 'All your system are belong to us!');
87  self::assertSame(500, $response->getStatusCode());
88  self::assertStringContainsString('All your system are belong to us!', $response->getBody()->getContents());
89  }
90 
95  {
96  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
97  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
98 
99  $this->expectExceptionMessage('All your system are belong to us!');
100  $this->expectExceptionCode(1607585445);
101  $subject = new ‪ErrorController();
102  $subject->internalErrorAction(new ‪ServerRequest(), 'All your system are belong to us!');
103  }
104 
109  {
110  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
111  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
112  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
113  $subject = new ‪ErrorController();
114  $response = $subject->pageNotFoundAction(new ‪ServerRequest(), 'Error handler is not configured.');
115  self::assertSame(404, $response->getStatusCode());
116  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
117  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
118  }
119 
124  {
125  $subject = new ‪ErrorController();
126  $response = $subject->pageNotFoundAction((new ‪ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
127  $responseContent = \json_decode($response->getBody()->getContents(), true);
128  self::assertSame(404, $response->getStatusCode());
129  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
130  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
131  }
132 
137  {
138  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
139  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
140  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
141  $subject = new ‪ErrorController();
142  $response = $subject->unavailableAction(new ‪ServerRequest(), 'Error handler is not configured.');
143  self::assertSame(503, $response->getStatusCode());
144  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
145  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
146  }
147 
152  {
153  $subject = new ‪ErrorController();
154  $response = $subject->unavailableAction((new ‪ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
155  $responseContent = \json_decode($response->getBody()->getContents(), true);
156  self::assertSame(503, $response->getStatusCode());
157  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
158  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
159  }
160 
165  {
166  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
167  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
168  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
169  $subject = new ‪ErrorController();
170  $response = $subject->internalErrorAction(new ‪ServerRequest(), 'Error handler is not configured.');
171  self::assertSame(500, $response->getStatusCode());
172  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
173  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
174  }
175 
180  {
181  $subject = new ‪ErrorController();
182  $response = $subject->internalErrorAction((new ‪ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
183  $responseContent = \json_decode($response->getBody()->getContents(), true);
184  self::assertSame(500, $response->getStatusCode());
185  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
186  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
187  }
188 
193  {
194  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
195  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
196  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
197  $subject = new ‪ErrorController();
198  $response = $subject->accessDeniedAction(new ‪ServerRequest(), 'Error handler is not configured.');
199  self::assertSame(403, $response->getStatusCode());
200  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
201  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
202  }
203 
208  {
209  $subject = new ‪ErrorController();
210  $response = $subject->accessDeniedAction((new ‪ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
211  $responseContent = \json_decode($response->getBody()->getContents(), true);
212  self::assertSame(403, $response->getStatusCode());
213  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
214  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
215  }
216 }
‪TYPO3\CMS\Core\Information\Typo3Information
Definition: Typo3Information.php:26
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction()
Definition: ErrorControllerTest.php:179
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction()
Definition: ErrorControllerTest.php:164
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction()
Definition: ErrorControllerTest.php:207
‪TYPO3\CMS\Frontend\Controller\ErrorController
Definition: ErrorController.php:38
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForUnavailableAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForUnavailableAction()
Definition: ErrorControllerTest.php:136
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\internalErrorHandlingDoesNotTriggerDueToDevIpMask
‪internalErrorHandlingDoesNotTriggerDueToDevIpMask()
Definition: ErrorControllerTest.php:94
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction()
Definition: ErrorControllerTest.php:108
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\internalErrorHandlingReturns500ResponseIfNotConfigured
‪internalErrorHandlingReturns500ResponseIfNotConfigured()
Definition: ErrorControllerTest.php:80
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: ErrorControllerTest.php:31
‪TYPO3\CMS\Frontend\Tests\Unit\Controller
Definition: ErrorControllerTest.php:18
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForUnavailableAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForUnavailableAction()
Definition: ErrorControllerTest.php:151
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\pageNotFoundHandlingReturns404ResponseIfNotConfigured
‪pageNotFoundHandlingReturns404ResponseIfNotConfigured()
Definition: ErrorControllerTest.php:36
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest
Definition: ErrorControllerTest.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\unavailableHandlingReturns503ResponseIfNotConfigured
‪unavailableHandlingReturns503ResponseIfNotConfigured()
Definition: ErrorControllerTest.php:51
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction()
Definition: ErrorControllerTest.php:192
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\unavailableHandlingDoesNotTriggerDueToDevIpMask
‪unavailableHandlingDoesNotTriggerDueToDevIpMask()
Definition: ErrorControllerTest.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction()
Definition: ErrorControllerTest.php:123