3 namespace Drupal\Tests\search\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests search functionality with punctuation and HTML entities.
12 class SearchNodePunctuationTest extends BrowserTestBase {
17 protected static $modules = ['node', 'search'];
20 * A user with permission to use advanced search.
22 * @var \Drupal\user\UserInterface
26 protected function setUp() {
29 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
31 node_access_rebuild();
32 // Create a test user and log in.
33 $this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
34 $this->drupalLogin($this->testUser);
38 * Tests that search works with punctuation and HTML entities.
40 public function testPhraseSearchPunctuation() {
41 $node = $this->drupalCreateNode(['body' => [['value' => "The bunny's ears were fluffy."]]]);
42 $node2 = $this->drupalCreateNode(['body' => [['value' => 'Dignissim Aliquam & Quieligo meus natu quae quia te. Damnum© erat— neo pneum. Facilisi feugiat ibidem ratis.']]]);
44 // Update the search index.
45 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
46 search_update_totals();
48 // Refresh variables after the treatment.
49 $this->refreshVariables();
51 // Submit a phrase wrapped in double quotes to include the punctuation.
52 $edit = ['keys' => '"bunny\'s"'];
53 $this->drupalPostForm('search/node', $edit, t('Search'));
54 $this->assertText($node->label());
56 // Check if the author is linked correctly to the user profile page.
57 $username = $node->getOwner()->getUsername();
58 $this->assertLink($username);
60 // Search for "&" and verify entities are not broken up in the output.
61 $edit = ['keys' => '&'];
62 $this->drupalPostForm('search/node', $edit, t('Search'));
63 $this->assertNoRaw('<strong>&</strong>amp;');
64 $this->assertText('You must include at least one keyword');
66 $edit = ['keys' => '&'];
67 $this->drupalPostForm('search/node', $edit, t('Search'));
68 $this->assertNoRaw('<strong>&</strong>amp;');
69 $this->assertText('You must include at least one keyword');