[TASK] Add unit test to cover stdWrap_debugData 58/48858/4
authorElmar Hinz <t3elmar@gmail.com>
Fri, 8 Jul 2016 14:29:14 +0000 (16:29 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 9 Jul 2016 14:30:24 +0000 (16:30 +0200)
Releases: master
Resolves: #76858
Change-Id: Ib5272ded084a3fe1ef62139bd8aac7f17e9839bd
Reviewed-on: https://review.typo3.org/48858
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 97ad888..66d486f 100644 (file)
@@ -5260,6 +5260,59 @@ class ContentObjectRendererTest extends UnitTestCase
     }
 
     /**
+     * Check if stdWrap_debug works properly.
+     *
+     * Show:
+     *
+     * - Calls the function debug.
+     * - Parameter 1 is $this->data.
+     * - Parameter 2 is the string '$cObj->data:'.
+     * - If $this->alternativeData is an array the same is repeated with:
+     * - Parameter 1 is $this->alternativeData.
+     * - Parameter 2 is the string '$cObj->alternativeData:'.
+     * - 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.
+     *
+     * Note 2:
+     *
+     *   The second paramter to the debug function isn't used by the current
+     *   implementation at all. It can't even indirectly be tested.
+     *
+     * @test
+     * @return void
+     */
+    public function stdWrap_debugData()
+    {
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
+        $content = $this->getUniqueId('content');
+        $key = $this->getUniqueId('key');
+        $value = $this->getUniqueId('value');
+        $altValue = $this->getUniqueId('value alt');
+        $this->subject->data = [$key => $value];
+        // Without alternative data only data is returned.
+        ob_start();
+        $result = $this->subject->stdWrap_debugData($content);
+        $out = ob_get_clean();
+        $this->assertSame($result, $content);
+        $this->assertNotContains('$cObj->data', $out);
+        $this->assertContains($value, $out);
+        $this->assertNotContains($altValue, $out);
+        // By adding alternative data both are returned together.
+        $this->subject->alternativeData = [$key => $altValue];
+        ob_start();
+        $this->subject->stdWrap_debugData($content);
+        $out = ob_get_clean();
+        $this->assertNotContains('$cObj->alternativeData', $out);
+        $this->assertContains($value, $out);
+        $this->assertContains($altValue, $out);
+    }
+
+    /**
      * Data provider for stdWrap_doubleBrTag
      *
      * @return array Order expected, input, config