Issue #1366232 by sun: Fixed drupalCreateUser() breaks if testing site/profile does not install Comment module.
parent
4fa6611e4e
commit
f7dd1a5fed
|
@ -1093,28 +1093,35 @@ class DrupalWebTestCase extends DrupalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a user with a given set of permissions. The permissions correspond to the
|
* Create a user with a given set of permissions.
|
||||||
* names given on the privileges page.
|
|
||||||
*
|
*
|
||||||
* @param $permissions
|
* @param array $permissions
|
||||||
* Array of permission names to assign to user.
|
* Array of permission names to assign to user. Note that the user always
|
||||||
* @return
|
* has the default permissions derived from the "authenticated users" role.
|
||||||
|
*
|
||||||
|
* @return object|false
|
||||||
* A fully loaded user object with pass_raw property, or FALSE if account
|
* A fully loaded user object with pass_raw property, or FALSE if account
|
||||||
* creation fails.
|
* creation fails.
|
||||||
*/
|
*/
|
||||||
protected function drupalCreateUser($permissions = array('access comments', 'access content', 'post comments', 'skip comment approval')) {
|
protected function drupalCreateUser(array $permissions = array()) {
|
||||||
// Create a role with the given permission set.
|
// Create a role with the given permission set, if any.
|
||||||
if (!($rid = $this->drupalCreateRole($permissions))) {
|
$rid = FALSE;
|
||||||
return FALSE;
|
if ($permissions) {
|
||||||
|
$rid = $this->drupalCreateRole($permissions);
|
||||||
|
if (!$rid) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a user assigned to that role.
|
// Create a user assigned to that role.
|
||||||
$edit = array();
|
$edit = array();
|
||||||
$edit['name'] = $this->randomName();
|
$edit['name'] = $this->randomName();
|
||||||
$edit['mail'] = $edit['name'] . '@example.com';
|
$edit['mail'] = $edit['name'] . '@example.com';
|
||||||
$edit['roles'] = array($rid => $rid);
|
|
||||||
$edit['pass'] = user_password();
|
$edit['pass'] = user_password();
|
||||||
$edit['status'] = 1;
|
$edit['status'] = 1;
|
||||||
|
if ($rid) {
|
||||||
|
$edit['roles'] = array($rid => $rid);
|
||||||
|
}
|
||||||
|
|
||||||
$account = user_save(drupal_anonymous_user(), $edit);
|
$account = user_save(drupal_anonymous_user(), $edit);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue