You are here

public function UserProtectionPermissionsTest::testEditOwnPass in User protect 8

Tests edit password with permission "userprotect.pass.edit".

Tests if an user with the permission "userprotect.pass.edit" can edit its own password.

File

tests/src/Functional/UserProtectionPermissionsTest.php, line 85

Class

UserProtectionPermissionsTest
Tests if "change own" User Protect permissions are respected.

Namespace

Drupal\Tests\userprotect\Functional

Code

public function testEditOwnPass() {

  // Create account that may edit its own password.
  $account = $this
    ->drupalCreateUser([
    'userprotect.pass.edit',
    'userprotect.account.edit',
  ]);
  $this
    ->drupalLogin($account);
  $new_pass = $this
    ->randomMachineName();
  $edit = [
    'current_pass' => $account->pass_raw,
    'pass[pass1]' => $new_pass,
    'pass[pass2]' => $new_pass,
  ];
  $this
    ->drupalPostForm('user/' . $account
    ->id() . '/edit', $edit, t('Save'));

  // Assert the password changed.
  $account = $this
    ->reloadEntity($account);
  $account->passRaw = $new_pass;
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($account);
}