You are here

private function FieldPermissionsUserTest::setUserFieldPermission in Field Permissions 8

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

Set user field permissions to the given type.

Parameters

string $perm: The permission type to set.

array $custom_permission: An array of custom permissions.

3 calls to FieldPermissionsUserTest::setUserFieldPermission()
FieldPermissionsUserTest::checkPrivateField in tests/src/Functional/FieldPermissionsUserTest.php
Test field access with private permissions.
FieldPermissionsUserTest::checkUserViewEditField in tests/src/Functional/FieldPermissionsUserTest.php
Tests custom permissions.
FieldPermissionsUserTest::checkUserViewEditOwnField in tests/src/Functional/FieldPermissionsUserTest.php
Test PUBLIC - view_own and edit_own field.

File

tests/src/Functional/FieldPermissionsUserTest.php, line 167

Class

FieldPermissionsUserTest
Test field permissions on users.

Namespace

Drupal\Tests\field_permissions\Functional

Code

private function setUserFieldPermission($perm, array $custom_permission = []) {
  $current_user = $this->loggedInUser;
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/config/people/accounts/fields/user.user.' . $this->fieldName);
  if ($perm === FieldPermissionTypeInterface::ACCESS_PUBLIC || $perm === FieldPermissionTypeInterface::ACCESS_PRIVATE) {
    $edit = [
      'type' => $perm,
    ];
    $this
      ->submitForm($edit, 'Save settings');
  }
  elseif ($perm === FieldPermissionTypeInterface::ACCESS_CUSTOM && !empty($custom_permission)) {
    $custom_permission['type'] = $perm;
    $this
      ->submitForm($custom_permission, 'Save settings');
  }
  if ($current_user) {
    $this
      ->drupalLogin($current_user);
  }
}