You are here

public function ApdqcCacheClearCase::testClearArray in Asynchronous Prefetch Database Query Cache 7

Test clearing using an array.

File

./apdqc.test, line 205
Tests for the Asynchronous Prefetch Database Query Cache module.

Class

ApdqcCacheClearCase
Test cache clearing methods for APDQC.

Code

public function testClearArray() {
  $cache = new APDQCache($this->defaultBin);

  // Create three cache entries.
  $cache
    ->set('test_cid_clear1', $this->defaultValue);
  $cache
    ->set('test_cid_clear2', $this->defaultValue);
  $cache
    ->set('test_cid_clear3', $this->defaultValue);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid_clear1', $this->defaultValue) && $this
    ->checkCacheExists('test_cid_clear2', $this->defaultValue) && $this
    ->checkCacheExists('test_cid_clear3', $this->defaultValue), 'Three cache entries were created.');

  // Clear two entries using an array.
  $cache
    ->clear(array(
    'test_cid_clear1',
    'test_cid_clear2',
  ));
  $this
    ->assertFalse($this
    ->checkCacheExists('test_cid_clear1', $this->defaultValue) || $this
    ->checkCacheExists('test_cid_clear2', $this->defaultValue), 'Two cache entries removed after clearing with an array.');

  // Make sure the 3rd entry still exists.
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid_clear3', $this->defaultValue), 'Entry was not cleared from the cache');

  // Create two cache entries.
  $cache
    ->set('test_cid_clear1', $this->defaultValue);
  $cache
    ->set('test_cid_clear2', $this->defaultValue);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid_clear1', $this->defaultValue) && $this
    ->checkCacheExists('test_cid_clear2', $this->defaultValue), 'Two cache entries were created.');

  // Clear all three entries using an array.
  $cache
    ->clear(array(
    'test_cid_clear1',
    'test_cid_clear2',
    'test_cid_clear3',
  ));
  $this
    ->assertFalse($this
    ->checkCacheExists('test_cid_clear1', $this->defaultValue) || $this
    ->checkCacheExists('test_cid_clear2', $this->defaultValue) || $this
    ->checkCacheExists('test_cid_clear3', $this->defaultValue), 'All cache entries removed when the array exceeded the cache clear threshold.');
}