function DefaultViewRecentCommentsTest::testBlockDisplay
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php \Drupal\Tests\comment\Functional\Views\DefaultViewRecentCommentsTest::testBlockDisplay()
- 10 core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php \Drupal\Tests\comment\Functional\Views\DefaultViewRecentCommentsTest::testBlockDisplay()
- 11.x core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php \Drupal\Tests\comment\Functional\Views\DefaultViewRecentCommentsTest::testBlockDisplay()
Tests the block defined by the comments_recent view.
File
-
core/
modules/ comment/ tests/ src/ Functional/ Views/ DefaultViewRecentCommentsTest.php, line 117
Class
- DefaultViewRecentCommentsTest
- Tests results for the Recent Comments view shipped with the module.
Namespace
Drupal\Tests\comment\Functional\ViewsCode
public function testBlockDisplay() {
$user = $this->drupalCreateUser([
'access comments',
]);
$this->drupalLogin($user);
$view = Views::getView('comments_recent');
$view->setDisplay('block_1');
$this->executeView($view);
$map = [
'subject' => 'subject',
'cid' => 'cid',
'comment_field_data_created' => 'created',
];
$expected_result = [];
foreach (array_values($this->commentsCreated) as $key => $comment) {
$expected_result[$key]['subject'] = $comment->getSubject();
$expected_result[$key]['cid'] = $comment->id();
$expected_result[$key]['created'] = $comment->getCreatedTime();
}
$this->assertIdenticalResultset($view, $expected_result, $map);
// Check the number of results given by the display is the expected.
$this->assertEqual(count($view->result), $this->blockDisplayResults, new FormattableMarkup('There are exactly @results comments. Expected @expected', [
'@results' => count($view->result),
'@expected' => $this->blockDisplayResults,
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.