You are here

private function BookAccessTestCase::caseAuthorDefaultsPropagateToNewNode in Book access 7.2

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

File

./book_access_test_case.test, line 293

Class

BookAccessTestCase

Code

private function caseAuthorDefaultsPropagateToNewNode() {
  $originalDefaults = variable_get("book_access_default_author_access");
  $newDefaults = array(
    'grant_view',
    'grant_delete',
  );
  variable_set("book_access_default_author_access", $newDefaults);
  $userBooks = array();
  $userNodes = array();
  $this
    ->createBook($userBooks, $userNodes, $this->author);

  // verify that our db data is correct, too
  $resultSet = db_select('book_access_author', 'book_access_author')
    ->condition('uid', $this->author->uid, '=')
    ->condition('nid', $userBooks[0]->nid, '=')
    ->fields('book_access_author')
    ->execute();
  $this
    ->assertTrue($resultSet
    ->rowCount() == 1, t('Exactly one entry in the database'));
  $row = $resultSet
    ->fetchAssoc();
  foreach ($originalDefaults as $grant) {
    if (in_array($grant, $newDefaults)) {
      $this
        ->assertTrue(BookAccess::checkGrant($userBooks[0]->nid, $grant, $this->author), t('New author default for grant "@grant" should be TRUE', array(
        '@grant' => $grant,
      )));
      $this
        ->assertEqual(1, $row[$grant], t('DB entry for node @nid, author @uid, grant "@grant" should be 1', array(
        '@nid' => $userBooks[0]->nid,
        '@uid' => $this->author->uid,
        '@grant' => $grant,
      )));
    }
    else {
      $this
        ->assertFalse(BookAccess::checkGrant($userBooks[0]->nid, $grant, $this->author), t('New author default for grant "@grant" should be FALSE', array(
        '@grant' => $grant,
      )));
      $this
        ->assertEqual(0, $row[$grant], t('DB entry for node @nid, author @uid, grant "@grant" should be 0', array(
        '@nid' => $userBooks[0]->nid,
        '@uid' => $this->author->uid,
        '@grant' => $grant,
      )));
    }
  }
  variable_set("book_access_default_author_access", $originalDefaults);
}