You are here

public function SearchCommentCountToggleTest::testSearchCommentCountToggle in Drupal 8

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

Verify that comment count display toggles properly on comment status of node

File

core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php, line 89

Class

SearchCommentCountToggleTest
Tests that comment count display toggles properly on comment status of node.

Namespace

Drupal\Tests\search\Functional

Code

public function testSearchCommentCountToggle() {

  // Search for the nodes by string in the node body.
  $edit = [
    'keys' => "'SearchCommentToggleTestCase'",
  ];
  $this
    ->drupalGet('search/node');

  // Test comment count display for nodes with comment status set to Open
  $this
    ->drupalPostForm(NULL, $edit, t('Search'));
  $this
    ->assertText(t('0 comments'), 'Empty comment count displays for nodes with comment status set to Open');
  $this
    ->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open');

  // Test comment count display for nodes with comment status set to Closed
  $this->searchableNodes['0 comments']
    ->set('comment', CommentItemInterface::CLOSED);
  $this->searchableNodes['0 comments']
    ->save();
  $this->searchableNodes['1 comment']
    ->set('comment', CommentItemInterface::CLOSED);
  $this->searchableNodes['1 comment']
    ->save();
  $this
    ->drupalPostForm(NULL, $edit, t('Search'));
  $this
    ->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Closed');
  $this
    ->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed');

  // Test comment count display for nodes with comment status set to Hidden
  $this->searchableNodes['0 comments']
    ->set('comment', CommentItemInterface::HIDDEN);
  $this->searchableNodes['0 comments']
    ->save();
  $this->searchableNodes['1 comment']
    ->set('comment', CommentItemInterface::HIDDEN);
  $this->searchableNodes['1 comment']
    ->save();
  $this
    ->drupalPostForm(NULL, $edit, t('Search'));
  $this
    ->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Hidden');
  $this
    ->assertNoText(t('1 comment'), 'Non-empty comment count does not display for nodes with comment status set to Hidden');
}