[TASK] Add unit test to cover stdWrap_debugFunc 60/48860/4
authorElmar Hinz <t3elmar@gmail.com>
Fri, 8 Jul 2016 15:15:18 +0000 (17:15 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 9 Jul 2016 14:56:40 +0000 (16:56 +0200)
Releases: master
Resolves: #76856
Change-Id: I88c54d559a06146439c7237802308f3857295953
Reviewed-on: https://review.typo3.org/48860
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 66d486f..214ad8b 100644 (file)
@@ -5312,6 +5312,59 @@ class ContentObjectRendererTest extends UnitTestCase
         $this->assertContains($altValue, $out);
     }
 
+    /*
+     * Data provider for stdWrap_debugFunc.
+     *
+     * @return array [$expectArray, $confDebugFunc]
+     */
+    public function stdWrap_debugFuncDataProvider()
+    {
+        return [
+            'expect array by string' => [ true, '2' ],
+            'expect array by integer' => [ true, 2 ],
+            'do not expect array' => [ false, '' ],
+        ];
+    }
+
+    /**
+     * Check if stdWrap_debugFunc works properly.
+     *
+     * Show:
+     *
+     * - Calls the function debug with one paramter.
+     * - The parameter is the given $content string.
+     * - The string is casted to array before, if (int)$conf['debugFunc'] is 2.
+     * - Returns $content as is.
+     *
+     * Note 1:
+     *
+     *   As PHPUnit can't mock PHP function calls, the call to debug can't be
+     *   easily intercepted. The test is done indirectly by catching the
+     *   frontend output of debug.
+     *
+     * @test
+     * @dataProvider stdWrap_debugFuncDataProvider
+     * @param bool $expectArray If cast to array is expected.
+     * @param mixed $confDebugFunc The configuration for $conf['debugFunc'].
+     * @return void
+     */
+    public function stdWrap_debugFunc($expectArray, $confDebugFunc)
+    {
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
+        $content = $this->getUniqueId('content');
+        $conf = ['debugFunc' => $confDebugFunc];
+        ob_start();
+        $result = $this->subject->stdWrap_debugFunc($content, $conf);
+        $out = ob_get_clean();
+        $this->assertSame($result, $content);
+        $this->assertContains($content, $out);
+        if ($expectArray) {
+            $this->assertContains('=>', $out);
+        } else {
+            $this->assertNotContains('=>', $out);
+        }
+    }
+
     /**
      * Data provider for stdWrap_doubleBrTag
      *