You are here

public function DefaultViewRecentCommentsTest::testBlockDisplay in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php \Drupal\comment\Tests\Views\DefaultViewRecentCommentsTest::testBlockDisplay()

Tests the block defined by the comments_recent view.

File

core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php, line 116
Contains \Drupal\comment\Tests\Views\DefaultViewRecentCommentsTest.

Class

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

Namespace

Drupal\comment\Tests\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 = array(
    'subject' => 'subject',
    'cid' => 'cid',
    'comment_field_data_created' => 'created',
  );
  $expected_result = array();
  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(sizeof($view->result), $this->blockDisplayResults, format_string('There are exactly @results comments. Expected @expected', array(
    '@results' => count($view->result),
    '@expected' => $this->blockDisplayResults,
  )));
}