You are here

protected function DrupalWebTestCase::drupalCreateUser in SimpleTest 6.2

Same name and namespace in other branches
  1. 7.2 drupal_web_test_case.php \DrupalWebTestCase::drupalCreateUser()
  2. 7 drupal_web_test_case.php \DrupalWebTestCase::drupalCreateUser()

Create a user with a given set of permissions. The permissions correspond to the names given on the privileges page.

Parameters

$permissions: Array of permission names to assign to user.

Return value

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

4 calls to DrupalWebTestCase::drupalCreateUser()
BlockTestCase::setUp in tests/block.test
Implementation of setUp().
SimpleTestFunctionalTest::setUp in ./simpletest.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
SimpleTestFunctionalTest::stubTest in ./simpletest.test
Test to be run and the results confirmed.
SimpleTestFunctionalTest::testInternalBrowser in ./simpletest.test
Test the internal browsers functionality.

File

./drupal_web_test_case.php, line 1030

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function drupalCreateUser($permissions = array(
  'access comments',
  'access content',
  'post comments',
  'post comments without approval',
)) {

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

  // Create a user assigned to that role.
  $edit = array();
  $edit['name'] = $this
    ->randomName();
  $edit['mail'] = $edit['name'] . '@example.com';
  $edit['roles'] = array(
    $rid => $rid,
  );
  $edit['pass'] = user_password();
  $edit['status'] = 1;
  $account = user_save('', $edit);
  $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;
}