Assign all permissions to a user programatically Is there a way to assign all the permissions to an authenticated user through code, I want to do it in unit tests.
You could use rules - when a user is created (could include certain contextual requirements) then all the roles are added.

or the less tidy way

You could get all the roles from the DB and then insert each into the user_roles table.

Something like:

$userID = 'ENTER UID';
$query = db_select('user_roles', 'r')-&gt;fields('r')-&gt;execute();

while($role = $query-&gt;fetchObject()){
    db_insert('user_roles')-&gt;fields(array('uid' =&gt; $userID, 'rid' =&gt; $role-&gt;rid))-&gt;execute();
}
drupal_static_reset('user_access');  /* Flush the caches */
drupal_static_reset('user_role_permissions');  /* Flush the caches */


The code is untested but should be a good foundation. 

You can also do the same in Drupal by loading the user object and making the changes, but the above will do the same.