function NodeAccessPagerTest::testCommentPager

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeAccessPagerTest.php \Drupal\Tests\node\Functional\NodeAccessPagerTest::testCommentPager()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeAccessPagerTest.php \Drupal\Tests\node\Functional\NodeAccessPagerTest::testCommentPager()
  3. 10 core/modules/node/tests/src/Functional/NodeAccessPagerTest.php \Drupal\Tests\node\Functional\NodeAccessPagerTest::testCommentPager()

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

File

core/modules/node/tests/src/Functional/NodeAccessPagerTest.php, line 60

Class

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

Namespace

Drupal\Tests\node\Functional

Code

public function testCommentPager() : void {
    // Create a node.
    $node = $this->drupalCreateNode();
    // Create 60 comments.
    for ($i = 0; $i < 60; $i++) {
        $comment = Comment::create([
            'entity_id' => $node->id(),
            'entity_type' => 'node',
            'field_name' => 'comment',
            'subject' => $this->randomMachineName(),
            'comment_body' => [
                [
                    '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->assertSession()
        ->pageTextContains($node->label());
    $this->assertSession()
        ->pageTextContains('Comments');
    $this->assertSession()
        ->responseContains('page=1');
    $this->assertSession()
        ->responseNotContains('page=2');
}

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