[TASK] Instantiate Context through dependency injection
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Error / ProductionExceptionHandlerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Error;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18
19 /**
20 * testcase for the \TYPO3\CMS\Core\Error\ProductionExceptionHandler class.
21 */
22 class ProductionExceptionHandlerTest extends UnitTestCase
23 {
24 /**
25 * @var \TYPO3\CMS\Core\Error\ProductionExceptionHandler|\PHPUnit_Framework_MockObject_MockObject
26 */
27 protected $subject;
28
29 /**
30 * Sets up this test case.
31 */
32 protected function setUp(): void
33 {
34 parent::setUp();
35 $this->subject = $this->getMockBuilder(\TYPO3\CMS\Core\Error\ProductionExceptionHandler::class)
36 ->setMethods(['discloseExceptionInformation', 'sendStatusHeaders', 'writeLogEntries'])
37 ->disableOriginalConstructor()
38 ->getMock();
39 $this->subject->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(true));
40 }
41
42 /**
43 * @test
44 */
45 public function echoExceptionWebEscapesExceptionMessage()
46 {
47 $message = '<b>b</b><script>alert(1);</script>';
48 $exception = new \Exception($message, 1476049364);
49 ob_start();
50 $this->subject->echoExceptionWeb($exception);
51 $output = ob_get_contents();
52 ob_end_clean();
53 $this->assertStringContainsString(htmlspecialchars($message), $output);
54 $this->assertStringNotContainsString($message, $output);
55 }
56
57 /**
58 * @test
59 */
60 public function echoExceptionWebEscapesExceptionTitle()
61 {
62 $title = '<b>b</b><script>alert(1);</script>';
63 /** @var $exception \Exception|\PHPUnit_Framework_MockObject_MockObject */
64 $exception = $this->getMockBuilder('Exception')
65 ->setMethods(['getTitle'])
66 ->setConstructorArgs(['some message'])
67 ->getMock();
68 $exception->expects($this->any())->method('getTitle')->will($this->returnValue($title));
69 ob_start();
70 $this->subject->echoExceptionWeb($exception);
71 $output = ob_get_contents();
72 ob_end_clean();
73 $this->assertStringContainsString(htmlspecialchars($title), $output);
74 $this->assertStringNotContainsString($title, $output);
75 }
76 }