SearchNodePunctuationTest.php 1.33 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\search\Tests\SearchNodePunctuationTest.
6 7 8 9 10
 */

namespace Drupal\search\Tests;

/**
11 12 13
 * Tests search functionality with punctuation.
 *
 * @group search
14
 */
15
class SearchNodePunctuationTest extends SearchTestBase {
16

17 18 19 20 21 22
  /**
   * A user with permission to use advanced search.
   *
   * @var \Drupal\user\UserInterface
   */
  public $testUser;
23

24
  protected function setUp() {
25
    parent::setUp();
26 27 28
    node_access_rebuild();

    // Create a test user and log in.
29 30
    $this->testUser = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search'));
    $this->drupalLogin($this->testUser);
31 32 33 34 35 36
  }

  /**
   * Tests that search returns results with punctuation in the search phrase.
   */
  function testPhraseSearchPunctuation() {
37
    $node = $this->drupalCreateNode(array('body' => array(array('value' => "The bunny's ears were fluffy."))));
38 39

    // Update the search index.
40
    $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
41 42 43 44 45 46 47
    search_update_totals();

    // Refresh variables after the treatment.
    $this->refreshVariables();

    // Submit a phrase wrapped in double quotes to include the punctuation.
    $edit = array('keys' => '"bunny\'s"');
48
    $this->drupalPostForm('search/node', $edit, t('Search'));
49
    $this->assertText($node->label());
50 51
  }
}