function CommentNodeAccessTest::testThreadedCommentView

Same name in other branches
  1. 7.x modules/comment/comment.test \CommentNodeAccessTest::testThreadedCommentView()
  2. 9 core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php \Drupal\Tests\comment\Functional\CommentNodeAccessTest::testThreadedCommentView()
  3. 8.9.x core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php \Drupal\Tests\comment\Functional\CommentNodeAccessTest::testThreadedCommentView()
  4. 11.x core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php \Drupal\Tests\comment\Functional\CommentNodeAccessTest::testThreadedCommentView()

Tests that threaded comments can be viewed.

File

core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php, line 54

Class

CommentNodeAccessTest
Tests comments with node access.

Namespace

Drupal\Tests\comment\Functional

Code

public function testThreadedCommentView() : void {
    // Set comments to have subject required and preview disabled.
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    // Post comment.
    $this->drupalLogin($this->webUser);
    $comment_text = $this->randomMachineName();
    $comment_subject = $this->randomMachineName();
    $comment = $this->postComment($this->node, $comment_text, $comment_subject);
    $this->assertTrue($this->commentExists($comment), 'Comment found.');
    // Check comment display.
    $this->drupalGet('node/' . $this->node
        ->id());
    $this->assertSession()
        ->pageTextContains($comment_subject);
    $this->assertSession()
        ->pageTextContains($comment_text);
    // Reply to comment, creating second comment.
    $this->drupalGet('comment/reply/node/' . $this->node
        ->id() . '/comment/' . $comment->id());
    $reply_text = $this->randomMachineName();
    $reply_subject = $this->randomMachineName();
    $reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE);
    $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
    // Go to the node page and verify comment and reply are visible.
    $this->drupalGet('node/' . $this->node
        ->id());
    $this->assertSession()
        ->pageTextContains($comment_text);
    $this->assertSession()
        ->pageTextContains($comment_subject);
    $this->assertSession()
        ->pageTextContains($reply_text);
    $this->assertSession()
        ->pageTextContains($reply_subject);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.