// Create some comments and attach them to the created node.
for ($i = 0;
$i <
$this->defaultDisplayResults;
$i++
) { /** @var \Drupal\comment\CommentInterface $comment */
$comment = Comment::
create([ 'status' => CommentInterface::PUBLISHED,
'field_name' => 'comment',
'entity_type' => 'node',
'entity_id' =>
$this->node->
id(),
]);
$comment->
setOwnerId(0
);
$comment->
setSubject('Test comment ' .
$i);
$comment->comment_body->value = 'Test body ' .
$i;
$comment->comment_body->format = 'full_html';
// Ensure comments are sorted in ascending order.
$time = REQUEST_TIME +
($this->defaultDisplayResults -
$i);
$comment->
setCreatedTime($time);
$comment->changed->value =
$time;
$comment->
save();
}