You are here

function SearchCommentTest::testAddNewComment in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/search/src/Tests/SearchCommentTest.php \Drupal\search\Tests\SearchCommentTest::testAddNewComment()

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

File

core/modules/search/src/Tests/SearchCommentTest.php, line 319
Contains \Drupal\search\Tests\SearchCommentTest.

Class

SearchCommentTest
Tests 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(
      array(
        'value' => 'short body text',
      ),
    ),
  );
  $user = $this
    ->drupalCreateUser(array(
    'search content',
    'create article content',
    'access content',
    'post comments',
    'access comments',
  ));
  $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
    ->id());
  $this
    ->assertText(t('Add new comment'));

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

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

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