You are here

protected function DrupalWebTestCase::drupalCreateUser in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalWebTestCase::drupalCreateUser()
  2. 7.2 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.

22 calls to DrupalWebTestCase::drupalCreateUser()
ActionLoopTestCase::testActionLoop in tests/actions.test
Set up a loop with 10-50 recursions, and see if it aborts properly.
ActionsConfigurationTestCase::testActionConfiguration in tests/actions.test
Test the configuration of advanced actions through the administration interface.
BootstrapPageCacheTestCase::testConditionalRequests in tests/bootstrap.test
Test support for requests containing If-Modified-Since and If-None-Match headers.
BootstrapPageCacheTestCase::testPageCache in tests/bootstrap.test
Test cache headers.
FileSaveUploadTest::setUp in tests/file.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.…

... See full list

File

./drupal_web_test_case.php, line 855

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(drupal_anonymous_user(), $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;
}