You are here

protected function FieldPermissionsTestCase::_assertUserPermissionState in Field Permissions 7

Helper function for asserting user permissions.

2 calls to FieldPermissionsTestCase::_assertUserPermissionState()
FieldPermissionsTestCase::assertUserDoesNotHavePermission in ./field_permissions.test
Asserts that a user account does not have a permission.
FieldPermissionsTestCase::assertUserHasPermission in ./field_permissions.test
Asserts that a user account has a permission.

File

./field_permissions.test, line 317
Tests for field_permissions.module.

Class

FieldPermissionsTestCase
Tests the Field Permissions module.

Code

protected function _assertUserPermissionState($account, $permission, $message, $should_have_permission) {

  // We need to clear static caches since the tests may have recently changed
  // the permissions via the UI (i.e., in a different thread than the one
  // running the tests).
  drupal_static_reset('user_access');
  drupal_static_reset('user_role_permissions');

  // Load the full user account, since we may have been provided an out of
  // date pseudo-account of the kind SimpleTest uses (e.g. as returned by
  // drupalCreateUser()), rather than an up to date object that actually
  // contains the full list of roles this user has been assigned.
  $full_account = user_load($account->uid);

  // Now check the permission.
  $has_permission = user_access($permission, $full_account);
  if ($should_have_permission) {
    $this
      ->assertTrue($has_permission, $message);
  }
  else {
    $this
      ->assertFalse($has_permission, $message);
  }
}