1 search.test SearchCommentTestCase::testAddNewComment()

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

File

core/modules/search/tests/search.test, line 907
Tests for search.module.

Class

SearchCommentTestCase
Test integration searching comments.

Code

function testAddNewComment() {
  // Create a node with a short body.
  $settings = array(
    'type' => 'post',
    'title' => 'short title',
    'body' => array(LANGUAGE_NONE => array(array('value' => 'short body text'))),
  );

  $user = $this->backdropCreateUser(array('search content', 'create post content', 'access content'));
  $this->backdropLogin($user);

  $node = $this->backdropCreateNode($settings);
  // Verify that if you view the node on its own page, 'Add comment' is
  // there.
  $this->backdropGet('node/' . $node->nid);
  $this->assertText(t('Add comment'), '"Add comment" appears on node page');

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

  // Search for 'comment'. Should be no results.
  $this->backdropLogin($user);
  $this->backdropPost('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 comment' should not
  // be part of the search snippet.
  $this->backdropPost('search/node', array('keys' => 'short'), t('Search'));
  $this->assertText($node->title, 'Search for keyword worked');
  $this->assertNoText(t('Add comment'), '"Add comment" does not appear on search results page');
}