Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Otherwise, it can be very hard to test users with the lack of certain permissions.
db_query('DELETE FROM {role_permission}');
in the setUp method should work fine. Sorry I cannot create patches at the moment.
Comment | File | Size | Author |
---|---|---|---|
#3 | simpletest_clear_permissions.patch | 1.1 KB | boombatower |
#3 | simpletest_clear_permissions_rid.patch | 1009 bytes | boombatower |
Comments
Comment #1
boombatower CreditAttribution: boombatower commentedIf anything we should provide a convenience method to clear the permissions, but since the entire framework is setup to test from the "default" state that would be a large deviation.
Something like:
?
Comment #2
cwgordon7 CreditAttribution: cwgordon7 commentedThat works too.
should work.
Comment #3
boombatower CreditAttribution: boombatower commentedWhich is preferred:
using RID
or name?
tweaked code & comment a tad.
Comment #4
cwgordon7 CreditAttribution: cwgordon7 commentedRID is better, IMO - it's easier to access, for one thing, seeing as $user->roles contains it. The RID patch is rtbc. :) It would be great if we could get this in before the testing party.
Comment #5
boombatower CreditAttribution: boombatower commentedAs would:
#299186: SimpleTest: assertFieldByXPath does not work for selects or textareas with value
#299461: assertEqual() does not work with arrays
#295697: Increase PHP Memory Limit for Simpletest
#295719: node.test cleanup
Comment #6
boombatower CreditAttribution: boombatower commentedStill applies....
clarification "simpletest_clear_permissions_rid.patch".
Comment #7
webchickHm. I'm not so sure about this.
I think a better way to go about this would be to add general functions to user.module that allow adding or deleting a permission from a given role, and have the tests that need that call those instead. This would be useful in far more than just SimpleTest... install profiles, for example.
Moshe thinks it's not fair to ask for that in this patch since it's about something very specific. But it'd be way more awesome if it were generalized. :D
Also, Moshe pointed out:
So probably need a $reset param.
Comment #8
boombatower CreditAttribution: boombatower commentedOnce this feature is decided upon and patch created, lets create tests as well.
Comment #9
Dave ReidI'd invite anyone from this issue to take a look at #300993: User roles and permissions API where I've done a lot of work trying to improve the role and permissions API, as well as implemented a few improvements from this issue. Maybe we should mark one of these as a duplicate?
Comment #10
boombatower CreditAttribution: boombatower commentedSeems valid to mark this one...since you have already been working in other.