You are here

private function BookAccessTestCase::caseRoleDefaultsPropagateToNewNode in Book access 7.2

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

File

./book_access_test_case.test, line 342

Class

BookAccessTestCase

Code

private function caseRoleDefaultsPropagateToNewNode() {
  $enabledGrants = array(
    'grant_view',
    'grant_update',
  );

  // precondition checks
  $grantsToCheck = array(
    'grant_delete' => FALSE,
    'grant_view' => TRUE,
  );
  $rid = $this
    ->drupalCreateRole(array(
    'access content',
  ));
  if ($rid === FALSE) {
    $this
      ->fail('Couldn\'t create test role');
  }
  $roles = array();
  $roleGrants = BookAccess::getRoleGrants($this->books[0], $roles);
  foreach ($grantsToCheck as $grant => $value) {
    $this
      ->assertEqual($value, $roleGrants[$grant][$rid], t('Grant "@grant" should be @value', array(
      '@grant' => $grant,
      '@value' => $value ? "true" : "false",
    )));
  }

  // change the default and create a new book
  variable_set("book_access_default_role_{$rid}_access", $enabledGrants);
  $roleBooks = array();
  $roleNodes = array();
  $roleUser = $this
    ->drupalCreateUser();
  user_multiple_role_edit(array(
    $roleUser->uid,
  ), 'add_role', $rid);
  $this
    ->createBook($roleBooks, $roleNodes, $roleUser);
  foreach ($enabledGrants as $grant) {
    $this
      ->assertTrue(BookAccess::checkGrant($roleBooks[0]->nid, $grant, $roleUser), t('New book\'s grant "@grant" should be enabled', array(
      '@grant' => $grant,
    )));
  }
}