You are here

public function FieldAccessTest::testMailAccess in User protect 8

Tests field access for the user's mail address.

File

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

Class

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

Namespace

Drupal\Tests\userprotect\Kernel

Code

public function testMailAccess() {

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

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