diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-05-07 19:34:24 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-05-07 19:34:24 +0000 |
commit | b9f1018ea4fe429656de0fad91fcde51d9507e50 (patch) | |
tree | 20648c37c14f84c119f13c49ce75c97f02c07336 /modules/user/user.test | |
parent | 48e293a6b3d647d79b7b3ce58ab467f9c3fd6de7 (diff) | |
download | brdo-b9f1018ea4fe429656de0fad91fcde51d9507e50.tar.gz brdo-b9f1018ea4fe429656de0fad91fcde51d9507e50.tar.bz2 |
- Patch #73874 by pwolanin: normalize the permissions table and wrote simpletests for the (new) permission handling. At last.
Diffstat (limited to 'modules/user/user.test')
-rw-r--r-- | modules/user/user.test | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/modules/user/user.test b/modules/user/user.test index 6c1570d2b..0e38def11 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -207,3 +207,57 @@ class UserDeleteTestCase extends DrupalWebTestCase { $this->assertFalse(user_load($edit), t('User is not found in the database')); } } + + +class UserPermissionsTestCase extends DrupalWebTestCase { + protected $admin_user; + protected $rid; + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Role permissions'), + 'description' => t('Verify that role permissions can be added and removed via the permissions page.'), + 'group' => t('User') + ); + } + + function setUp() { + parent::setUp(); + + $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'access user profiles')); + + // Find the new role ID - it must be the maximum. + $all_rids = array_keys($this->admin_user->roles); + sort($all_rids); + $this->rid = array_pop($all_rids); + } + + /** + * Change user permissions and check user_access(). + */ + function testUserPermissionChanges() { + $this->drupalLogin($this->admin_user); + $rid = $this->rid; + $account = $this->admin_user; + + // Add a permission. + $this->assertFalse(user_access('administer nodes', $account, TRUE), t('User does not have "administer nodes" permission.')); + $edit = array(); + $edit[$rid . '[administer nodes]'] = TRUE; + $this->drupalPost('admin/user/permissions', $edit, t('Save permissions')); + $this->assertText(t('The changes have been saved.'), t('Successful save message displayed.')); + $this->assertTrue(user_access('administer nodes', $account, TRUE), t('User now has "administer nodes" permission.')); + + // Remove a permission. + $this->assertTrue(user_access('access user profiles', $account, TRUE), t('User has "access user profiles" permission.')); + $edit = array(); + $edit[$rid . '[access user profiles]'] = FALSE; + $this->drupalPost('admin/user/permissions', $edit, t('Save permissions')); + $this->assertText(t('The changes have been saved.'), t('Successful save message displayed.')); + $this->assertFalse(user_access('access user profiles', $account, TRUE), t('User no longer has "access user profiles" permission.')); + } + +} |