3 namespace Drupal\Tests\search\Functional;
6 * Tests search functionality with punctuation and HTML entities.
10 class SearchNodePunctuationTest extends SearchTestBase {
13 * A user with permission to use advanced search.
15 * @var \Drupal\user\UserInterface
19 protected function setUp() {
21 node_access_rebuild();
23 // Create a test user and log in.
24 $this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
25 $this->drupalLogin($this->testUser);
29 * Tests that search works with punctuation and HTML entities.
31 public function testPhraseSearchPunctuation() {
32 $node = $this->drupalCreateNode(['body' => [['value' => "The bunny's ears were fluffy."]]]);
33 $node2 = $this->drupalCreateNode(['body' => [['value' => 'Dignissim Aliquam & Quieligo meus natu quae quia te. Damnum© erat— neo pneum. Facilisi feugiat ibidem ratis.']]]);
35 // Update the search index.
36 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
37 search_update_totals();
39 // Refresh variables after the treatment.
40 $this->refreshVariables();
42 // Submit a phrase wrapped in double quotes to include the punctuation.
43 $edit = ['keys' => '"bunny\'s"'];
44 $this->drupalPostForm('search/node', $edit, t('Search'));
45 $this->assertText($node->label());
47 // Check if the author is linked correctly to the user profile page.
48 $username = $node->getOwner()->getUsername();
49 $this->assertLink($username);
51 // Search for "&" and verify entities are not broken up in the output.
52 $edit = ['keys' => '&'];
53 $this->drupalPostForm('search/node', $edit, t('Search'));
54 $this->assertNoRaw('<strong>&</strong>amp;');
55 $this->assertText('You must include at least one keyword');
57 $edit = ['keys' => '&'];
58 $this->drupalPostForm('search/node', $edit, t('Search'));
59 $this->assertNoRaw('<strong>&</strong>amp;');
60 $this->assertText('You must include at least one keyword');