‪TYPO3CMS  10.4
DebugUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪DebugUtilityTest extends UnitTestCase
25 {
26  protected function ‪tearDown(): void
27  {
28  parent::tearDown();
31  }
32 
37  {
40 
41  ob_start();
42  ‪DebugUtility::debug('<script>alert(\'Hello world!\')</script>');
43  ‪$output = ob_get_contents();
44  ob_end_clean();
45 
46  self::assertStringContainsString(
47  '<script>alert(\'Hello world!\')</script>',
49  );
50  }
51 
56  {
59 
60  ob_start();
61  ‪DebugUtility::debug('<script>alert(\'Hello world!\')</script>');
62  ‪$output = ob_get_contents();
63  ob_end_clean();
64 
65  self::assertStringContainsString(
66  '&lt;script&gt;alert(\'Hello world!\')&lt;/script&gt;',
68  );
69  }
70 
75  {
76  $object = new \stdClass();
77  $object->foo = 42;
78  $object->bar = ['baz'];
79 
80  return [
81  'Debug string' => [
82  'Hello world!',
83  '"Hello world!" (12 chars)',
84  ],
85  'Debug array' => [
86  [
87  'foo',
88  'bar',
89  'baz' => [
90  42,
91  ],
92  ],
93  'array(3 items)' . PHP_EOL
94  . ' 0 => "foo" (3 chars)' . PHP_EOL
95  . ' 1 => "bar" (3 chars)' . PHP_EOL
96  . ' baz => array(1 item)' . PHP_EOL
97  . ' 0 => 42 (integer)',
98  ],
99  'Debug object' => [
100  $object,
101  'stdClass prototype object' . PHP_EOL
102  . ' foo => public 42 (integer)' . PHP_EOL
103  . ' bar => public array(1 item)' . PHP_EOL
104  . ' 0 => "baz" (3 chars)'
105  ],
106  ];
107  }
108 
115  public function ‪convertVariableToStringReturnsVariableContent($variable, $expected)
116  {
117  self::assertSame($expected, ‪DebugUtility::convertVariableToString($variable));
118  }
119 }
‪TYPO3\CMS\Core\Utility\DebugUtility\debug
‪static debug($var='', $header='Debug', $group='Debug')
Definition: DebugUtility.php:43
‪TYPO3\CMS\Core\Utility\DebugUtility\usePlainTextOutput
‪static usePlainTextOutput($plainTextOutput)
Definition: DebugUtility.php:238
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\convertVariableToStringReturnsVariableContent
‪convertVariableToStringReturnsVariableContent($variable, $expected)
Definition: DebugUtilityTest.php:115
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\convertVariableToStringReturnsVariableContentDataProvider
‪array convertVariableToStringReturnsVariableContentDataProvider()
Definition: DebugUtilityTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest
Definition: DebugUtilityTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\debugEncodesHtmlInputIfNoPlainText
‪debugEncodesHtmlInputIfNoPlainText()
Definition: DebugUtilityTest.php:55
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\debugNotEncodesHtmlInputIfPlainText
‪debugNotEncodesHtmlInputIfPlainText()
Definition: DebugUtilityTest.php:36
‪TYPO3\CMS\Core\Utility\DebugUtility
Definition: DebugUtility.php:25
‪TYPO3\CMS\Core\Utility\DebugUtility\useAnsiColor
‪static useAnsiColor($ansiColorUsage)
Definition: DebugUtility.php:253
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\tearDown
‪tearDown()
Definition: DebugUtilityTest.php:26
‪TYPO3\CMS\Core\Utility\DebugUtility\convertVariableToString
‪static string convertVariableToString($variable)
Definition: DebugUtility.php:81