You are here

public function AuthcacheP13nTestDatabaseKeyValueStore::testDelete in Authenticated User Page Caching (Authcache) 7.2

Cover AuthcacheP13nDatabaseKeyValueStore::delete().

File

modules/authcache_p13n/tests/authcache_p13n.db-kv-store.test, line 311
Test case for database key-value store.

Class

AuthcacheP13nTestDatabaseKeyValueStore
Test database key-value store.

Code

public function testDelete() {

  // Delete all.
  $this
    ->dbInsertSampleData();
  $this
    ->assertEqual(count($this->store1
    ->getKeys()), 3);
  $this
    ->assertEqual(count($this->store2
    ->getKeys()), 1);
  $result = $this->store1
    ->delete();
  $this
    ->assertEqual($result, 3, 'Delete should report number of affected rows');
  $this
    ->assertEqual(count($this->store1
    ->getKeys()), 0, 'After deletion of store1, only values of store shall remain');
  $this
    ->assertEqual(count($this->store2
    ->getKeys()), 1, 'After deletion of store1, only values of store shall remain');
  $result = $this->store2
    ->delete();
  $this
    ->assertEqual($result, 1, 'Delete should report number of affected rows');
  $this
    ->assertEqual(count($this->store1
    ->getKeys()), 0, 'After deletion of store2, no values shall remain');
  $this
    ->assertEqual(count($this->store2
    ->getKeys()), 0, 'After deletion of store2, no values shall remain');

  // Delete specific.
  $this
    ->dbInsertSampleData();
  $result = $this->store1
    ->delete(array(
    'k1',
    'k2',
  ));
  $this
    ->assertEqual($result, 2, 'Delete should report number of affected rows');
  $result = $this->store1
    ->getKeys(array(
    'k1',
    'k2',
    'k3',
  ));
  $this
    ->assertEqual(array(
    'k3',
  ), $result, 'Deleted keys should not be returned, existing keys must show up.');

  // Delete missing.
  $result = $this->store1
    ->delete(array(
    'missing-key',
  ));
  $this
    ->assertEqual(0, $result, 'If no keys could be deleted, should return 0');

  // Delete empty key-set.
  $result = $this->store1
    ->delete(array());
  $this
    ->assertEqual(0, $result, 'If empty key-set is specified, should return 0');

  // Remove test data.
  db_delete('authcache_p13n_key_value')
    ->execute();
}