Add user to a role

iterator - June 1, 2009 - 10:21
Project:SimpleTest
Version:6.x-2.8
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi..
Is it possible to add an user to an specific role? I only found the possibility to add permissions to an user:

$this->drupalCreateUser(array('access content', 'create page content'));

Do i have to add all permissions of an role or is it possible to add the role directly? For example: drupalUserRole('moderator');

#1

Dave Reid - June 1, 2009 - 19:40

This isn't really possible right now using the built-in DrupalWebTestCase methods. I can really only see a couple possible solutions: add all the permissions that you need (what all of core tests do right now), run a query to add the user ID and desired role ID to the {user_roles} table.

I've been trying to improve the user role/permission APIs in core with #300993: User roles and permissions API.

#2

boombatower - June 2, 2009 - 05:14
Status:active» postponed (maintainer needs more info)

@Dave Reid is right. Options then are to do the db query as he suggested or submit the page in drupal that allows you set a user to a role. Depends on your test.

#3

boombatower - September 14, 2009 - 19:48
Status:postponed (maintainer needs more info)» fixed

#4

System Message - September 28, 2009 - 19:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.