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