]> BookStack Code Mirror - bookstack/commitdiff
Added testing to cover search result highlighting
authorDan Brown <redacted>
Sat, 13 Nov 2021 13:26:11 +0000 (13:26 +0000)
committerDan Brown <redacted>
Sat, 13 Nov 2021 13:26:11 +0000 (13:26 +0000)
tests/Entity/EntitySearchTest.php

index f69dba21154438ef5832dd8dcf8c321edeb1c00a..95d47462983dd1c1032466c6e0019d5a59301c86 100644 (file)
@@ -383,4 +383,32 @@ class EntitySearchTest extends TestCase
         $this->assertEquals(3, $scoreByTerm->get('Animal'));
         $this->assertEquals(3, $scoreByTerm->get('SuperImportant'));
     }
+
+    public function test_matching_terms_in_search_results_are_highlighted()
+    {
+        $this->newPage(['name' => 'My Meowie Cat', 'html' => '<p>A superimportant page about meowieable animals</p>', 'tags' => [
+            ['name' => 'Animal', 'value' => 'MeowieCat'],
+            ['name' => 'SuperImportant'],
+        ]]);
+
+        $search = $this->asEditor()->get('/search?term=SuperImportant+Meowie');
+        // Title
+        $search->assertSee('My <strong>Meowie</strong> Cat', false);
+        // Content
+        $search->assertSee('A <strong>superimportant</strong> page about <strong>meowie</strong>able animals', false);
+        // Tag name
+        $search->assertElementContains('.tag-name.highlight', 'SuperImportant');
+        // Tag value
+        $search->assertElementContains('.tag-value.highlight', 'MeowieCat');
+    }
+
+    public function test_html_entities_in_item_details_remains_escaped_in_search_results()
+    {
+        $this->newPage(['name' => 'My <cool> TestPageContent', 'html' => '<p>My supercool &lt;great&gt; TestPageContent page</p>']);
+
+        $search = $this->asEditor()->get('/search?term=TestPageContent');
+        $search->assertSee('My &lt;cool&gt; <strong>TestPageContent</strong>', false);
+        $search->assertSee('My supercool &lt;great&gt; <strong>TestPageContent</strong> page', false);
+    }
+
 }