function DefaultViewRecentCommentsTest::testBlockDisplay

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

Class

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

Namespace

Drupal\Tests\comment\Functional\Views

Code

public function testBlockDisplay() : void {
    $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, 'There are exactly ' . count($view->result) . ' comments. Expected ' . $this->blockDisplayResults);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.