diff --git modules/user/user.module modules/user/user.module
index bbd4886..3c037af 100644
--- modules/user/user.module
+++ modules/user/user.module
@@ -2575,7 +2575,7 @@ function user_roles($membersonly = FALSE, $permission = NULL) {
  *   exists, FALSE otherwise.
  */
 function user_role_load($role) {
-  $field = is_int($role) ? 'rid' : 'name';
+  $field = is_numeric($role) ? 'rid' : 'name';
   return db_select('role', 'r')
     ->fields('r')
     ->condition($field, $role)
diff --git modules/user/user.test modules/user/user.test
index 511d0f6..ed97010 100644
--- modules/user/user.test
+++ modules/user/user.test
@@ -1456,4 +1456,93 @@ class UserEditedOwnAccountTestCase extends DrupalWebTestCase {
     $account->name = $edit['name'];
     $this->drupalLogin($account);
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Test user roles.
+ */
+class RoleAdministrationTestCase extends DrupalWebTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Role administration'),
+      'description' => t('Tests addition and deletion of roles and whether users can be assigned and removed from roles.'),
+      'group' => t('User')
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+    parent::setUp();
+    $this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions'));
+    $this->drupalLogin($this->admin_user);
+  }
+
+  /**
+   * Tests that a role can be added through the role admin interface.
+   */
+  function testAddRole() {
+    $edit['name'] = $this->randomName() ;
+    $this->drupalPost('admin/people/permissions/roles', $edit, t('Add role'));
+    $this->assertText(t('The role has been added.'), t('New role submitted through form.'));
+    $this->assertText($edit['name'], t('Newly added role is displayed on list.'));
+
+    $role = array_pop($this->xpath("//a[starts-with(@href, '/admin/people/permissions/roles/edit')]"));
+
+    $this->drupalPost($role['href'], array(), t('Delete role'));
+    $this->assertText(t('The role has been deleted.'), t('Role deleted through form.'));
+    $this->assertNoLinkByHref($role['href'], t('No link to deleted role.'));
+  }
+
+  /**
+   * Tests that a user can be assigned a role and that the role can be removed
+   * again.
+   */
+  function testCreateUserAndAssignRole()  {
+    $rid = $this->drupalCreateRole(array('access content'));
+    $user = $this->drupalCreateUser();
+    // Assign the role to the user.
+    $this->drupalPost('user/' . $user->uid . '/edit', array("roles[$rid]" => $rid), t('Save'));
+    $this->assertText(t('The changes have been saved.'));
+    $this->assertFieldChecked('edit-roles-' . $rid, t('Role is assigned.'));
+
+    // Remove the role from the user.
+    $this->drupalPost('user/' . $user->uid . '/edit', array("roles[$rid]" => FALSE), t('Save'));
+    $this->assertText(t('The changes have been saved.'));
+    $this->assertNoFieldChecked('edit-roles-' . $rid, t('Role is removed from user.'));
+  }
+
+  /**
+   * Tests that when creating a user the role can be assigned. And that it can
+   * be removed again.
+   */
+  function testCreateUserWithRole() {
+    $rid = $this->drupalCreateRole(array('access content'));
+    // Create a new user and add the role at the same time.
+    $edit = array(
+      'name' => $this->randomName(),
+      'mail' => $this->randomName() . '@example.com',
+      'pass[pass1]' => $pass = $this->randomString(),
+      'pass[pass2]' => $pass,
+      "roles[$rid]" => $rid,
+    );
+    $this->drupalPost('admin/people/create', $edit, t('Create new account'));
+    $this->assertText(t('Created a new user account for !name.', array('!name' => $edit['name'])));
+    // Get the newly added user.
+    $user2 = user_load_by_name($edit['name']);
+
+    $this->drupalGet('user/' . $user2->uid . '/edit');
+    $this->assertFieldChecked('edit-roles-' . $rid, t('Role is assigned.'));
+
+    // Remove the role again.
+    $this->drupalPost('user/' . $user2->uid . '/edit', array("roles[$rid]" => FALSE), t('Save'));
+    $this->assertText(t('The changes have been saved.'));
+    $this->assertNoFieldChecked('edit-roles-' . $rid, t('Role is removed from user.'));
+  }
+}
+
