annotate 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
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\search\Functional;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Tests search functionality with punctuation and HTML entities.
Chris@0 7 *
Chris@0 8 * @group search
Chris@0 9 */
Chris@0 10 class SearchNodePunctuationTest extends SearchTestBase {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * A user with permission to use advanced search.
Chris@0 14 *
Chris@0 15 * @var \Drupal\user\UserInterface
Chris@0 16 */
Chris@0 17 public $testUser;
Chris@0 18
Chris@0 19 protected function setUp() {
Chris@0 20 parent::setUp();
Chris@0 21 node_access_rebuild();
Chris@0 22
Chris@0 23 // Create a test user and log in.
Chris@0 24 $this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
Chris@0 25 $this->drupalLogin($this->testUser);
Chris@0 26 }
Chris@0 27
Chris@0 28 /**
Chris@0 29 * Tests that search works with punctuation and HTML entities.
Chris@0 30 */
Chris@0 31 public function testPhraseSearchPunctuation() {
Chris@0 32 $node = $this->drupalCreateNode(['body' => [['value' => "The bunny's ears were fluffy."]]]);
Chris@0 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.']]]);
Chris@0 34
Chris@0 35 // Update the search index.
Chris@0 36 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
Chris@0 37 search_update_totals();
Chris@0 38
Chris@0 39 // Refresh variables after the treatment.
Chris@0 40 $this->refreshVariables();
Chris@0 41
Chris@0 42 // Submit a phrase wrapped in double quotes to include the punctuation.
Chris@0 43 $edit = ['keys' => '"bunny\'s"'];
Chris@0 44 $this->drupalPostForm('search/node', $edit, t('Search'));
Chris@0 45 $this->assertText($node->label());
Chris@0 46
Chris@0 47 // Check if the author is linked correctly to the user profile page.
Chris@0 48 $username = $node->getOwner()->getUsername();
Chris@0 49 $this->assertLink($username);
Chris@0 50
Chris@0 51 // Search for "&" and verify entities are not broken up in the output.
Chris@0 52 $edit = ['keys' => '&'];
Chris@0 53 $this->drupalPostForm('search/node', $edit, t('Search'));
Chris@0 54 $this->assertNoRaw('<strong>&</strong>amp;');
Chris@0 55 $this->assertText('You must include at least one keyword');
Chris@0 56
Chris@0 57 $edit = ['keys' => '&amp;'];
Chris@0 58 $this->drupalPostForm('search/node', $edit, t('Search'));
Chris@0 59 $this->assertNoRaw('<strong>&</strong>amp;');
Chris@0 60 $this->assertText('You must include at least one keyword');
Chris@0 61 }
Chris@0 62
Chris@0 63 }