[TASK] Update copyright year to 2013
[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 * Copyright notice
6 *
7 * (c) 2012-2013 Oliver Klee <typo3-coding@oliverklee.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * testcase for the \TYPO3\CMS\Core\Error\ProductionExceptionHandler class.
29 *
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 */
32 class ProductionExceptionHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Error\ProductionExceptionHandler|\PHPUnit_Framework_MockObject_MockObject
36 */
37 private $fixture = NULL;
38
39 /**
40 * Sets up this test case.
41 */
42 protected function setUp() {
43 $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler', array('discloseExceptionInformation', 'sendStatusHeaders', 'writeLogEntries'), array(), '', FALSE);
44 $this->fixture->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(TRUE));
45 }
46
47 /**
48 * Tears down this test case.
49 */
50 protected function tearDown() {
51 unset($this->fixture);
52 }
53
54 /**
55 * @test
56 */
57 public function echoExceptionWebEscapesExceptionMessage() {
58 $message = '<b>b</b><script>alert(1);</script>';
59 $exception = new \Exception($message);
60 ob_start();
61 $this->fixture->echoExceptionWeb($exception);
62 $output = ob_get_contents();
63 ob_end_clean();
64 $this->assertContains(htmlspecialchars($message), $output);
65 $this->assertNotContains($message, $output);
66 }
67
68 /**
69 * @test
70 */
71 public function echoExceptionWebEscapesExceptionTitle() {
72 $title = '<b>b</b><script>alert(1);</script>';
73 /** @var $exception \Exception|\PHPUnit_Framework_MockObject_MockObject */
74 $exception = $this->getMock('Exception', array('getTitle'), array('some message'));
75 $exception->expects($this->any())->method('getTitle')->will($this->returnValue($title));
76 ob_start();
77 $this->fixture->echoExceptionWeb($exception);
78 $output = ob_get_contents();
79 ob_end_clean();
80 $this->assertContains(htmlspecialchars($title), $output);
81 $this->assertNotContains($title, $output);
82 }
83
84 }
85
86 ?>