SearchNodePunctuationTest.php 1.4 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
 * Tests node search with punctuation.
12
 */
13
class SearchNodePunctuationTest extends SearchTestBase {
14

15 16 17 18
  public $test_user;

  public static function getInfo() {
    return array(
19 20
      'name' => 'Search with punctuation',
      'description' => 'Tests search functionality with punctuation.',
21 22 23 24 25
      'group' => 'Search',
    );
  }

  function setUp() {
26
    parent::setUp();
27 28 29 30 31 32 33 34 35 36 37
    node_access_rebuild();

    // Create a test user and log in.
    $this->test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search'));
    $this->drupalLogin($this->test_user);
  }

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

    // Update the search index.
41
    $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
42 43 44 45 46 47 48
    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"');
49
    $this->drupalPostForm('search/node', $edit, t('Search'));
50
    $this->assertText($node->label());
51 52
  }
}