Hi folk,
I have a large code base for a large distributed, (8000 users, 300000 person database) volunteer organisation that is very security and privacy aware. We have complex business rules implemented in custom logic that leverages and extends the drupal permission system.
I have a big suite of tests against our complex rules I've I've hit a snag with the way user_access short-cuts the global drupal static variable cache. This means it is impossible to reset the cache in the same page load. (or am I missing something??)
the solution seems to be something like this:
Index: user.module
===================================================================
--- user.module (revision 3345)
+++ user.module (working copy)
@@ -782,6 +782,7 @@
*
* @param $string
* The permission, such as "administer nodes", being checked for.
+ * If -1 then resets caching (to allow unit testing while masquerading as a new user);
* @param $account
* (optional) The account to check, if not given use currently logged in user.
*
@@ -808,6 +809,12 @@
// in a static variable.
// Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast;
+ // reset cache
+ if ($string === -1) {
+ unset($drupal_static_fast);
+ drupal_static_reset(__FUNCTION__);
+ return TRUE;
+ }
if (!isset($drupal_static_fast)) {
$drupal_static_fast['perm'] = &drupal_static(__FUNCTION__);
}
is this practical??
many thanks in advance for guidance
Comments
Comment #1
Erich Schulz commentedsorry - figured it out