[TASK] Add unit tests for HtmlParser::substituteSubpart() 18/42718/5
authorMichael Oehlhof <typo3@oehlhof.de>
Tue, 18 Aug 2015 16:02:24 +0000 (18:02 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 18 Aug 2015 22:15:09 +0000 (00:15 +0200)
Resolves: #69160
Releases: master
Change-Id: I240dd575b6b105846493a608b8039b0883e2a866
Reviewed-on: http://review.typo3.org/42718
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Tests/Unit/Html/HtmlParserTest.php

index f0ea5ae..11f3cfb 100644 (file)
@@ -106,6 +106,134 @@ text
        }
 
        /**
+        * Data provider for substituteSubpart
+        *
+        * @return array
+        */
+       public function substituteSubpartDataProvider() {
+               return array(
+                       'No start marker' => array(
+                               '<body>text</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               FALSE,
+                               '<body>text</body>'
+                       ),
+                       'No stop marker' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->
+text
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               FALSE,
+                               '<body>
+<!-- ###SUBPART### Start -->
+text
+</body>',
+                       ),
+                       'Start and stop marker in HTML comment' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->
+text
+<!-- ###SUBPART### End -->
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               FALSE,
+                               '<body>
+hello
+</body>'
+                       ),
+                       'Recursive subpart' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->text1<!-- ###SUBPART### End -->
+<!-- ###SUBPART### Start -->text2<!-- ###SUBPART### End -->
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               TRUE,
+                               FALSE,
+                               '<body>
+hello
+hello
+</body>'
+                       ),
+                       'Keep HTML marker' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->text<!-- ###SUBPART### End -->
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               TRUE,
+                               '<body>
+<!-- ###SUBPART### Start -->hello<!-- ###SUBPART### End -->
+</body>'
+                       ),
+                       'Keep HTML begin marker' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->text###SUBPART###
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               TRUE,
+                               '<body>
+<!-- ###SUBPART### Start -->hello###SUBPART###
+</body>'
+                       ),
+                       'Keep HTML end marker' => array(
+                               '<body>
+###SUBPART###text<!-- ###SUBPART### End -->
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               TRUE,
+                               '<body>
+###SUBPART###hello<!-- ###SUBPART### End -->
+</body>'
+                       ),
+                       'Keep plain marker' => array(
+                               '<body>
+###SUBPART###text###SUBPART###
+</body>',
+                               '###SUBPART###',
+                               'hello',
+                               FALSE,
+                               TRUE,
+                               '<body>
+###SUBPART###hello###SUBPART###
+</body>'
+                       ),
+                       'Wrap around' => array(
+                               '<body>
+###SUBPART###text###SUBPART###
+</body>',
+                               '###SUBPART###',
+                               array('before-', '-after'),
+                               FALSE,
+                               TRUE,
+                               '<body>
+###SUBPART###before-text-after###SUBPART###
+</body>'
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider substituteSubpartDataProvider
+        */
+       public function substituteSubpart($content, $marker, $subpartContent, $recursive, $keepMarker, $expected) {
+               $this->assertSame($expected, HtmlParser::substituteSubpart($content, $marker, $subpartContent, $recursive, $keepMarker));
+       }
+
+       /**
         * Data provider for substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArray
         */
        public function substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArrayDataProvider() {