UserEditedOwnAccountTest.php

Definition of Drupal\user\Tests\UserEditedOwnAccountTest.

Namespace

Drupal\user\Tests

File

drupal/core/modules/user/lib/Drupal/user/Tests/UserEditedOwnAccountTest.php
View source
<?php

/**
 * @file
 * Definition of Drupal\user\Tests\UserEditedOwnAccountTest.
 */
namespace Drupal\user\Tests;

use Drupal\simpletest\WebTestBase;

/*
 * Test that a user, having editing their own account, can still log in.
 */
class UserEditedOwnAccountTest extends WebTestBase {
  public static function getInfo() {
    return array(
      'name' => 'User edited own account',
      'description' => 'Test user edited own account can still log in.',
      'group' => 'User',
    );
  }
  function testUserEditedOwnAccount() {

    // Change account setting 'Who can register accounts?' to Administrators
    // only.
    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
      ->randomName();
    $this
      ->drupalPost('user/' . $account->uid . '/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);
  }

}

Classes