Chris@0: drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]); Chris@0: $this->addDefaultCommentField('node', 'page'); Chris@0: $this->webUser = $this->drupalCreateUser(['access content', 'access comments', 'node test view']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the comment pager for nodes with multiple grants per realm. Chris@0: */ Chris@0: public function testCommentPager() { Chris@0: // Create a node. Chris@0: $node = $this->drupalCreateNode(); Chris@0: Chris@0: // Create 60 comments. Chris@0: for ($i = 0; $i < 60; $i++) { Chris@0: $comment = Comment::create([ Chris@0: 'entity_id' => $node->id(), Chris@0: 'entity_type' => 'node', Chris@0: 'field_name' => 'comment', Chris@0: 'subject' => $this->randomMachineName(), Chris@0: 'comment_body' => [ Chris@0: ['value' => $this->randomMachineName()], Chris@0: ], Chris@0: 'status' => CommentInterface::PUBLISHED, Chris@0: ]); Chris@0: $comment->save(); Chris@0: } Chris@0: Chris@0: $this->drupalLogin($this->webUser); Chris@0: Chris@0: // View the node page. With the default 50 comments per page there should Chris@0: // be two pages (0, 1) but no third (2) page. Chris@0: $this->drupalGet('node/' . $node->id()); Chris@0: $this->assertText($node->label()); Chris@0: $this->assertText(t('Comments')); Chris@0: $this->assertRaw('page=1'); Chris@0: $this->assertNoRaw('page=2'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the forum node pager for nodes with multiple grants per realm. Chris@0: */ Chris@0: public function testForumPager() { Chris@0: // Look up the forums vocabulary ID. Chris@0: $vid = $this->config('forum.settings')->get('vocabulary'); Chris@0: $this->assertTrue($vid, 'Forum navigation vocabulary ID is set.'); Chris@0: Chris@0: // Look up the general discussion term. Chris@0: $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vid, 0, 1); Chris@0: $tid = reset($tree)->tid; Chris@0: $this->assertTrue($tid, 'General discussion term is found in the forum vocabulary.'); Chris@0: Chris@0: // Create 30 nodes. Chris@0: for ($i = 0; $i < 30; $i++) { Chris@0: $this->drupalCreateNode([ Chris@0: 'nid' => NULL, Chris@0: 'type' => 'forum', Chris@0: 'taxonomy_forums' => [ Chris@0: ['target_id' => $tid], Chris@0: ], Chris@0: ]); Chris@0: } Chris@0: Chris@0: // View the general discussion forum page. With the default 25 nodes per Chris@0: // page there should be two pages for 30 nodes, no more. Chris@0: $this->drupalLogin($this->webUser); Chris@0: $this->drupalGet('forum/' . $tid); Chris@0: $this->assertRaw('page=1'); Chris@0: $this->assertNoRaw('page=2'); Chris@0: } Chris@0: Chris@0: }