comparison core/modules/node/tests/src/Functional/NodeAccessPagerTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\comment\CommentInterface;
6 use Drupal\comment\Tests\CommentTestTrait;
7 use Drupal\comment\Entity\Comment;
8 use Drupal\Tests\BrowserTestBase;
9
10 /**
11 * Tests access controlled node views have the right amount of comment pages.
12 *
13 * @group node
14 */
15 class NodeAccessPagerTest extends BrowserTestBase {
16
17 use CommentTestTrait;
18
19 /**
20 * Modules to enable.
21 *
22 * @var array
23 */
24 public static $modules = ['node_access_test', 'comment', 'forum'];
25
26 protected function setUp() {
27 parent::setUp();
28
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']);
33 }
34
35 /**
36 * Tests the comment pager for nodes with multiple grants per realm.
37 */
38 public function testCommentPager() {
39 // Create a node.
40 $node = $this->drupalCreateNode();
41
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(),
49 'comment_body' => [
50 ['value' => $this->randomMachineName()],
51 ],
52 'status' => CommentInterface::PUBLISHED,
53 ]);
54 $comment->save();
55 }
56
57 $this->drupalLogin($this->webUser);
58
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');
66 }
67
68 /**
69 * Tests the forum node pager for nodes with multiple grants per realm.
70 */
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.');
75
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.');
80
81 // Create 30 nodes.
82 for ($i = 0; $i < 30; $i++) {
83 $this->drupalCreateNode([
84 'nid' => NULL,
85 'type' => 'forum',
86 'taxonomy_forums' => [
87 ['target_id' => $tid],
88 ],
89 ]);
90 }
91
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');
98 }
99
100 }