+
+ public function test_tag_names_and_values_are_indexed_for_search()
+ {
+ $page = $this->entities->newPage(['name' => 'PageA', 'html' => '<p>content</p>', 'tags' => [
+ ['name' => 'Animal', 'value' => 'MeowieCat'],
+ ['name' => 'SuperImportant'],
+ ]]);
+
+ $scoreByTerm = $page->searchTerms()->pluck('score', 'term');
+ $this->assertEquals(5, $scoreByTerm->get('MeowieCat'));
+ $this->assertEquals(3, $scoreByTerm->get('Animal'));
+ $this->assertEquals(3, $scoreByTerm->get('SuperImportant'));
+ }
+
+ public function test_matching_terms_in_search_results_are_highlighted()
+ {
+ $this->entities->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
+ $this->withHtml($search)->assertElementContains('.tag-name.highlight', 'SuperImportant');
+ // Tag value
+ $this->withHtml($search)->assertElementContains('.tag-value.highlight', 'MeowieCat');
+ }
+
+ public function test_match_highlighting_works_with_multibyte_content()
+ {
+ $this->entities->newPage([
+ 'name' => 'Test Page',
+ 'html' => '<p>На мен ми трябва нещо добро test</p>',
+ ]);
+
+ $search = $this->asEditor()->get('/search?term=' . urlencode('На мен ми трябва нещо добро'));
+ $search->assertSee('<strong>На</strong> <strong>мен</strong> <strong>ми</strong> <strong>трябва</strong> <strong>нещо</strong> <strong>добро</strong> test', false);
+ }
+
+ public function test_html_entities_in_item_details_remains_escaped_in_search_results()
+ {
+ $this->entities->newPage(['name' => 'My <cool> TestPageContent', 'html' => '<p>My supercool <great> TestPageContent page</p>']);
+
+ $search = $this->asEditor()->get('/search?term=TestPageContent');
+ $search->assertSee('My <cool> <strong>TestPageContent</strong>', false);
+ $search->assertSee('My supercool <great> <strong>TestPageContent</strong> page', false);
+ }
+
+ public function test_words_adjacent_to_lines_breaks_can_be_matched_with_normal_terms()
+ {
+ $page = $this->entities->newPage(['name' => 'TermA', 'html' => '
+ <p>TermA<br>TermB<br>TermC</p>
+ ']);
+
+ $search = $this->asEditor()->get('/search?term=' . urlencode('TermB TermC'));
+
+ $search->assertSee($page->getUrl(), false);
+ }
+
+ public function test_searches_with_user_filters_adds_them_into_advanced_search_form()
+ {
+ $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan}'));
+ $this->withHtml($resp)->assertElementExists('form input[name="filters[updated_by]"][value="dan"]');
+ $this->withHtml($resp)->assertElementExists('form input[name="filters[created_by]"][value="dan"]');
+ }
+
+ public function test_searches_with_user_filters_using_me_adds_them_into_advanced_search_form()
+ {
+ $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:me} {created_by:me}'));
+ $this->withHtml($resp)->assertElementExists('form input[name="filters[updated_by]"][value="me"][checked="checked"]');
+ $this->withHtml($resp)->assertElementExists('form input[name="filters[created_by]"][value="me"][checked="checked"]');
+ }
+
+ public function test_search_suggestion_endpoint()
+ {
+ $this->entities->newPage(['name' => 'My suggestion page', 'html' => '<p>My supercool suggestion page</p>']);
+
+ // Test specific search
+ $resp = $this->asEditor()->get('/search/suggest?term="supercool+suggestion"');
+ $resp->assertSee('My suggestion page');
+ $resp->assertDontSee('My supercool suggestion page');
+ $resp->assertDontSee('No items available');
+ $this->withHtml($resp)->assertElementCount('a', 1);
+
+ // Test search limit
+ $resp = $this->asEditor()->get('/search/suggest?term=et');
+ $this->withHtml($resp)->assertElementCount('a', 5);
+
+ // Test empty state
+ $resp = $this->asEditor()->get('/search/suggest?term=spaghettisaurusrex');
+ $this->withHtml($resp)->assertElementCount('a', 0);
+ $resp->assertSee('No items available');
+ }