ClearTest.php 1.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php

/**
 * @file
 * Definition of Drupal\system\Tests\Cache\ClearTest.
 */

namespace Drupal\system\Tests\Cache;

/**
 * Tests cache clearing methods.
 */
class ClearTest extends CacheTestBase {
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  public static function getInfo() {
    return array(
      'name' => 'Cache clear test',
      'description' => 'Check our clearing is done the proper way.',
      'group' => 'Cache'
    );
  }

  function setUp() {
    $this->default_bin = 'page';
    $this->default_value = $this->randomName(10);

    parent::setUp();
  }

  /**
31
   * Tests drupal_flush_all_caches().
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
   */
  function testFlushAllCaches() {
    // Create cache entries for each flushed cache bin.
    $bins = module_invoke_all('cache_flush');
    $this->assertTrue($bins, 'hook_cache_flush() returned bins to flush.');
    $bins = array_merge($bins, array('menu'));
    foreach ($bins as $id => $bin) {
      $cid = 'test_cid_clear' . $id;
      cache($bin)->set($cid, $this->default_value);
    }

    // Remove all caches then make sure that they are cleared.
    drupal_flush_all_caches();

    foreach ($bins as $id => $bin) {
      $cid = 'test_cid_clear' . $id;
48
      $this->assertFalse($this->checkCacheExists($cid, $this->default_value, $bin), format_string('All cache entries removed from @bin.', array('@bin' => $bin)));
49 50 51
    }
  }
}