[TASK] Add unit tests for TYPO3SEARCH markers 91/47191/2
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Thu, 10 Mar 2016 13:44:22 +0000 (14:44 +0100)
committerAndreas Fernandez <typo3@scripting-base.de>
Fri, 11 Mar 2016 09:16:07 +0000 (10:16 +0100)
Add two unit tests for Indexer, covering content extraction
from between TYPO3SEARCH_begin and TYPO3SEARCH_end markers.

Add note to documentation that it's possible to have multiple
TYPO3SEARCH marker pairs.

Resolves: #74815
Releases: master, 7.6, 6.2
Change-Id: I37c67dfc055dc30698831eef6d0231d929fef957
Reviewed-on: https://review.typo3.org/47191
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/indexed_search/Documentation/TechnicalDetails/HtmlContent/Index.rst
typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php

index 9a63984..85eb32d 100644 (file)
@@ -40,3 +40,5 @@ Rules:
    until that point is excluded and preceeding content until next "end"
    marker is included.
 
+#. If there are multiple marker pairs in HTML, content from in between
+   all pairs is included.
\ No newline at end of file
index 796d13c..c46685d 100644 (file)
@@ -132,4 +132,99 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals($baseHref, $result);
        }
 
+       /**
+        * Tests whether indexer can extract content between "TYPO3SEARCH_begin" and "TYPO3SEARCH_end" markers
+        *
+        * @test
+        */
+       public function typoSearchTagsRemovesBodyContentOutsideMarkers() {
+               $body = <<<EOT
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<title>Some Title</title>
+<link href='css/normalize.css' rel='stylesheet' type='text/css'/>
+</head>
+<body>
+<div>
+<div class="non_searchable">
+    not searchable content
+</div>
+<!--TYPO3SEARCH_begin-->
+<div class="searchable">
+    lorem ipsum
+</div>
+<!--TYPO3SEARCH_end-->
+<div class="non_searchable">
+    not searchable content
+</div>
+</body>
+</html>
+EOT;
+               $expected = <<<EOT
+
+<div class="searchable">
+    lorem ipsum
+</div>
+
+EOT;
+
+               $result = $this->fixture->typoSearchTags($body);
+               $this->assertTrue($result);
+               $this->assertEquals($expected, $body);
+       }
+
+       /**
+        * Tests whether indexer can extract content between multiple pairs of "TYPO3SEARCH" markers
+        *
+        * @test
+        */
+       public function typoSearchTagsHandlesMultipleMarkerPairs() {
+               $body = <<<EOT
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<title>Some Title</title>
+<link href='css/normalize.css' rel='stylesheet' type='text/css'/>
+</head>
+<body>
+<div>
+<div class="non_searchable">
+    not searchable content
+</div>
+<!--TYPO3SEARCH_begin-->
+<div class="searchable">
+    lorem ipsum
+</div>
+<!--TYPO3SEARCH_end-->
+<div class="non_searchable">
+    not searchable content
+</div>
+<!--TYPO3SEARCH_begin-->
+<div class="searchable">
+    lorem ipsum2
+</div>
+<!--TYPO3SEARCH_end-->
+<div class="non_searchable">
+    not searchable content
+</div>
+</body>
+</html>
+EOT;
+               $expected = <<<EOT
+
+<div class="searchable">
+    lorem ipsum
+</div>
+
+<div class="searchable">
+    lorem ipsum2
+</div>
+
+EOT;
+
+               $result = $this->fixture->typoSearchTags($body);
+               $this->assertTrue($result);
+               $this->assertEquals($expected, $body);
+       }
 }