protected function DrupalWebTestCase::drupalCreateUser
7.x drupal_web_test_case.php | protected DrupalWebTestCase::drupalCreateUser(array $permissions = array()) |
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.
292 calls to DrupalWebTestCase::drupalCreateUser()
- AccessDeniedTestCase::setUp in drupal-7.x/
modules/ system/ system.test - Sets up a Drupal site for running functional and integration tests.
- ActionLoopTestCase::testActionLoop in drupal-7.x/
modules/ simpletest/ tests/ actions.test - Set up a loop with 3 - 12 recursions, and see if it aborts properly.
- ActionsConfigurationTestCase::testActionConfiguration in drupal-7.x/
modules/ simpletest/ tests/ actions.test - Test the configuration of advanced actions through the administration interface.
- AggregatorRenderingTestCase::testBlockLinks in drupal-7.x/
modules/ aggregator/ aggregator.test - Adds a feed block to the page and checks its links.
- AggregatorTestCase::setUp in drupal-7.x/
modules/ aggregator/ aggregator.test - Sets up a Drupal site for running functional and integration tests.
File
- drupal-7.x/
modules/ simpletest/ drupal_web_test_case.php, line 1115
Class
- DrupalWebTestCase
- Test case for typical Drupal tests.
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 = 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;
}