You are here

protected function RoleDelegationTestCase::assignPermissionToRole in Role Delegation 7

Assign or remove one permission to/from one role, and assert that the result succeeded.

Parameters

$permission: The name of the permission to assign or remove.

$rid: The role id of the role to assign/remove the permission to/from.

$assign: TRUE (the default) to assign the permission, or FALSE to remove it.

Return value

TRUE or FALSE depending on whether the permission was successfully assigned or removed.

1 call to RoleDelegationTestCase::assignPermissionToRole()
RoleDelegationTestCase::setUp in ./role_delegation.test
Sets up a Drupal site for running functional and integration tests.

File

./role_delegation.test, line 66
Tests for the Role Delegation module.

Class

RoleDelegationTestCase
Base class for Role Delegation tests.

Code

protected function assignPermissionToRole($permission, $rid, $assign = TRUE) {
  $name = "{$rid}[{$permission}]";
  $this
    ->drupalPost("admin/people/permissions/{$rid}", array(
    $name => $assign,
  ), t('Save permissions'));
  $elements = $this
    ->xpath("//input[@name='{$name}']");
  $this
    ->assertTrue(isset($elements[0]) && ($assign xor empty($elements[0]['checked'])), ($assign ? 'Assign' : 'Remove') . ' permission "' . $permission . '" ' . ($assign ? 'to' : 'from') . " role {$rid}.");
}