You are here

public function MassPasswordTestBase::setUp in Mass Password Change 8

Set up a privileged user.

Overrides BrowserTestBase::setUp

File

tests/src/Functional/MassPasswordTestBase.php, line 36

Class

MassPasswordTestBase
Test base class for mass_password_change module.

Namespace

Drupal\Tests\mass_password_change\Functional

Code

public function setUp() {
  parent::setUp();

  // Create roles.
  $roles = [];
  for ($i = 0; $i < 3; $i++) {
    $role = $this
      ->drupalCreateRole([]);
    $roles[$role] = $role;
  }

  // Create users.
  for ($i = 0; $i < 8; $i++) {
    if ($i % 5 == 0) {
      $account = $this
        ->drupalCreateUser([], NULL, TRUE);
    }
    else {
      $account = $this
        ->drupalCreateUser();
    }
    $account->roles[] = array_rand($roles);
    $account
      ->save();
  }

  // Create and log in our privileged user.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer users',
  ]);
  $this
    ->drupalLogin($this->adminUser);

  // Get accounts from user listing page.
  $this
    ->drupalGet('/admin/people');
  $this->accounts = $this
    ->getUserObjectsFromAccountsPage();
}