comparison core/modules/comment/tests/src/Functional/CommentNodeAccessTest.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\comment\Functional;
4
5 use Drupal\comment\CommentManagerInterface;
6
7 /**
8 * Tests comments with node access.
9 *
10 * Verifies there is no PostgreSQL error when viewing a node with threaded
11 * comments (a comment and a reply), if a node access module is in use.
12 *
13 * @group comment
14 */
15 class CommentNodeAccessTest extends CommentTestBase {
16
17 /**
18 * Modules to install.
19 *
20 * @var array
21 */
22 public static $modules = ['node_access_test'];
23
24 protected function setUp() {
25 parent::setUp();
26
27 node_access_rebuild();
28
29 // Re-create user.
30 $this->webUser = $this->drupalCreateUser([
31 'access comments',
32 'post comments',
33 'create article content',
34 'edit own comments',
35 'node test view',
36 'skip comment approval',
37 ]);
38
39 // Set the author of the created node to the web_user uid.
40 $this->node->setOwnerId($this->webUser->id())->save();
41 }
42
43 /**
44 * Test that threaded comments can be viewed.
45 */
46 public function testThreadedCommentView() {
47 // Set comments to have subject required and preview disabled.
48 $this->drupalLogin($this->adminUser);
49 $this->setCommentPreview(DRUPAL_DISABLED);
50 $this->setCommentForm(TRUE);
51 $this->setCommentSubject(TRUE);
52 $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
53 $this->drupalLogout();
54
55 // Post comment.
56 $this->drupalLogin($this->webUser);
57 $comment_text = $this->randomMachineName();
58 $comment_subject = $this->randomMachineName();
59 $comment = $this->postComment($this->node, $comment_text, $comment_subject);
60 $this->assertTrue($this->commentExists($comment), 'Comment found.');
61
62 // Check comment display.
63 $this->drupalGet('node/' . $this->node->id());
64 $this->assertText($comment_subject, 'Individual comment subject found.');
65 $this->assertText($comment_text, 'Individual comment body found.');
66
67 // Reply to comment, creating second comment.
68 $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id());
69 $reply_text = $this->randomMachineName();
70 $reply_subject = $this->randomMachineName();
71 $reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE);
72 $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
73
74 // Go to the node page and verify comment and reply are visible.
75 $this->drupalGet('node/' . $this->node->id());
76 $this->assertText($comment_text);
77 $this->assertText($comment_subject);
78 $this->assertText($reply_text);
79 $this->assertText($reply_subject);
80 }
81
82 }