You are here

function CommentPagerTest::assertCommentOrder in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentPagerTest.php \Drupal\comment\Tests\CommentPagerTest::assertCommentOrder()

Asserts that the comments are displayed in the correct order.

Parameters

$comments: And array of comments.

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

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

File

core/modules/comment/src/Tests/CommentPagerTest.php, line 181
Contains \Drupal\comment\Tests\CommentPagerTest.

Class

CommentPagerTest
Tests paging of comments and their settings.

Namespace

Drupal\comment\Tests

Code

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

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