b292fdc6d72e31f3cfc9298d9e14331b35f802b5
[yaffs-website] / web / core / modules / search / tests / src / Functional / SearchNodePunctuationTest.php
1 <?php
2
3 namespace Drupal\Tests\search\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests search functionality with punctuation and HTML entities.
9  *
10  * @group search
11  */
12 class SearchNodePunctuationTest extends BrowserTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected static $modules = ['node', 'search'];
18
19   /**
20    * A user with permission to use advanced search.
21    *
22    * @var \Drupal\user\UserInterface
23    */
24   public $testUser;
25
26   protected function setUp() {
27     parent::setUp();
28
29     $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
30
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);
35   }
36
37   /**
38    * Tests that search works with punctuation and HTML entities.
39    */
40   public function testPhraseSearchPunctuation() {
41     $node = $this->drupalCreateNode(['body' => [['value' => "The bunny's ears were fluffy."]]]);
42     $node2 = $this->drupalCreateNode(['body' => [['value' => 'Dignissim Aliquam &amp; Quieligo meus natu quae quia te. Damnum&copy; erat&mdash; neo pneum. Facilisi feugiat ibidem ratis.']]]);
43
44     // Update the search index.
45     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
46     search_update_totals();
47
48     // Refresh variables after the treatment.
49     $this->refreshVariables();
50
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());
55
56     // Check if the author is linked correctly to the user profile page.
57     $username = $node->getOwner()->getUsername();
58     $this->assertLink($username);
59
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');
65
66     $edit = ['keys' => '&amp;'];
67     $this->drupalPostForm('search/node', $edit, t('Search'));
68     $this->assertNoRaw('<strong>&</strong>amp;');
69     $this->assertText('You must include at least one keyword');
70   }
71
72 }