You are here

function UserPermissionsTestCase::testUserPermissionChanges in Drupal 7

Change user permissions and check user_access().

File

modules/user/user.test, line 1596
Tests for user.module.

Class

UserPermissionsTestCase

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.');
}