You are here

public function FieldAccessTest::testNameAccess in User protect 8

Tests field access for the user's name.

File

tests/src/Kernel/FieldAccessTest.php, line 36

Class

FieldAccessTest
Tests field access for each UserProtection plugin that protects a field.

Namespace

Drupal\Tests\userprotect\Kernel

Code

public function testNameAccess() {

  // Create an account with no protection. The logged in user should have the
  // privileges to edit this account's name.
  $account = $this
    ->drupalCreateUser();
  $this
    ->assertTrue($account->name
    ->access('edit', $this->userAdmin), 'User admin can edit account name of non-protected user.');

  // Create a protected account. The logged in user should NOT have the
  // privileges to edit this account's name.
  $protected_account = $this
    ->createProtectedUser([
    'user_name',
  ]);
  $this
    ->assertFalse($protected_account->name
    ->access('edit', $this->userAdmin), 'User admin cannot edit account name of protected user.');
}