‪TYPO3CMS  11.5
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 
20 use Prophecy\PhpUnit\ProphecyTrait;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪ErrorControllerTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33  protected ‪$resetSingletonInstances = true;
34 
39  {
40  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
41  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
42  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
43  ‪$GLOBALS['TYPO3_REQUEST'] = [];
44  $subject = new ‪ErrorController();
45  $response = $subject->pageNotFoundAction(new ‪ServerRequest(), 'This test page was not found!');
46  self::assertSame(404, $response->getStatusCode());
47  self::assertStringContainsString('This test page was not found!', $response->getBody()->getContents());
48  }
49 
54  {
55  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
56  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
57  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
58  ‪$GLOBALS['TYPO3_REQUEST'] = [];
59  $subject = new ‪ErrorController();
60  $response = $subject->unavailableAction(new ‪ServerRequest(), 'This page is temporarily unavailable.');
61  self::assertSame(503, $response->getStatusCode());
62  self::assertStringContainsString('This page is temporarily unavailable.', $response->getBody()->getContents());
63  }
64 
69  {
70  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
71  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
72 
73  $this->expectExceptionMessage('All your system are belong to us!');
74  $this->expectExceptionCode(1518472181);
75  $subject = new ErrorController();
76  $subject->unavailableAction(new ServerRequest(), 'All your system are belong to us!');
77  }
78 
83  {
84  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
85  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
86  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
87  $subject = new ErrorController();
88  $response = $subject->internalErrorAction(new ServerRequest(), 'All your system are belong to us!');
89  self::assertSame(500, $response->getStatusCode());
90  self::assertStringContainsString('All your system are belong to us!', $response->getBody()->getContents());
91  }
92 
97  {
98  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
99  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
100 
101  $this->expectExceptionMessage('All your system are belong to us!');
102  $this->expectExceptionCode(1607585445);
103  $subject = new ErrorController();
104  $subject->internalErrorAction(new ServerRequest(), 'All your system are belong to us!');
105  }
106 
111  {
112  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
113  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
114  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
115  $subject = new ErrorController();
116  $response = $subject->pageNotFoundAction(new ServerRequest(), 'Error handler is not configured.');
117  self::assertSame(404, $response->getStatusCode());
118  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
119  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
120  }
121 
126  {
127  $subject = new ErrorController();
128  $response = $subject->pageNotFoundAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
129  $responseContent = \json_decode($response->getBody()->getContents(), true);
130  self::assertSame(404, $response->getStatusCode());
131  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
132  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
133  }
134 
139  {
140  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
141  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
142  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
143  $subject = new ErrorController();
144  $response = $subject->unavailableAction(new ServerRequest(), 'Error handler is not configured.');
145  self::assertSame(503, $response->getStatusCode());
146  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
147  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
148  }
149 
154  {
155  $subject = new ErrorController();
156  $response = $subject->unavailableAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
157  $responseContent = \json_decode($response->getBody()->getContents(), true);
158  self::assertSame(503, $response->getStatusCode());
159  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
160  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
161  }
162 
167  {
168  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
169  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
170  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
171  $subject = new ErrorController();
172  $response = $subject->internalErrorAction(new ServerRequest(), 'Error handler is not configured.');
173  self::assertSame(500, $response->getStatusCode());
174  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
175  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
176  }
177 
182  {
183  $subject = new ErrorController();
184  $response = $subject->internalErrorAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
185  $responseContent = \json_decode($response->getBody()->getContents(), true);
186  self::assertSame(500, $response->getStatusCode());
187  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
188  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
189  }
190 
195  {
196  $typo3InformationProphecy = $this->prophesize(Typo3Information::class);
197  $typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
198  GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
199  $subject = new ErrorController();
200  $response = $subject->accessDeniedAction(new ServerRequest(), 'Error handler is not configured.');
201  self::assertSame(403, $response->getStatusCode());
202  self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
203  self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
204  }
205 
210  {
211  $subject = new ErrorController();
212  $response = $subject->accessDeniedAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
213  $responseContent = \json_decode($response->getBody()->getContents(), true);
214  self::assertSame(403, $response->getStatusCode());
215  self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
216  self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
217  }
218 }
‪TYPO3\CMS\Core\Information\Typo3Information
Definition: Typo3Information.php:28
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction()
Definition: ErrorControllerTest.php:180
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction()
Definition: ErrorControllerTest.php:165
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction()
Definition: ErrorControllerTest.php:208
‪TYPO3\CMS\Frontend\Controller\ErrorController
Definition: ErrorController.php:39
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForUnavailableAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForUnavailableAction()
Definition: ErrorControllerTest.php:137
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\internalErrorHandlingDoesNotTriggerDueToDevIpMask
‪internalErrorHandlingDoesNotTriggerDueToDevIpMask()
Definition: ErrorControllerTest.php:95
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction()
Definition: ErrorControllerTest.php:109
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\internalErrorHandlingReturns500ResponseIfNotConfigured
‪internalErrorHandlingReturns500ResponseIfNotConfigured()
Definition: ErrorControllerTest.php:81
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: ErrorControllerTest.php:32
‪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:152
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\pageNotFoundHandlingReturns404ResponseIfNotConfigured
‪pageNotFoundHandlingReturns404ResponseIfNotConfigured()
Definition: ErrorControllerTest.php:37
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest
Definition: ErrorControllerTest.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\unavailableHandlingReturns503ResponseIfNotConfigured
‪unavailableHandlingReturns503ResponseIfNotConfigured()
Definition: ErrorControllerTest.php:52
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction
‪defaultErrorHandlerWithHtmlResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction()
Definition: ErrorControllerTest.php:193
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\unavailableHandlingDoesNotTriggerDueToDevIpMask
‪unavailableHandlingDoesNotTriggerDueToDevIpMask()
Definition: ErrorControllerTest.php:67
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Frontend\Tests\Unit\Controller\ErrorControllerTest\defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction
‪defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction()
Definition: ErrorControllerTest.php:124