You are here

public function AccessSchemeFunctionTest::testSchemeDeleteWithGrants in Access Control Kit 7

Test deleting an access scheme that contains grants.

File

./access.test, line 546
Tests for the access control kit module.

Class

AccessSchemeFunctionTest
Tests for access scheme functions.

Code

public function testSchemeDeleteWithGrants() {
  $this
    ->assertEqual(2, count($this->schemes));

  // Create five access grants each for the two test schemes.
  foreach ($this->schemes as $scheme) {

    // Assert that there are no existing grants for the access scheme.
    $has_rows = (bool) db_query_range('SELECT 1 FROM {access_grant} WHERE scheme = :scheme', 0, 1, array(
      ':scheme' => $scheme->machine_name,
    ))
      ->fetchField();
    $this
      ->assertFalse($has_rows);
    for ($i = 0; $i < 5; $i++) {
      $this
        ->createGrant($scheme);
    }

    // Assert that there are now five grants for the access scheme.
    $this
      ->assertEqual(5, db_query('SELECT COUNT(*) FROM {access_grant} WHERE scheme = :scheme', array(
      ':scheme' => $scheme->machine_name,
    ))
      ->fetchField());
  }

  // Delete the first scheme.
  $scheme = reset($this->schemes);
  access_scheme_delete($scheme->sid);

  // Assert that there are no grants left for the deleted scheme.
  $has_rows = (bool) db_query_range('SELECT 1 FROM {access_grant} WHERE scheme = :scheme', 0, 1, array(
    ':scheme' => $scheme->machine_name,
  ))
    ->fetchField();
  $this
    ->assertFalse($has_rows);

  // Assert that there are still five grants for the remaining scheme.
  $scheme = array_pop($this->schemes);
  $this
    ->assertEqual(5, db_query('SELECT COUNT(*) FROM {access_grant} WHERE scheme = :scheme', array(
    ':scheme' => $scheme->machine_name,
  ))
    ->fetchField());
}