summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-12-22 01:56:09 -0800
committerwebchick <webchick@24967.no-reply.drupal.org>2011-12-22 01:56:09 -0800
commite134bd5b1626c721018a15872af390759ba1b843 (patch)
treecaca3aaf8b5f92fa13489bc1b96b132dfc5b6b0d
parent640507b6ba9bf9796739f03913bd1fe5aadac679 (diff)
downloadbrdo-e134bd5b1626c721018a15872af390759ba1b843.tar.gz
brdo-e134bd5b1626c721018a15872af390759ba1b843.tar.bz2
Issue #1366232 by sun: Fixed drupalCreateUser() breaks if testing site/profile does not install Comment module.
-rw-r--r--modules/simpletest/drupal_web_test_case.php27
1 files changed, 17 insertions, 10 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 783bba064..48b06406e 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1071,28 +1071,35 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
- * Create a user with a given set of permissions. The permissions correspond to the
- * names given on the privileges page.
+ * Create a user with a given set of permissions.
*
- * @param $permissions
- * Array of permission names to assign to user.
- * @return
+ * @param 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 object|false
* A fully loaded user object with pass_raw property, or FALSE if account
* creation fails.
*/
- protected function drupalCreateUser($permissions = array('access comments', 'access content', 'post comments', 'skip comment approval')) {
- // Create a role with the given permission set.
- if (!($rid = $this->drupalCreateRole($permissions))) {
- return FALSE;
+ 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['roles'] = array($rid => $rid);
$edit['pass'] = user_password();
$edit['status'] = 1;
+ if ($rid) {
+ $edit['roles'] = array($rid => $rid);
+ }
$account = user_save(drupal_anonymous_user(), $edit);