function CommentPagerTest::assertCommentOrder
Same name in other branches
- 7.x modules/comment/comment.test \CommentPagerTest::assertCommentOrder()
- 9 core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\CommentPagerTest::assertCommentOrder()
- 8.9.x core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\CommentPagerTest::assertCommentOrder()
- 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.
@internal
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 230
Class
- CommentPagerTest
- Tests paging of comments and their settings.
Namespace
Drupal\Tests\comment\FunctionalCode
public function assertCommentOrder(array $comments, array $expected_order) : void {
$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, sprintf('Comment order: expected %s, returned %s.', implode(',', $expected_cids), implode(',', $result_order)));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.