‪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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 final class ‪DebugUtilityTest extends UnitTestCase
29 {
30  protected function ‪tearDown(): void
31  {
32  parent::tearDown();
35  }
36 
37  #[Test]
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>',
50  $output
51  );
52  }
53 
54  #[Test]
55  public function ‪debugEncodesHtmlInputIfNoPlainText(): void
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;',
67  $output
68  );
69  }
70 
72  {
73  $object = new \stdClass();
74  $object->foo = 42;
75  $object->bar = ['baz'];
76 
77  return [
78  'Debug string' => [
79  'Hello world!',
80  '"Hello world!" (12 chars)',
81  ],
82  'Debug array' => [
83  [
84  'foo',
85  'bar',
86  'baz' => [
87  42,
88  ],
89  ],
90  'array(3 items)' . PHP_EOL
91  . ' 0 => "foo" (3 chars)' . PHP_EOL
92  . ' 1 => "bar" (3 chars)' . PHP_EOL
93  . ' baz => array(1 item)' . PHP_EOL
94  . ' 0 => 42 (integer)',
95  ],
96  'Debug object' => [
97  $object,
98  'stdClass prototype object' . PHP_EOL
99  . ' foo => public 42 (integer)' . PHP_EOL
100  . ' bar => public array(1 item)' . PHP_EOL
101  . ' 0 => "baz" (3 chars)',
102  ],
103  ];
104  }
105 
109  #[DataProvider('convertVariableToStringReturnsVariableContentDataProvider')]
110  #[Test]
111  public function ‪convertVariableToStringReturnsVariableContent($variable, string $expected): void
112  {
113  self::assertSame($expected, ‪DebugUtility::convertVariableToString($variable));
114  }
115 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\DebugUtilityTest\convertVariableToStringReturnsVariableContent
‪convertVariableToStringReturnsVariableContent($variable, string $expected)
Definition: DebugUtilityTest.php:111
‪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:71
‪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:29
‪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:55
‪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\Tests\Unit\Utility\DebugUtilityTest\tearDown
‪tearDown()
Definition: DebugUtilityTest.php:30
‪TYPO3\CMS\Core\Utility\DebugUtility\convertVariableToString
‪static string convertVariableToString(mixed $variable)
Definition: DebugUtility.php:52