annotate core/modules/node/tests/src/Functional/NodeAccessPagerTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\node\Functional;
Chris@0 4
Chris@0 5 use Drupal\comment\CommentInterface;
Chris@0 6 use Drupal\comment\Tests\CommentTestTrait;
Chris@0 7 use Drupal\comment\Entity\Comment;
Chris@0 8 use Drupal\Tests\BrowserTestBase;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Tests access controlled node views have the right amount of comment pages.
Chris@0 12 *
Chris@0 13 * @group node
Chris@0 14 */
Chris@0 15 class NodeAccessPagerTest extends BrowserTestBase {
Chris@0 16
Chris@0 17 use CommentTestTrait;
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Modules to enable.
Chris@0 21 *
Chris@0 22 * @var array
Chris@0 23 */
Chris@0 24 public static $modules = ['node_access_test', 'comment', 'forum'];
Chris@0 25
Chris@0 26 protected function setUp() {
Chris@0 27 parent::setUp();
Chris@0 28
Chris@0 29 node_access_rebuild();
Chris@0 30 $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
Chris@0 31 $this->addDefaultCommentField('node', 'page');
Chris@0 32 $this->webUser = $this->drupalCreateUser(['access content', 'access comments', 'node test view']);
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * Tests the comment pager for nodes with multiple grants per realm.
Chris@0 37 */
Chris@0 38 public function testCommentPager() {
Chris@0 39 // Create a node.
Chris@0 40 $node = $this->drupalCreateNode();
Chris@0 41
Chris@0 42 // Create 60 comments.
Chris@0 43 for ($i = 0; $i < 60; $i++) {
Chris@0 44 $comment = Comment::create([
Chris@0 45 'entity_id' => $node->id(),
Chris@0 46 'entity_type' => 'node',
Chris@0 47 'field_name' => 'comment',
Chris@0 48 'subject' => $this->randomMachineName(),
Chris@0 49 'comment_body' => [
Chris@0 50 ['value' => $this->randomMachineName()],
Chris@0 51 ],
Chris@0 52 'status' => CommentInterface::PUBLISHED,
Chris@0 53 ]);
Chris@0 54 $comment->save();
Chris@0 55 }
Chris@0 56
Chris@0 57 $this->drupalLogin($this->webUser);
Chris@0 58
Chris@0 59 // View the node page. With the default 50 comments per page there should
Chris@0 60 // be two pages (0, 1) but no third (2) page.
Chris@0 61 $this->drupalGet('node/' . $node->id());
Chris@0 62 $this->assertText($node->label());
Chris@0 63 $this->assertText(t('Comments'));
Chris@0 64 $this->assertRaw('page=1');
Chris@0 65 $this->assertNoRaw('page=2');
Chris@0 66 }
Chris@0 67
Chris@0 68 /**
Chris@0 69 * Tests the forum node pager for nodes with multiple grants per realm.
Chris@0 70 */
Chris@0 71 public function testForumPager() {
Chris@0 72 // Look up the forums vocabulary ID.
Chris@0 73 $vid = $this->config('forum.settings')->get('vocabulary');
Chris@0 74 $this->assertTrue($vid, 'Forum navigation vocabulary ID is set.');
Chris@0 75
Chris@0 76 // Look up the general discussion term.
Chris@0 77 $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vid, 0, 1);
Chris@0 78 $tid = reset($tree)->tid;
Chris@0 79 $this->assertTrue($tid, 'General discussion term is found in the forum vocabulary.');
Chris@0 80
Chris@0 81 // Create 30 nodes.
Chris@0 82 for ($i = 0; $i < 30; $i++) {
Chris@0 83 $this->drupalCreateNode([
Chris@0 84 'nid' => NULL,
Chris@0 85 'type' => 'forum',
Chris@0 86 'taxonomy_forums' => [
Chris@0 87 ['target_id' => $tid],
Chris@0 88 ],
Chris@0 89 ]);
Chris@0 90 }
Chris@0 91
Chris@0 92 // View the general discussion forum page. With the default 25 nodes per
Chris@0 93 // page there should be two pages for 30 nodes, no more.
Chris@0 94 $this->drupalLogin($this->webUser);
Chris@0 95 $this->drupalGet('forum/' . $tid);
Chris@0 96 $this->assertRaw('page=1');
Chris@0 97 $this->assertNoRaw('page=2');
Chris@0 98 }
Chris@0 99
Chris@0 100 }