You are here

class MemcacheTestCase in Zircon Profile 8.0

Same name in this branch
  1. 8.0 modules/memcache/tests/memcache.test \MemcacheTestCase
  2. 8.0 modules/memcache/tests/memcache6.test \MemcacheTestCase
Same name and namespace in other branches
  1. 8 modules/memcache/tests/memcache.test \MemcacheTestCase
  2. 8 modules/memcache/tests/memcache6.test \MemcacheTestCase

Hierarchy

Expanded class hierarchy of MemcacheTestCase

File

modules/memcache/tests/memcache.test, line 3

View source
class MemcacheTestCase extends DrupalWebTestCase {
  protected $profile = 'testing';
  protected $default_bin = 'cache_memcache';
  protected $default_cid = 'test_temporary';
  protected $default_value = 'MemcacheTest';
  function setUp() {
    parent::setUp(func_get_args());
    variable_set("cache_flush_{$this->default_bin}", 0);
    variable_set('cache_class_cache_memcache', 'MemcacheDrupal');
    $this
      ->resetVariables();
  }

  /**
   * Check whether or not a cache entry exists.
   *
   * @param $cid
   *   The cache id.
   * @param $var
   *   The variable the cache should contain.
   * @param $bin
   *   The bin the cache item was stored in.
   * @return
   *   TRUE on pass, FALSE on fail.
   */
  protected function checkCacheExists($cid, $var, $bin = NULL) {
    if ($bin == NULL) {
      $bin = $this->default_bin;
    }
    $cache = cache_get($cid, $bin);
    return isset($cache->data) && $cache->data == $var;
  }

  /**
   * Assert or a cache entry exists.
   *
   * @param $message
   *   Message to display.
   * @param $var
   *   The variable the cache should contain.
   * @param $cid
   *   The cache id.
   * @param $bin
   *   The bin the cache item was stored in.
   */
  protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) {
    if ($bin == NULL) {
      $bin = $this->default_bin;
    }
    if ($cid == NULL) {
      $cid = $this->default_cid;
    }
    if ($var == NULL) {
      $var = $this->default_value;
    }
    $this
      ->assertTrue($this
      ->checkCacheExists($cid, $var, $bin), $message);
  }

  /**
   * Assert or a cache entry has been removed.
   *
   * @param $message
   *   Message to display.
   * @param $cid
   *   The cache id.
   * @param $bin
   *   The bin the cache item was stored in.
   */
  function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
    if ($bin == NULL) {
      $bin = $this->default_bin;
    }
    if ($cid == NULL) {
      $cid = $this->default_cid;
    }
    $cache = cache_get($cid, $bin);
    $this
      ->assertFalse($cache, $message);
  }

  /**
   * Perform the general wipe.
   * @param $bin
   *   The bin to perform the wipe on.
   */
  protected function generalWipe($bin = NULL) {
    if ($bin == NULL) {
      $bin = $this->default_bin;
    }
    cache_clear_all(NULL, $bin);
  }
  function resetVariables() {
    _cache_get_object($this->default_bin)
      ->reloadVariables();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemcacheTestCase::$default_bin protected property
MemcacheTestCase::$default_cid protected property
MemcacheTestCase::$default_value protected property
MemcacheTestCase::$profile protected property
MemcacheTestCase::assertCacheExists protected function Assert or a cache entry exists.
MemcacheTestCase::assertCacheRemoved function Assert or a cache entry has been removed.
MemcacheTestCase::checkCacheExists protected function Check whether or not a cache entry exists.
MemcacheTestCase::generalWipe protected function Perform the general wipe.
MemcacheTestCase::resetVariables function
MemcacheTestCase::setUp function