You are here

public function ViewsFieldAccessTest::testPrivatePermissions in Field Permissions 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ViewsFieldAccessTest.php \Drupal\Tests\field_permissions\Kernel\ViewsFieldAccessTest::testPrivatePermissions()

Tests private permissions.

File

tests/src/Kernel/ViewsFieldAccessTest.php, line 168

Class

ViewsFieldAccessTest
Test that custom and private field access works with views.

Namespace

Drupal\Tests\field_permissions\Kernel

Code

public function testPrivatePermissions() {
  $this->fieldStorage
    ->setThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PRIVATE)
    ->save();

  // First check with the dedicated permission.
  $this->roleWithAccess
    ->grantPermission('access private fields')
    ->save();
  $this
    ->assertFieldAccess();

  // Now check with actual ownership.
  $this->roleWithAccess
    ->revokePermission('access private fields')
    ->save();
  $this->entity
    ->setOwner($this->userWithAccess)
    ->save();
  $this
    ->assertFieldAccess();
}