[TASK] Add unit test to cover prefixComment 19/52219/6
authorElmar Hinz <t3elmar@gmail.com>
Tue, 28 Mar 2017 15:58:26 +0000 (17:58 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 28 Mar 2017 19:00:57 +0000 (21:00 +0200)
Add unit test to cover ContentObjectRenderer::prefixComment

Resolves: #80526
Releases: master
Change-Id: I37e89ecfdb2cea2f9290eced97337c0019e78ba9
Reviewed-on: https://review.typo3.org/52219
Tested-by: TYPO3com <no-reply@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>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index b2ca3f7..84f7c0b 100644 (file)
@@ -3445,6 +3445,65 @@ class ContentObjectRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTe
             $subject->HTMLcaseshift($content, $case));
     }
 
+    /**
+     * Data provider for prefixComment.
+     *
+     * @return array [$expect, $comment, $content]
+     */
+    public function prefixCommentDataProvider()
+    {
+        $comment = $this->getUniqueId();
+        $content = $this->getUniqueId();
+        $format = '%s';
+        $format .= '%%s<!-- %%s [begin] -->%s';
+        $format .= '%%s%s%%s%s';
+        $format .= '%%s<!-- %%s [end] -->%s';
+        $format .= '%%s%s';
+        $format = sprintf($format, LF, LF, TAB, LF, LF, TAB);
+        $indent1 = TAB;
+        $indent2 = TAB . TAB;
+        return [
+            'indent one tab' => [
+                sprintf($format,
+                    $indent1, $comment,
+                    $indent1, $content,
+                    $indent1, $comment,
+                    $indent1),
+                '1|' . $comment, $content ],
+            'indent two tabs' => [
+                sprintf($format,
+                    $indent2, $comment,
+                    $indent2, $content,
+                    $indent2, $comment,
+                    $indent2),
+                '2|' . $comment, $content ],
+            'htmlspecialchars applies for comment only' => [
+                sprintf($format,
+                    $indent1, '&lt;' . $comment . '&gt;',
+                    $indent1, '<' . $content . '>',
+                    $indent1, '&lt;' . $comment . '&gt;',
+                    $indent1),
+                '1|' . '<' . $comment . '>', '<' . $content . '>' ],
+        ];
+    }
+
+    /**
+     * Check if prefixComment works properly.
+     *
+     * @test
+     * @dataProvider prefixCommentDataProvider
+     * @param string $expect The expected output.
+     * @param string $comment The parameter $comment.
+     * @param string $content The parameter $content.
+     */
+    public function prefixComment($expect, $comment, $content)
+    {
+        // The parameter $conf is never used. Just provide null.
+        // Consider to improve the signature and deprecate the old one.
+        $result = $this->subject->prefixComment($comment, null, $content);
+        $this->assertEquals($expect, $result);
+    }
+
     /***************************************************************************
     * General tests for stdWrap_
     ***************************************************************************/