You are here

public function CommentPagerTest::assertCommentOrder 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::assertCommentOrder()
  2. 10 core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\CommentPagerTest::assertCommentOrder()

Asserts that the comments are displayed in the correct order.

Parameters

\Drupal\comment\CommentInterface[] $comments: An array of comments, must be of the type CommentInterface.

array $expected_order: An array of keys from $comments describing the expected order.

1 call to CommentPagerTest::assertCommentOrder()
CommentPagerTest::testCommentOrderingThreading in core/modules/comment/tests/src/Functional/CommentPagerTest.php
Tests comment ordering and threading.

File

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

Class

CommentPagerTest
Tests paging of comments and their settings.

Namespace

Drupal\Tests\comment\Functional

Code

public function assertCommentOrder(array $comments, array $expected_order) {
  $expected_cids = [];

  // First, rekey the expected order by cid.
  foreach ($expected_order as $key) {
    $expected_cids[] = $comments[$key]
      ->id();
  }
  $comment_anchors = $this
    ->xpath('//article[starts-with(@id,"comment-")]');
  $result_order = [];
  foreach ($comment_anchors as $anchor) {
    $result_order[] = substr($anchor
      ->getAttribute('id'), 8);
  }
  $this
    ->assertEquals($expected_cids, $result_order, new FormattableMarkup('Comment order: expected @expected, returned @returned.', [
    '@expected' => implode(',', $expected_cids),
    '@returned' => implode(',', $result_order),
  ]));
}