function CommentEntityReferenceTest::testCommentOfUnpublishedNodeBypassAccess
Same name in other branches
- 10 core/modules/comment/tests/src/Functional/CommentEntityReferenceTest.php \Drupal\Tests\comment\Functional\CommentEntityReferenceTest::testCommentOfUnpublishedNodeBypassAccess()
Tests that comments of unpublished are not shown.
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentEntityReferenceTest.php, line 103
Class
- CommentEntityReferenceTest
- Tests that comments behave correctly when added as entity references.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentOfUnpublishedNodeBypassAccess() : void {
// Unpublish the node that has the comment.
$this->node
->setUnpublished()
->save();
// When the user has 'bypass node access' permission, they can still set it.
$edit = [
'entity_reference_comment' => $this->comment
->id(),
];
$this->drupalGet('node/' . $this->node2
->id() . '/edit');
$this->submitForm($edit, 'Save');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('has been updated');
// Comment is seen as administrator user.
$this->assertSession()
->pageTextContains($this->comment
->label());
// But not as anonymous.
$this->drupalLogout();
$this->drupalGet('node/' . $this->node2
->id());
$this->assertSession()
->pageTextContains($this->node2
->label());
$this->assertSession()
->pageTextNotContains($this->comment
->label());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.