‪TYPO3CMS  ‪main
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 final 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 
74  {
75  $object = new \stdClass();
76  $object->foo = 42;
77  $object->bar = ['baz'];
78 
79  return [
80  'Debug string' => [
81  'Hello world!',
82  '"Hello world!" (12 chars)',
83  ],
84  'Debug array' => [
85  [
86  'foo',
87  'bar',
88  'baz' => [
89  42,
90  ],
91  ],
92  'array(3 items)' . PHP_EOL
93  . ' 0 => "foo" (3 chars)' . PHP_EOL
94  . ' 1 => "bar" (3 chars)' . PHP_EOL
95  . ' baz => array(1 item)' . PHP_EOL
96  . ' 0 => 42 (integer)',
97  ],
98  'Debug object' => [
99  $object,
100  'stdClass prototype object' . PHP_EOL
101  . ' foo => public 42 (integer)' . PHP_EOL
102  . ' bar => public array(1 item)' . PHP_EOL
103  . ' 0 => "baz" (3 chars)',
104  ],
105  ];
106  }
107 
113  public function ‪convertVariableToStringReturnsVariableContent($variable, string $expected): void
114  {
115  self::assertSame($expected, ‪DebugUtility::convertVariableToString($variable));
116  }
117 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\convertVariableToStringReturnsVariableContent
‪convertVariableToStringReturnsVariableContent($variable, string $expected)
Definition: DebugUtilityTest.php:113
‪TYPO3\CMS\Core\Utility\DebugUtility\usePlainTextOutput
‪static usePlainTextOutput(bool $plainTextOutput)
Definition: DebugUtility.php:140
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\convertVariableToStringReturnsVariableContentDataProvider
‪static convertVariableToStringReturnsVariableContentDataProvider()
Definition: DebugUtilityTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Utility\DebugUtility\useAnsiColor
‪static useAnsiColor(bool $ansiColorUsage)
Definition: DebugUtility.php:154
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest
Definition: DebugUtilityTest.php:27
‪TYPO3\CMS\Core\Utility\DebugUtility\debug
‪static debug(mixed $var='', string $header='Debug')
Definition: DebugUtility.php:37
‪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
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\tearDown
‪tearDown()
Definition: DebugUtilityTest.php:28
‪TYPO3\CMS\Core\Utility\DebugUtility\convertVariableToString
‪static string convertVariableToString(mixed $variable)
Definition: DebugUtility.php:52