3 namespace Drupal\Tests\node\Functional;
5 use Drupal\comment\CommentInterface;
6 use Drupal\comment\Tests\CommentTestTrait;
7 use Drupal\comment\Entity\Comment;
8 use Drupal\Tests\BrowserTestBase;
11 * Tests access controlled node views have the right amount of comment pages.
15 class NodeAccessPagerTest extends BrowserTestBase {
24 public static $modules = ['node_access_test', 'comment', 'forum'];
26 protected function setUp() {
29 node_access_rebuild();
30 $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
31 $this->addDefaultCommentField('node', 'page');
32 $this->webUser = $this->drupalCreateUser(['access content', 'access comments', 'node test view']);
36 * Tests the comment pager for nodes with multiple grants per realm.
38 public function testCommentPager() {
40 $node = $this->drupalCreateNode();
42 // Create 60 comments.
43 for ($i = 0; $i < 60; $i++) {
44 $comment = Comment::create([
45 'entity_id' => $node->id(),
46 'entity_type' => 'node',
47 'field_name' => 'comment',
48 'subject' => $this->randomMachineName(),
50 ['value' => $this->randomMachineName()],
52 'status' => CommentInterface::PUBLISHED,
57 $this->drupalLogin($this->webUser);
59 // View the node page. With the default 50 comments per page there should
60 // be two pages (0, 1) but no third (2) page.
61 $this->drupalGet('node/' . $node->id());
62 $this->assertText($node->label());
63 $this->assertText(t('Comments'));
64 $this->assertRaw('page=1');
65 $this->assertNoRaw('page=2');
69 * Tests the forum node pager for nodes with multiple grants per realm.
71 public function testForumPager() {
72 // Look up the forums vocabulary ID.
73 $vid = $this->config('forum.settings')->get('vocabulary');
74 $this->assertTrue($vid, 'Forum navigation vocabulary ID is set.');
76 // Look up the general discussion term.
77 $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vid, 0, 1);
78 $tid = reset($tree)->tid;
79 $this->assertTrue($tid, 'General discussion term is found in the forum vocabulary.');
82 for ($i = 0; $i < 30; $i++) {
83 $this->drupalCreateNode([
86 'taxonomy_forums' => [
87 ['target_id' => $tid],
92 // View the general discussion forum page. With the default 25 nodes per
93 // page there should be two pages for 30 nodes, no more.
94 $this->drupalLogin($this->webUser);
95 $this->drupalGet('forum/' . $tid);
96 $this->assertRaw('page=1');
97 $this->assertNoRaw('page=2');