function CacheClearCase::testClearArray

7.x cache.test CacheClearCase::testClearArray()

Test clearing using an array.

File

drupal-7.x/modules/simpletest/tests/cache.test, line 288

Class

CacheClearCase
Test cache clearing methods.

Code

function testClearArray() {
  // Create three cache entries.
  cache_set('test_cid_clear1', $this->default_value, $this->default_bin);
  cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
  cache_set('test_cid_clear3', $this->default_value, $this->default_bin);
  $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
    && $this->checkCacheExists('test_cid_clear2', $this->default_value)
    && $this->checkCacheExists('test_cid_clear3', $this->default_value), 
  'Three cache entries were created.');

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

  $this->assertTrue($this->checkCacheExists('test_cid_clear3', $this->default_value), 
  'Entry was not cleared from the cache');

  // Set the cache clear threshold to 2 to confirm that the full bin is cleared
  // when the threshold is exceeded.
  variable_set('cache_clear_threshold', 2);
  cache_set('test_cid_clear1', $this->default_value, $this->default_bin);
  cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
  $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
    && $this->checkCacheExists('test_cid_clear2', $this->default_value), 
  'Two cache entries were created.');
  cache_clear_all(array('test_cid_clear1', 'test_cid_clear2', 'test_cid_clear3'), $this->default_bin);
  $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value)
    || $this->checkCacheExists('test_cid_clear2', $this->default_value)
    || $this->checkCacheExists('test_cid_clear3', $this->default_value), 
  'All cache entries removed when the array exceeded the cache clear threshold.');
}