You are here

public function CommentPagerTest::testCommentPermalink in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\CommentPagerTest::testCommentPermalink()

Confirms comment paging works correctly with flat and threaded comments.

File

core/modules/comment/tests/src/Functional/CommentPagerTest.php, line 102

Class

CommentPagerTest
Tests paging of comments and their settings.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCommentPermalink() {
  $this
    ->drupalLogin($this->adminUser);

  // Set comment variables.
  $this
    ->setCommentForm(TRUE);
  $this
    ->setCommentSubject(TRUE);
  $this
    ->setCommentPreview(DRUPAL_DISABLED);

  // Create a node and three comments.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'promote' => 1,
  ]);
  $comments = [];
  $comments[] = $this
    ->postComment($node, 'comment 1: ' . $this
    ->randomMachineName(), $this
    ->randomMachineName(), TRUE);
  $comments[] = $this
    ->postComment($node, 'comment 2: ' . $this
    ->randomMachineName(), $this
    ->randomMachineName(), TRUE);
  $comments[] = $this
    ->postComment($node, 'comment 3: ' . $this
    ->randomMachineName(), $this
    ->randomMachineName(), TRUE);
  $this
    ->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');

  // Set comments to one per page so that we are able to test paging without
  // needing to insert large numbers of comments.
  $this
    ->setCommentsPerPage(1);

  // Navigate to each comment permalink as anonymous and assert it appears on
  // the page.
  foreach ($comments as $index => $comment) {
    $this
      ->drupalGet($comment
      ->toUrl());
    $this
      ->assertTrue($this
      ->commentExists($comment), sprintf('Comment %d appears on page %d.', $index + 1, $index + 1));
  }
}