TYPO3 CMS  TYPO3_8-7
DebugUtilityTest.php
Go to the documentation of this file.
1 <?php
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 
18 
22 class DebugUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
24  protected function tearDown()
25  {
26  parent::tearDown();
29  }
30 
35  {
38 
39  ob_start();
40  DebugUtility::debug('<script>alert(\'Hello world!\')</script>');
41  $output = ob_get_contents();
42  ob_end_clean();
43 
44  $this->assertContains(
45  '<script>alert(\'Hello world!\')</script>',
46  $output
47  );
48  }
49 
54  {
57 
58  ob_start();
59  DebugUtility::debug('<script>alert(\'Hello world!\')</script>');
60  $output = ob_get_contents();
61  ob_end_clean();
62 
63  $this->assertContains(
64  '&lt;script&gt;alert(\'Hello world!\')&lt;/script&gt;',
65  $output
66  );
67  }
68 
73  {
74  $object = new \stdClass();
75  $object->foo = 42;
76  $object->bar = ['baz'];
77 
78  return [
79  'Debug string' => [
80  'Hello world!',
81  '"Hello world!" (12 chars)',
82  ],
83  'Debug array' => [
84  [
85  'foo',
86  'bar',
87  'baz' => [
88  42,
89  ],
90  ],
91  'array(3 items)' . PHP_EOL
92  . ' 0 => "foo" (3 chars)' . PHP_EOL
93  . ' 1 => "bar" (3 chars)' . PHP_EOL
94  . ' baz => array(1 item)' . PHP_EOL
95  . ' 0 => 42 (integer)',
96  ],
97  'Debug object' => [
98  $object,
99  'stdClass prototype object' . PHP_EOL
100  . ' foo => public 42 (integer)' . PHP_EOL
101  . ' bar => public array(1 item)' . PHP_EOL
102  . ' 0 => "baz" (3 chars)'
103  ],
104  ];
105  }
106 
113  public function convertVariableToStringReturnsVariableContent($variable, $expected)
114  {
115  $this->assertSame($expected, DebugUtility::convertVariableToString($variable));
116  }
117 }
static useAnsiColor($ansiColorUsage)
static convertVariableToString($variable)
static debug($var='', $header='Debug', $group='Debug')
static usePlainTextOutput($plainTextOutput)