You are here

protected function FieldPermissionsCommentTest::checkPrivateCommentField in Field Permissions 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/FieldPermissionsCommentTest.php \Drupal\Tests\field_permissions\Functional\FieldPermissionsCommentTest::checkPrivateCommentField()

Tests the comment field when set to private.

1 call to FieldPermissionsCommentTest::checkPrivateCommentField()
FieldPermissionsCommentTest::testFieldPermissionComment in tests/src/Functional/FieldPermissionsCommentTest.php
Test field permissions on comments.

File

tests/src/Functional/FieldPermissionsCommentTest.php, line 225

Class

FieldPermissionsCommentTest
Test field permissions with the comment module and fields.

Namespace

Drupal\Tests\field_permissions\Functional

Code

protected function checkPrivateCommentField() {
  $path = 'admin/structure/comment/manage/comment/fields/comment.comment.' . $this->fieldName;
  $permission = [];
  $this
    ->drupalLogin($this->adminUser);

  // Add perm to admin (admin field permissions).
  $this->adminUserRole
    ->grantPermission('administer field permissions')
    ->save();

  // Set Private field to comment body.
  $this
    ->setCommentFieldPermissions(FieldPermissionTypeInterface::ACCESS_PRIVATE, $permission, $path);
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->limitedUser);
  $this
    ->drupalGet('node/' . $this->node
    ->id());

  // Test hide body comment post by Adminuser but display subject..
  $this
    ->assertSession()
    ->pageTextContains($this->commentSubject);
  $this
    ->assertSession()
    ->pageTextNotContains($this->fieldText);

  // Test view your comment.
  $this
    ->assertSession()
    ->pageTextContains('Limit User comment subject');
  $this
    ->assertSession()
    ->pageTextContains('Limit User comment body');

  // Test edit your comment.
  $this
    ->drupalGet('comment/2/edit');
  $this
    ->assertSession()
    ->pageTextContains('Limit User comment body');

  // Logout and access as anonymous.
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('comment/2/edit');

  // Comment body should be hidden.
  $this
    ->assertSession()
    ->pageTextNotContains('Limit User comment body');
  $this
    ->drupalLogout();
}