protected function WebTestBase::drupalCreateUser

Create a user with a given set of permissions.

Parameters

array $permissions: Array of permission names to assign to user. Note that the user always has the default permissions derived from the "authenticated users" role.

Return value

object|false A fully loaded user object with pass_raw property, or FALSE if account creation fails.

360 calls to WebTestBase::drupalCreateUser()
AccessDeniedTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php
Sets up a Drupal site for running functional and integration tests.
AccessTest::setUp in drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/AccessTest.php
Sets up a Drupal site for running functional and integration tests.
AccessTestBase::setUp in drupal/core/modules/views/lib/Drupal/views/Tests/User/AccessTestBase.php
Sets up a Drupal site for running functional and integration tests.
AdminTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/System/AdminTest.php
Sets up a Drupal site for running functional and integration tests.
AggregatorRenderingTest::testBlockLinks in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php
Add a feed block to the page and checks its links.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php, line 422
Definition of Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function drupalCreateUser(array $permissions = array()) {

  // Create a role with the given permission set, if any.
  $rid = FALSE;
  if ($permissions) {
    $rid = $this
      ->drupalCreateRole($permissions);
    if (!$rid) {
      return FALSE;
    }
  }

  // Create a user assigned to that role.
  $edit = array();
  $edit['name'] = $this
    ->randomName();
  $edit['mail'] = $edit['name'] . '@example.com';
  $edit['pass'] = user_password();
  $edit['status'] = 1;
  if ($rid) {
    $edit['roles'] = array(
      $rid => $rid,
    );
  }
  $account = entity_create('user', $edit);
  $account
    ->save();
  $this
    ->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array(
    '%name' => $edit['name'],
    '%pass' => $edit['pass'],
  )), t('User login'));
  if (empty($account->uid)) {
    return FALSE;
  }

  // Add the raw password so that we can log in as this user.
  $account->pass_raw = $edit['pass'];
  return $account;
}