You are here

public function NodeAccessPagerTest::testCommentPager in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/node/src/Tests/NodeAccessPagerTest.php \Drupal\node\Tests\NodeAccessPagerTest::testCommentPager()

Tests the comment pager for nodes with multiple grants per realm.

File

core/modules/node/src/Tests/NodeAccessPagerTest.php, line 42
Contains \Drupal\node\Tests\NodeAccessPagerTest.

Class

NodeAccessPagerTest
Tests access controlled node views have the right amount of comment pages.

Namespace

Drupal\node\Tests

Code

public function testCommentPager() {

  // Create a node.
  $node = $this
    ->drupalCreateNode();

  // Create 60 comments.
  for ($i = 0; $i < 60; $i++) {
    $comment = entity_create('comment', array(
      'entity_id' => $node
        ->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'subject' => $this
        ->randomMachineName(),
      'comment_body' => array(
        array(
          'value' => $this
            ->randomMachineName(),
        ),
      ),
      'status' => CommentInterface::PUBLISHED,
    ));
    $comment
      ->save();
  }
  $this
    ->drupalLogin($this->webUser);

  // View the node page. With the default 50 comments per page there should
  // be two pages (0, 1) but no third (2) page.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertText($node
    ->label());
  $this
    ->assertText(t('Comments'));
  $this
    ->assertRaw('page=1');
  $this
    ->assertNoRaw('page=2');
}