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/memcache6.test, line 3

View source
class MemcacheTestCase extends DrupalWebTestCase {
  protected $default_bin = 'cache';
  protected $default_cid = 'test_temporary';
  protected $default_value = 'MemcacheTest';
  function setUp() {
    parent::setUp();
  }

  /**
   * 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);
  }

  /**
   * Setup the lifetime settings for caching.
   *
   * @param $time
   *   The time in seconds the cache should minimal live.
   */
  protected function setupLifetime($time) {
    variable_set('cache_lifetime', $time);
    variable_set('cache_flush', 0);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemcacheTestCase::$default_bin protected property
MemcacheTestCase::$default_cid protected property
MemcacheTestCase::$default_value 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::setUp function
MemcacheTestCase::setupLifetime protected function Setup the lifetime settings for caching.