[TASK] Add unit tests for HtmlParser::getSubpart() 67/42667/5
authorMichael Oehlhof <typo3@oehlhof.de>
Sun, 16 Aug 2015 23:15:59 +0000 (01:15 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 18 Aug 2015 22:00:49 +0000 (00:00 +0200)
Resolves: #69116
Releases: master
Change-Id: I07d4d04d2108976287617b458c0f9857099c2ada
Reviewed-on: http://review.typo3.org/42667
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
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 6417135..f0ea5ae 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\Html;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Html\HtmlParser;
+
 /**
  * Testcase for \TYPO3\CMS\Core\Html\HtmlParser
  */
@@ -25,7 +27,82 @@ class HtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $subject = NULL;
 
        protected function setUp() {
-               $this->subject = new \TYPO3\CMS\Core\Html\HtmlParser();
+               $this->subject = new HtmlParser();
+       }
+
+       /**
+        * Data provider for getSubpart
+        *
+        * @return array
+        */
+       public function getSubpartDataProvider() {
+               return array(
+                       'No start marker' => array(
+                               '<body>text</body>',
+                               '###SUBPART###',
+                               ''
+                       ),
+                       'No stop marker' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->
+text
+</body>',
+                               '###SUBPART###',
+                               ''
+                       ),
+                       'Start and stop marker in HTML comment' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->
+text
+<!-- ###SUBPART### End -->
+</body>',
+                               '###SUBPART###',
+                               '
+text
+'
+                       ),
+                       'Stop marker in HTML comment' => array(
+                               '<body>
+###SUBPART###
+text
+<!-- ###SUBPART### End -->
+</body>',
+                               '###SUBPART###',
+                               '
+text
+'
+                       ),
+                       'Start marker in HTML comment' => array(
+                               '<body>
+<!-- ###SUBPART### Start -->
+text
+###SUBPART###
+</body>',
+                               '###SUBPART###',
+                               '
+text
+'
+                       ),
+                       'Start and stop marker direct' => array(
+                               '<body>
+###SUBPART###
+text
+###SUBPART###
+</body>',
+                               '###SUBPART###',
+                               '
+text
+'
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider getSubpartDataProvider
+        */
+       public function getSubpart($content, $marker, $expected) {
+               $this->assertSame($expected, HtmlParser::getSubpart($content, $marker));
        }
 
        /**
@@ -227,7 +304,7 @@ Value 2.2
         * @dataProvider substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArrayDataProvider
         */
        public function substituteMarkerAndSubpartArrayRecursiveResolvesMarkersAndSubpartsArray($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused, $expected) {
-               $this->assertSame($expected, $this->subject->substituteMarkerAndSubpartArrayRecursive($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused));
+               $this->assertSame($expected, HtmlParser::substituteMarkerAndSubpartArrayRecursive($template, $markersAndSubparts, $wrap, $uppercase, $deleteUnused));
        }
 
        /**