You are here

private function CommentViewAccessTest::createComment in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php \Drupal\Tests\social_comment\Kernel\CommentViewAccessTest::createComment()

Create and save a comment entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the comment is made on.

mixed[] $values: An optional array of values to pass to Comment::create.

Return value

\Drupal\comment\CommentInterface The created comment.

Throws

\Drupal\Core\Entity\EntityStorageException

4 calls to CommentViewAccessTest::createComment()
CommentViewAccessTest::testUserCanNotViewCommentWithoutPermission in modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php
Test that a user can not view comment without permission.
CommentViewAccessTest::testUserCanNotViewOtherUnpublishedComment in modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php
Test that a user can't view other people's unpublished comments.
CommentViewAccessTest::testUserCanNotViewOwnUnpublishedComment in modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php
Test that a user can't view their own unpublished comments.
CommentViewAccessTest::testUserCanViewOnlyPublishedComment in modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php
Test that a user can view everyone's published comments.

File

modules/social_features/social_comment/tests/src/Kernel/CommentViewAccessTest.php, line 217

Class

CommentViewAccessTest
Tests comment view level access.

Namespace

Drupal\Tests\social_comment\Kernel

Code

private function createComment(EntityInterface $entity, array $values = []) : CommentInterface {

  /** @var \Drupal\comment\CommentInterface $comment */
  $comment = $this->storage
    ->create($values + [
    'entity_id' => $entity
      ->id(),
    'entity_type' => $entity
      ->getEntityTypeId(),
    'comment_type' => 'comment',
    'field_name' => 'comments',
  ]);
  $comment
    ->save();
  return $comment;
}