You are here

public function SearchCommentTest::testAddNewComment in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::testAddNewComment()
  2. 10 core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::testAddNewComment()

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

File

core/modules/search/tests/src/Functional/SearchCommentTest.php, line 328

Class

SearchCommentTest
Tests integration searching comments.

Namespace

Drupal\Tests\search\Functional

Code

public function testAddNewComment() {

  // Create a node with a short body.
  $settings = [
    'type' => 'article',
    'title' => 'short title',
    'body' => [
      [
        'value' => 'short body text',
      ],
    ],
  ];
  $user = $this
    ->drupalCreateUser([
    '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', [
    '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', [
    'keys' => 'short',
  ], t('Search'));
  $this
    ->assertText($node
    ->label(), 'Search for keyword worked');
  $this
    ->assertNoText(t('Add new comment'));
}