summaryrefslogtreecommitdiff
path: root/modules/simpletest/drupal_web_test_case.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r--modules/simpletest/drupal_web_test_case.php32
1 files changed, 30 insertions, 2 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 88d5a6b3c..58af4efea 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -191,8 +191,7 @@ class DrupalWebTestCase extends UnitTestCase {
*/
function drupalCreateUser($permissions = NULL) {
// Create a role with the given permission set.
- $rid = $this->_drupalCreateRole($permissions);
- if (!$rid) {
+ if (!($rid = $this->_drupalCreateRole($permissions))) {
return FALSE;
}
@@ -228,6 +227,10 @@ class DrupalWebTestCase extends UnitTestCase {
$permissions = array('access comments', 'access content', 'post comments', 'post comments without approval');
}
+ if (!$this->checkPermissions($permissions)) {
+ return FALSE;
+ }
+
// Create new role.
$role_name = $this->randomName();
db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name);
@@ -248,6 +251,30 @@ class DrupalWebTestCase extends UnitTestCase {
}
/**
+ * Check to make sure that the array of permissions are valid.
+ *
+ * @param array $permissions Permissions to check.
+ * @param boolean $reset Reset cached available permissions.
+ * @return boolean Valid.
+ */
+ private function checkPermissions(array $permissions, $reset = FALSE) {
+ static $available;
+
+ if (!isset($available) || $reset) {
+ $available = array_keys(module_invoke_all('perm'));
+ }
+
+ $valid = TRUE;
+ foreach ($permissions as $permission) {
+ if (!in_array($permission, $available)) {
+ $this->fail(t('Invalid permission %permission.', array('%permission' => $permission)), t('Role'));
+ $valid = FALSE;
+ }
+ }
+ return $valid;
+ }
+
+ /**
* Logs in a user with the internal browser. If already logged in then logs the current
* user out before logging in the specified user. If no user is specified then a new
* user will be created and logged in.
@@ -331,6 +358,7 @@ class DrupalWebTestCase extends UnitTestCase {
actions_synchronize();
_drupal_flush_css_js();
$this->refreshVariables();
+ $this->checkPermissions(array(), TRUE);
// Restore necessary variables.
variable_set('install_profile', 'default');