You are here

function UserEditedOwnAccountTest::testUserEditedOwnAccount in Zircon Profile 8

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

File

core/modules/user/src/Tests/UserEditedOwnAccountTest.php, line 26
Contains \Drupal\user\Tests\UserEditedOwnAccountTest.

Class

UserEditedOwnAccountTest
Tests user edited own account can still log in.

Namespace

Drupal\user\Tests

Code

function testUserEditedOwnAccount() {

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

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

  // Change own username.
  $edit = array();
  $edit['name'] = $this
    ->randomMachineName();
  $this
    ->drupalPostForm('user/' . $account
    ->id() . '/edit', $edit, t('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);
}