You are here

function BetterFormatsTestCase::setPermission in Better Formats 6

Same name and namespace in other branches
  1. 6.2 tests/better_formats_anonymous_user.test \BetterFormatsTestCase::setPermission()

Set permission.

Parameters

string $role User role to set permissions for.:

array $permissions Key-value array of permissions to set.:

1 call to BetterFormatsTestCase::setPermission()
BetterFormatsTestCase::testBetterFormatsFunctionalTest in tests/better_formats_anonymous_user.test
Test various behaviors for anonymous users.

File

tests/better_formats_anonymous_user.test, line 106
Tests for the Better Formats module.

Class

BetterFormatsTestCase
@file Tests for the Better Formats module.

Code

function setPermission($role, $permissions) {

  // Get role id (rid) for specified role.
  $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", array(
    '%s' => $role,
  )));
  if ($rid === FALSE) {
    $this
      ->fail(t(' [permission] Role "' . $role . '" not found.'));
  }

  // Create edit array from permission.
  $edit = array();
  foreach ($permissions as $name => $value) {
    $edit[$rid . '[' . $name . ']'] = $value;
  }
  $this
    ->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
  $this
    ->assertText(t('The changes have been saved.'), t(' [permission] Saved changes.'));
}