function UserPermissionsTestCase::testUserPermissionChanges
7.x user.test | UserPermissionsTestCase::testUserPermissionChanges() |
Change user permissions and check user_access().
File
- drupal-7.x/
modules/ user/ user.test, line 1252 - Tests for user.module.
Class
Code
function testUserPermissionChanges() {
$this->drupalLogin($this->admin_user);
$rid = $this->rid;
$account = $this->admin_user;
// Add a permission.
$this->assertFalse(user_access('administer nodes', $account), 'User does not have "administer nodes" permission.');
$edit = array();
$edit[$rid . '[administer nodes]'] = TRUE;
$this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
$this->assertTrue(user_access('administer nodes', $account), 'User now has "administer nodes" permission.');
// Remove a permission.
$this->assertTrue(user_access('access user profiles', $account), 'User has "access user profiles" permission.');
$edit = array();
$edit[$rid . '[access user profiles]'] = FALSE;
$this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
$this->assertFalse(user_access('access user profiles', $account), 'User no longer has "access user profiles" permission.');
}