[BUGFIX] DebuggerUtility changes global blacklist
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Utility / DebuggerUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
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 use TYPO3\CMS\Core\Tests\UnitTestCase;
17 use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
18
19 /**
20 * Test case
21 */
22 class DebuggerUtilityTest extends UnitTestCase
23 {
24 /**
25 * @test
26 */
27 public function debuggerRewindsInstancesOfIterator()
28 {
29 /** @var $objectStorage \TYPO3\CMS\Extbase\Persistence\ObjectStorage */
30 $objectStorage = $this->getMock(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class, ['dummy']);
31 for ($i = 0; $i < 5; $i++) {
32 $obj = new \StdClass();
33 $obj->property = $i;
34 $objectStorage->attach($obj);
35 }
36 DebuggerUtility::var_dump($objectStorage, null, 8, true, false, true);
37 $this->assertTrue($objectStorage->valid());
38 }
39
40 /**
41 * @test
42 */
43 public function debuggerDoesNotRewindInstanceOfArrayAccess()
44 {
45 $parameters = [];
46 for ($i = 0; $i < 5; $i++) {
47 $argument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('argument_' . $i, 'integer');
48 $parameters[$i] = $argument;
49 }
50
51 /** @var $arguments \TYPO3\CMS\Fluid\Core\ViewHelper\Arguments */
52 $arguments = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\Arguments::class, ['dummy'], ['arguments' => $parameters]);
53
54 $arguments->expects($this->never())->method('rewind');
55 DebuggerUtility::var_dump($arguments, null, 8, true, false, true);
56 }
57
58 /**
59 * @test
60 */
61 public function varDumpShowsPropertiesOfStdClassObjects()
62 {
63 $testObject = new \stdClass();
64 $testObject->foo = 'bar';
65 $result = DebuggerUtility::var_dump($testObject, null, 8, true, false, true);
66 $this->assertRegExp('/foo.*bar/', $result);
67 }
68
69 /**
70 * @test
71 * @return void
72 */
73 public function varDumpRespectsBlacklistedProperties()
74 {
75 $testClass = new \stdClass();
76 $testClass->secretData = 'I like cucumber.';
77 $testClass->notSoSecretData = 'I like burger.';
78
79 $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, null, ['secretData']);
80 self::assertNotContains($testClass->secretData, $result);
81 }
82
83 /**
84 * @test
85 * @return void
86 */
87 public function varDumpRespectsBlacklistedClasses()
88 {
89 $testClass = new \stdClass();
90 $testClass->data = 'I like burger.';
91
92 $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, [\stdClass::class]);
93 self::assertNotContains($testClass->data, $result);
94 }
95 }