function SearchCommentTest::testAddNewComment

Verify that 'add new comment' does not appear in search results or index.

File

drupal/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php, line 219
Definition of Drupal\search\Tests\SearchCommentTest.

Class

SearchCommentTest
Test integration searching comments.

Namespace

Drupal\search\Tests

Code

function testAddNewComment() {

  // Create a node with a short body.
  $settings = array(
    'type' => 'article',
    'title' => 'short title',
    'body' => array(
      LANGUAGE_NOT_SPECIFIED => array(
        array(
          'value' => 'short body text',
        ),
      ),
    ),
  );
  $user = $this
    ->drupalCreateUser(array(
    'search content',
    'create article content',
    'access content',
  ));
  $this
    ->drupalLogin($user);
  $node = $this
    ->drupalCreateNode($settings);

  // Verify that if you view the node on its own page, 'add new comment'
  // is there.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('Add new comment'), 'Add new comment appears on node page');

  // Run cron to index this page.
  $this
    ->drupalLogout();
  $this
    ->cronRun();

  // Search for 'comment'. Should be no results.
  $this
    ->drupalLogin($user);
  $this
    ->drupalPost('search/node', array(
    'keys' => 'comment',
  ), t('Search'));
  $this
    ->assertText(t('Your search yielded no results'), 'No results searching for the word comment');

  // Search for the node title. Should be found, and 'Add new comment' should
  // not be part of the search snippet.
  $this
    ->drupalPost('search/node', array(
    'keys' => 'short',
  ), t('Search'));
  $this
    ->assertText($node
    ->label(), 'Search for keyword worked');
  $this
    ->assertNoText(t('Add new comment'), 'Add new comment does not appear on search results page');
}