From 63d8d72d7ecdba31903bee4c2295f2d0a2149e0d Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 13 Nov 2021 13:26:11 +0000 Subject: [PATCH] Added testing to cover search result highlighting --- tests/Entity/EntitySearchTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Entity/EntitySearchTest.php b/tests/Entity/EntitySearchTest.php index f69dba211..95d474629 100644 --- a/tests/Entity/EntitySearchTest.php +++ b/tests/Entity/EntitySearchTest.php @@ -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' => '

A superimportant page about meowieable animals

', 'tags' => [ + ['name' => 'Animal', 'value' => 'MeowieCat'], + ['name' => 'SuperImportant'], + ]]); + + $search = $this->asEditor()->get('/search?term=SuperImportant+Meowie'); + // Title + $search->assertSee('My Meowie Cat', false); + // Content + $search->assertSee('A superimportant page about meowieable 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 TestPageContent', 'html' => '

My supercool <great> TestPageContent page

']); + + $search = $this->asEditor()->get('/search?term=TestPageContent'); + $search->assertSee('My <cool> TestPageContent', false); + $search->assertSee('My supercool <great> TestPageContent page', false); + } + }