You are here

UserEditedOwnAccountTest.php in Drupal 8

Same filename and directory in other branches
  1. 9 core/modules/user/tests/src/Functional/UserEditedOwnAccountTest.php

File

core/modules/user/tests/src/Functional/UserEditedOwnAccountTest.php
View source
<?php

namespace Drupal\Tests\user\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\user\UserInterface;

/**
 * Tests user edited own account can still log in.
 *
 * @group user
 */
class UserEditedOwnAccountTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  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
      ->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);
  }

}

Classes

Namesort descending Description
UserEditedOwnAccountTest Tests user edited own account can still log in.