[TASK] Namespace and move t3lib unit tests - 3
[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 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 * @package TYPO3
32 * @subpackage t3lib_error
33 */
34 class ProductionExceptionHandlerTest extends \Tx_Phpunit_TestCase {
35
36 /**
37 * @var \TYPO3\CMS\Core\Error\ProductionExceptionHandler|PHPUnit_Framework_MockObject_MockObject
38 */
39 private $fixture = NULL;
40
41 /**
42 * Sets up this test case.
43 */
44 protected function setUp() {
45 $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler', array('discloseExceptionInformation', 'sendStatusHeaders', 'writeLogEntries'), array(), '', FALSE);
46 $this->fixture->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(TRUE));
47 }
48
49 /**
50 * Tears down this test case.
51 */
52 protected function tearDown() {
53 unset($this->fixture);
54 }
55
56 /**
57 * @test
58 */
59 public function echoExceptionWebEscapesExceptionMessage() {
60 $message = '<b>b</b><script>alert(1);</script>';
61 $exception = new \Exception($message);
62 ob_start();
63 $this->fixture->echoExceptionWeb($exception);
64 $output = ob_get_contents();
65 ob_end_clean();
66 $this->assertContains(htmlspecialchars($message), $output);
67 $this->assertNotContains($message, $output);
68 }
69
70 /**
71 * @test
72 */
73 public function echoExceptionWebEscapesExceptionTitle() {
74 $title = '<b>b</b><script>alert(1);</script>';
75 /** @var $exception Exception|PHPUnit_Framework_MockObject_MockObject */
76 $exception = $this->getMock('Exception', array('getTitle'), array('some message'));
77 $exception->expects($this->any())->method('getTitle')->will($this->returnValue($title));
78 ob_start();
79 $this->fixture->echoExceptionWeb($exception);
80 $output = ob_get_contents();
81 ob_end_clean();
82 $this->assertContains(htmlspecialchars($title), $output);
83 $this->assertNotContains($title, $output);
84 }
85
86 }
87
88 ?>