function DefaultViewRecentCommentsTest::testBlockDisplay

Same name in other branches
  1. 8.9.x core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php \Drupal\Tests\comment\Functional\Views\DefaultViewRecentCommentsTest::testBlockDisplay()
  2. 10 core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php \Drupal\Tests\comment\Functional\Views\DefaultViewRecentCommentsTest::testBlockDisplay()
  3. 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 120

Class

DefaultViewRecentCommentsTest
Tests results for the Recent Comments view shipped with the module.

Namespace

Drupal\Tests\comment\Functional\Views

Code

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->assertCount($this->blockDisplayResults, $view->result, 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.