diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-11-18 14:59:16 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-11-18 14:59:16 +0000 |
commit | 33905692957eb1cce0451a52ef9a6e8061c7dd83 (patch) | |
tree | d19bb0a28308d3eed00b5fbfbd3013166833bbd4 /modules/user/user.test | |
parent | ccd16b82a6ad62f3e2b00ca47e448be5571073fa (diff) | |
download | brdo-33905692957eb1cce0451a52ef9a6e8061c7dd83.tar.gz brdo-33905692957eb1cce0451a52ef9a6e8061c7dd83.tar.bz2 |
- Patch #334671 by Steve Dondley: users cannot be assigned to roles or removed from them -- comes with tests. Yay.
Diffstat (limited to 'modules/user/user.test')
-rw-r--r-- | modules/user/user.test | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/modules/user/user.test b/modules/user/user.test index 91e1df32e..82f1ca66e 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -570,3 +570,83 @@ class UserAutocompleteTestCase extends DrupalWebTestCase { $this->assertRaw($this->unprivileged_user->name, t('User name found in autocompletion results.')); } } + +/** + * 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); + } + + /** + * Add a role to the site. + */ + function testAddRole() { + $edit['name'] = 'test_role'; + $this->drupalPost('admin/user/roles', $edit, t('Add role')); + $this->assertText(t('The role has been added.'), t('New role submitted through form.')); + + $result = db_query('SELECT rid FROM {role} WHERE name = "test_role"'); + $this->assertTrue($result->fetch(), 'New role added to database.'); + } + + /** + * Delete a role from the site. + */ + function testDeleteRole() { + // Determine largest rid + $rid = db_query('SELECT max(rid) FROM {role}')->fetchField(); + + $this->drupalPost('admin/user/roles/edit/' . $rid, array(), t('Delete role')); + $this->assertText(t('The role has been deleted.'), t('Role deleted through form.')); + $result = db_query('SELECT rid FROM {role} WHERE rid = :rid', array(':rid' => $rid)); + $this->assertFalse($result->fetch(), 'Role deleted from database.'); + } + + /** + * Adds a user to an existing role and removes them from the role. + */ + function testAddAndRemoveUserFromRole() { + // Add a user to an existing role + $regular_user = $this->drupalCreateUser(array()); + $rid = db_query('SELECT max(rid) FROM {role}')->fetchField(); + $uid = $regular_user->uid; + $edit['roles[' . $rid . ']'] = $rid; + $this->drupalPost("user/$uid/edit", $edit, t('Save')); + $this->assertText(t('The changes have been saved.'), t('User added to role through form.')); + $result = db_query('SELECT * FROM {users_roles} WHERE uid = :uid AND rid = :rid', + array(':uid' => $uid, + ':rid' => $rid) + ); + $this->assertTrue($result->fetch(), 'Assigned user to a role'); + + // Remove a user from an existing role + $edit['roles[' . $rid . ']'] = FALSE; + $this->drupalPost("user/$uid/edit", $edit, t('Save')); + $this->assertText(t('The changes have been saved.'), t('User removed from role through form.')); + $result = db_query('SELECT * FROM {users_roles} WHERE uid = :uid AND rid = :rid', + array(':uid' => $uid, + ':rid' => $rid) + ); + $this->assertFalse($result->fetch(), 'Removed user from a role'); + } + +} |