1 user.test UserPermissionsTestCase::testUserPermissionChanges()

Change user permissions and check user_access().

File

core/modules/user/tests/user.test, line 1302
Tests for user.module.

Class

UserPermissionsTestCase

Code

function testUserPermissionChanges() {
  $this->backdropLogin($this->admin_user);
  $role_name = $this->role_name;
  $account = $this->admin_user;

  // Add a permission.
  $this->assertFalse(user_access('administer nodes', $account), 'User does not have "administer nodes" permission.');
  $edit = array();
  $edit[$role_name . '[administer nodes]'] = TRUE;
  $this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
  $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
  backdrop_static_reset('user_roles');
  backdrop_static_reset('user_access');
  $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[$role_name . '[access user profiles]'] = FALSE;
  $this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
  $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
  backdrop_static_reset('user_roles');
  backdrop_static_reset('user_access');
  $this->assertFalse(user_access('access user profiles', $account), 'User no longer has "access user profiles" permission.');
}