public function CommentViewAccessTest::testUserCanViewOnlyPublishedComment 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::testUserCanViewOnlyPublishedComment()
Test that a user can view everyone's published comments.
File
- modules/
social_features/ social_comment/ tests/ src/ Kernel/ CommentViewAccessTest.php, line 179
Class
- CommentViewAccessTest
- Tests comment view level access.
Namespace
Drupal\Tests\social_comment\KernelCode
public function testUserCanViewOnlyPublishedComment() {
$this
->setUpCurrentUser([], [
'access comments',
]);
$this
->createComment($this->node, [
'status' => CommentInterface::PUBLISHED,
]);
// Create another user to try and view the comment.
$this
->setUpCurrentUser([], [
'access comments',
]);
$this
->createComment($this->node, [
'status' => CommentInterface::PUBLISHED,
]);
$all_comments = $this->storage
->getQuery()
->accessCheck(FALSE)
->condition('entity_id', $this->node
->id())
->condition('comment_type', 'comment')
->execute();
self::assertCount(2, $all_comments);
$visible_comments = $this->storage
->getQuery()
->accessCheck(TRUE)
->condition('entity_id', $this->node
->id())
->condition('comment_type', 'comment')
->execute();
self::assertCount(2, $visible_comments);
}