protected function ForumAccessBaseTestCase::drupalCreateNamedUser in Forum Access 7
Extend drupalCreateUser() base method to accept a name as well as multiple roles (rather than permissions).
Parameters
$name: Name to assign to the user
$rids: Array of Role IDs to assign to user.
Return value
A fully loaded user object with pass_raw property, or FALSE if account creation fails.
1 call to ForumAccessBaseTestCase::drupalCreateNamedUser()
File
- tests/
forum_access_test_base.php, line 301 - Base class with auxiliary functions for forum access module tests.
Class
- ForumAccessBaseTestCase
- Base test class for the Forum Access module.
Code
protected function drupalCreateNamedUser($name, $rids = array()) {
// Create a user.
$rids2 = array();
foreach ($rids as $rid) {
$rids2[$rid] = $rid;
}
$edit = array();
$edit['name'] = $name;
$edit['mail'] = $edit['name'] . '@example.com';
$edit['roles'] = $rids2;
$edit['pass'] = user_password();
$edit['status'] = 1;
$account = user_save(drupal_anonymous_user(), $edit);
$this
->assertTrue(!empty($account->uid), t('User %name created, uid=%uid.', array(
'%name' => $edit['name'],
'%uid' => $account->uid,
)), 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;
}