function CommentAccessTest::testCannotViewCommentReplyFormOnEntitiesYouCannotView

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentAccessTest.php \Drupal\Tests\comment\Functional\CommentAccessTest::testCannotViewCommentReplyFormOnEntitiesYouCannotView()
  2. 8.9.x core/modules/comment/tests/src/Functional/CommentAccessTest.php \Drupal\Tests\comment\Functional\CommentAccessTest::testCannotViewCommentReplyFormOnEntitiesYouCannotView()
  3. 10 core/modules/comment/tests/src/Functional/CommentAccessTest.php \Drupal\Tests\comment\Functional\CommentAccessTest::testCannotViewCommentReplyFormOnEntitiesYouCannotView()

Tests cannot view comment reply form on entities you cannot view.

File

core/modules/comment/tests/src/Functional/CommentAccessTest.php, line 96

Class

CommentAccessTest
Tests comment administration and preview access.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCannotViewCommentReplyFormOnEntitiesYouCannotView() : void {
    $assert = $this->assertSession();
    // Create a comment on an unpublished node.
    $comment = Comment::create([
        'entity_type' => 'node',
        'name' => 'Tony',
        'hostname' => 'magic.example.com',
        'mail' => 'foo@example.com',
        'subject' => 'Comment on unpublished node',
        'entity_id' => $this->unpublishedNode
            ->id(),
        'comment_type' => 'comment',
        'field_name' => 'comment',
        'pid' => 0,
        'uid' => $this->unpublishedNode
            ->getOwnerId(),
        'status' => 1,
    ]);
    $comment->save();
    $comment_url = 'comment/reply/node/' . $this->unpublishedNode
        ->id() . '/comment/' . $comment->id();
    // Replying to a comment on an unpublished node results in access denied.
    $this->drupalGet($comment_url);
    $assert->statusCodeEquals(403);
    // Publishing the node grants access.
    $this->unpublishedNode
        ->setPublished()
        ->save();
    $this->drupalGet($comment_url);
    $assert->statusCodeEquals(200);
}

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