Spun off from #691938: Block caching per-role, per-user, per-page is broken, I had a problem where I wanted to create two test users with the same role. drupalCreateUser() internally calls drupalCreateRole(), and you get a new role every time, even if you pass the same permissions to drupalCreateUser(). I had to do some workarounds to copy the roles from one user to another.
This patch caches the roles according to (permission list + optional role name), allowing you to do:
$this->normal_user = $this->drupalCreateUser();
$this->normal_user_alt = $this->drupalCreateUser();
and they share a role since they both have the same (default) permissions. I think this a nice unobtrusive way to approach it, rather than modifying drupalCreateUser() to accept a role id/array/object. I'm too lazy for that :)
| Comment | File | Size | Author |
|---|---|---|---|
| simpletest-roles.patch | 1.42 KB | carlos8f |
Comments
Comment #1
dries commentedI'm not sure. I'd actually change drupalCreateUser() to accept a roles array instead of a permissions array. That would be a bigger change, of course, but it would make sense.
Comment #2
Chaulky commentedI agree that drupalCreateUser() should accept a roles array. There are many use cases where testing with a specific role rather than a specific set of permissions makes sense. The current behavior should absolutely be preserved as it is also useful in many situations.