You are here

public function UserEditedOwnAccountTest::testUserEditedOwnAccount in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserEditedOwnAccountTest.php \Drupal\Tests\user\Functional\UserEditedOwnAccountTest::testUserEditedOwnAccount()

File

core/modules/user/tests/src/Functional/UserEditedOwnAccountTest.php, line 20

Class

UserEditedOwnAccountTest
Tests user edited own account can still log in.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserEditedOwnAccount() {

  // Change account setting 'Who can register accounts?' to Administrators
  // only.
  $this
    ->config('user.settings')
    ->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)
    ->save();

  // Create a new user account and log in.
  $account = $this
    ->drupalCreateUser([
    'change own username',
  ]);
  $this
    ->drupalLogin($account);

  // Change own username.
  $edit = [];
  $edit['name'] = $this
    ->randomMachineName();
  $this
    ->drupalGet('user/' . $account
    ->id() . '/edit');
  $this
    ->submitForm($edit, 'Save');

  // Log out.
  $this
    ->drupalLogout();

  // Set the new name on the user account and attempt to log back in.
  $account->name = $edit['name'];
  $this
    ->drupalLogin($account);
}