You are here

private function BookAccessTestCase::caseResetToDefaults in Book access 7.2

1 call to BookAccessTestCase::caseResetToDefaults()
BookAccessTestCase::testCases in ./book_access_test_case.test

File

./book_access_test_case.test, line 505

Class

BookAccessTestCase

Code

private function caseResetToDefaults() {

  // grants that will be set to true
  // after a default reset
  $grantsToCheck = array(
    'grant_delete',
    'grant_view',
    'grant_update',
  );

  // set up user/role
  $rid = $this
    ->drupalCreateRole(array(
    'access content',
  ));
  if ($rid === FALSE) {
    $this
      ->fail('Couldn\'t create test role');
  }
  $roleBooks = array();
  $roleNodes = array();
  $roleUser = $this
    ->drupalCreateUser();
  foreach ($roleUser->roles as $rid => $rname) {
    user_multiple_role_edit(array(
      $roleUser->uid,
    ), 'remove_role', $rid);
  }
  user_multiple_role_edit(array(
    $roleUser->uid,
  ), 'add_role', $rid);
  $roleUser = user_load($roleUser->uid);

  // clear defaults
  variable_set("book_access_default_role_{$rid}_access", array());

  // create with a different author, check defaults
  $this
    ->createBook($roleBooks, $roleNodes, $this->author);
  foreach ($grantsToCheck as $grant) {
    $this
      ->assertFalse(BookAccess::checkGrant($roleBooks[0]->nid, $grant, $roleUser), t('New book\'s grant "@grant" should be disabled', array(
      '@grant' => $grant,
    )));
  }

  // change defaults
  variable_set("book_access_default_role_{$rid}_access", $grantsToCheck);
  BookAccess::resetToDefault($roleBooks[0]->nid);
  foreach ($grantsToCheck as $grant) {
    $this
      ->assertTrue(BookAccess::checkGrant($roleBooks[0]->nid, $grant, $roleUser), t('New book\'s grant "@grant" should be reset to the new default of enabled', array(
      '@grant' => $grant,
    )));
  }
}