Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.89
diff -u -r1.89 user.test
--- modules/user/user.test	20 Apr 2010 09:48:06 -0000	1.89
+++ modules/user/user.test	23 Apr 2010 08:43:03 -0000
@@ -1585,3 +1585,67 @@
     }
   }
 }
+
+/**
+ * Test creating user roles and assigning them to users
+ */
+class UserRoleCreationAssignmentTest extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'User role assignment',
+      'description' => 'Test assigning user roles to users.',
+      'group' => 'User',
+    );
+  }
+  
+  function setup() {
+    parent::setUp();
+    $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
+  }
+  
+  /**
+   * Tests the ability to assign/revoke roles to new users
+   */
+  function testRoleAssignment() {
+    $this->drupalLogin($this->admin_user);
+    
+    $myTestUser = $this->drupalCreateUser();
+    
+    // Loads a role from the database, then modify a role to save back to the database. We do this to ensure the test's sample data doesn't become obsolete upon a schema change.
+    $newRole = user_role_load(2); // authenticated user
+    
+    // We're going to check to make sure that we're loading the authenticated user role, because if we're not, then we can't guarantee the data for the rest of the test.
+    $this->assertTrue($newRole->name == 'authenticated user', t('User role loaded from the database is an authenticated user'));
+    
+    unset($newRole->rid);
+    $newRole->name = "Test Role";
+    user_role_save($newRole);
+    $newRoleFromDB = user_role_load_by_name("Test Role");
+    $this->assertTrue(is_object($newRoleFromDB), t('Role loaded successfully.'));
+    $newRoleId = $newRoleFromDB->rid;
+    
+    // save new roles to user
+    $edit = array(
+      'roles' => array(),
+    );
+    $edit['roles'][$newRoleId] = 'Test Role';
+    $myTestUser = user_save($myTestUser, $edit);
+    
+    $this->assertTrue(user_access('access content', $myTestUser), t('User has permission from authenticated role.'));
+    $this->assertFalse(user_access('administer nodes', $myTestUser), t('User does not have permission to administer content.'));   
+    
+    // grant an additional permission to test role.
+    user_role_grant_permissions($newRoleId, array('administer nodes'));
+    
+    // Manual check of permission in database, sanity check
+    $perm = db_query('SELECT rid FROM {role_permission} WHERE rid = :rid AND permission = :permission',
+      array(
+        ':rid' => $newRoleId,
+        ':permission' => 'administer nodes',
+      ))->fetchField();
+      
+    $this->assertTrue($perm == $newRoleId, t('User permission sanity check.'));
+        
+    $this->assertTrue(user_access('administer nodes', $myTestUser), t('User has permission to access administer content'));
+  }
+}
