1 cache.test CacheClearCase::testClearArray()

Test clearing using an array.

File

core/modules/simpletest/tests/cache.test, line 246

Class

CacheClearCase
Test cache clearing methods.

Code

function testClearArray() {
  // Create three cache entries.
  $cache = cache($this->default_bin);
  $cache->set('test_cid_clear1', $this->default_value);
  $cache->set('test_cid_clear2', $this->default_value);
  $cache->set('test_cid_clear3', $this->default_value);
  $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->deleteMultiple(array('test_cid_clear1', 'test_cid_clear2'));
  $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');

  // Check clearing multiple cache entries at the same time.
  $cache->set('test_cid_clear1', $this->default_value);
  $cache->set('test_cid_clear2', $this->default_value);
  $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
    && $this->checkCacheExists('test_cid_clear2', $this->default_value), 
  'Two cache entries were created.');
  $cache->deleteMultiple(array('test_cid_clear1', 'test_cid_clear2', 'test_cid_clear3'));
  $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.');
}