[TASK] Add unit tests for TYPO3SEARCH markers 89/47189/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:07:22 +0000 (10:07 +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/47189
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 4658a20..517e570 100644 (file)
@@ -40,3 +40,5 @@ Rules:
    until that point is excluded and preceding 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 38fc781..844b6e2 100644 (file)
@@ -120,4 +120,102 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $result = $this->subject->extractBaseHref($html);
         $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->subject->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->subject->typoSearchTags($body);
+        $this->assertTrue($result);
+        $this->assertEquals($expected, $body);
+    }
 }