You are here

protected function FieldPermissionsCommentTest::checkPrivateFieldPermission in Field Permissions 8

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

Tests access to private field permission.

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

File

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

Class

FieldPermissionsCommentTest
Test field permissions with the comment module and fields.

Namespace

Drupal\Tests\field_permissions\Functional

Code

protected function checkPrivateFieldPermission() {
  $path = 'admin/structure/comment/manage/comment/fields/comment.comment.' . $this->fieldName;
  $permission = [];
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->setCommentFieldPermissions(FieldPermissionTypeInterface::ACCESS_PRIVATE, $permission, $path);

  // Login a user that didn't author the node.
  $this
    ->drupalLogin($this->webUser);

  // View.
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->pageTextNotContains('Limit User comment body');

  // Edit.
  $this
    ->drupalGet('comment/2/edit');
  $this
    ->assertSession()
    ->pageTextNotContains('Limit User comment body');

  // Add permission access user private field.
  $this->webUserRole
    ->grantPermission('access private fields')
    ->save();

  // View.
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('Limit User comment body');

  // Edit.
  $this
    ->drupalGet('comment/2/edit');
  $this
    ->assertSession()
    ->pageTextContains('Limit User comment body');
  $this
    ->drupalLogout();
}