3 namespace Drupal\comment\Tests;
5 use Drupal\comment\CommentManagerInterface;
8 * Tests comments with node access.
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.
15 class CommentNodeAccessTest extends CommentTestBase {
22 public static $modules = ['node_access_test'];
24 protected function setUp() {
27 node_access_rebuild();
30 $this->webUser = $this->drupalCreateUser([
33 'create article content',
36 'skip comment approval',
39 // Set the author of the created node to the web_user uid.
40 $this->node->setOwnerId($this->webUser->id())->save();
44 * Test that threaded comments can be viewed.
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();
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.');
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.');
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.');
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);