comparison core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\search\Functional;
4
5 /**
6 * Tests search functionality with punctuation and HTML entities.
7 *
8 * @group search
9 */
10 class SearchNodePunctuationTest extends SearchTestBase {
11
12 /**
13 * A user with permission to use advanced search.
14 *
15 * @var \Drupal\user\UserInterface
16 */
17 public $testUser;
18
19 protected function setUp() {
20 parent::setUp();
21 node_access_rebuild();
22
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);
26 }
27
28 /**
29 * Tests that search works with punctuation and HTML entities.
30 */
31 public function testPhraseSearchPunctuation() {
32 $node = $this->drupalCreateNode(['body' => [['value' => "The bunny's ears were fluffy."]]]);
33 $node2 = $this->drupalCreateNode(['body' => [['value' => 'Dignissim Aliquam &amp; Quieligo meus natu quae quia te. Damnum&copy; erat&mdash; neo pneum. Facilisi feugiat ibidem ratis.']]]);
34
35 // Update the search index.
36 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
37 search_update_totals();
38
39 // Refresh variables after the treatment.
40 $this->refreshVariables();
41
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());
46
47 // Check if the author is linked correctly to the user profile page.
48 $username = $node->getOwner()->getUsername();
49 $this->assertLink($username);
50
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');
56
57 $edit = ['keys' => '&amp;'];
58 $this->drupalPostForm('search/node', $edit, t('Search'));
59 $this->assertNoRaw('<strong>&</strong>amp;');
60 $this->assertText('You must include at least one keyword');
61 }
62
63 }