public function CommentViewAccessTest::testUserCanNotViewOtherUnpublishedComment in Open Social 10.2.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php \Drupal\Tests\social_comment\Kernel\CommentViewAccessTest::testUserCanNotViewOtherUnpublishedComment()
Test that a user can't view other people's unpublished comments.
File
- modules/
social_features/ social_comment/ tests/ src/ Kernel/ CommentViewAccessTest.php, line 151
Class
- CommentViewAccessTest
- Tests comment view level access.
Namespace
Drupal\Tests\social_comment\KernelCode
public function testUserCanNotViewOtherUnpublishedComment() : void {
// Create a published comment.
$this
->setUpCurrentUser([], [
'access comments',
]);
$this
->createComment($this->node, [
'status' => CommentInterface::NOT_PUBLISHED,
]);
// Create another user to view the comment.
$this
->setUpCurrentUser([], [
'access comments',
]);
$all_comments = $this->storage
->getQuery()
->accessCheck(FALSE)
->condition('entity_id', $this->node
->id())
->condition('comment_type', 'comment')
->execute();
self::assertCount(1, $all_comments);
$visible_comments = $this->storage
->getQuery()
->accessCheck(TRUE)
->condition('entity_id', $this->node
->id())
->condition('comment_type', 'comment')
->execute();
self::assertCount(0, $visible_comments);
}