You are here

class MemCacheSavingCase in Memcache API and Integration 7

Same name in this branch
  1. 7 tests/memcache.test \MemCacheSavingCase
  2. 7 tests/memcache6.test \MemCacheSavingCase
Same name and namespace in other branches
  1. 6 tests/memcache.test \MemCacheSavingCase

Hierarchy

Expanded class hierarchy of MemCacheSavingCase

File

tests/memcache.test, line 250
Test cases for the memcache cache backend.

View source
class MemCacheSavingCase extends MemcacheTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Memcache saving test',
      'description' => 'Check our variables are saved and restored the right way.',
      'group' => 'Memcache',
    );
  }

  /**
   * @see MemcacheTestCase::setUp()
   */
  public function setUp() {
    parent::setUp();
  }

  /**
   * Test the saving and restoring of a string.
   */
  public function testString() {
    $this
      ->checkVariable($this
      ->randomName(100));
  }

  /**
   * Test the saving and restoring of an integer.
   */
  public function testInteger() {
    $this
      ->checkVariable(100);
  }

  /**
   * Test the saving and restoring of a double.
   */
  public function testDouble() {
    $this
      ->checkVariable(1.29);
  }

  /**
   * Test the saving and restoring of an array.
   */
  public function testArray() {
    $this
      ->checkVariable(array(
      'drupal1',
      'drupal2' => 'drupal3',
      'drupal4' => array(
        'drupal5',
        'drupal6',
      ),
    ));
  }

  /**
   * Test the saving and restoring of an object.
   */
  public function testObject() {
    $test_object = new stdClass();
    $test_object->test1 = $this
      ->randomName(100);
    $test_object->test2 = 100;
    $test_object->test3 = array(
      'drupal1',
      'drupal2' => 'drupal3',
      'drupal4' => array(
        'drupal5',
        'drupal6',
      ),
    );
    cache_set('test_object', $test_object, $this->default_bin);
    $cache = cache_get('test_object', $this->default_bin);
    $this
      ->assertTrue(isset($cache->data) && $cache->data == $test_object, t('Object is saved and restored properly.'));
  }

  /**
   * Test save and restoring a string with a long key.
   */
  public function testStringLongKey() {
    $this
      ->checkVariable($this
      ->randomName(100), 'ThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydog');
  }

  /**
   * Test save and restoring a string using a key with special characters.
   */
  public function testStringSpecialKey() {
    $this
      ->checkVariable($this
      ->randomName(100), 'Qwerty!@#$%^&*()_+-=[]\\;\',./<>?:"{}|£¢');
  }

  /**
   * Test saving and restoring an integer value directly with dmemcache_set().
   */
  function testIntegerValue() {
    $key = $this
      ->randomName(100);
    $val = rand(1, 1000);
    dmemcache_set($key, $val, 0, 'cache');
    $cache = dmemcache_get($key, 'cache');
    $this
      ->assertTrue($val === $cache, t('Integer is saved and restored properly with key @key', array(
      '@key' => $key,
    )));
  }

  /**
   * Test saving and restoring a very large value (>1MiB).
   */
  function testLargeValue() {
    $this
      ->checkVariable(array_fill(0, 500000, rand()));
  }

  /**
   * Test save and restoring a string with a long key and a very large value.
   */
  function testLongKeyLargeValue() {
    $this
      ->checkVariable(array_fill(0, 500000, rand()), $this
      ->randomName(300));
  }

  /**
   * Check or a variable is stored and restored properly.
   */
  public function checkVariable($var, $key = 'test_var') {
    cache_set($key, $var, $this->default_bin);
    $cache = cache_get($key, $this->default_bin);
    $this
      ->assertTrue(isset($cache->data) && $cache->data === $var, t('@type is saved and restored properly!key.', array(
      '@type' => ucfirst(gettype($var)),
      '!key' => $key != 'test_var' ? t(' with key @key', array(
        '@key' => $key,
      )) : '',
    )));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemCacheSavingCase::checkVariable public function Check or a variable is stored and restored properly.
MemCacheSavingCase::getInfo public static function
MemCacheSavingCase::setUp public function
MemCacheSavingCase::testArray public function Test the saving and restoring of an array.
MemCacheSavingCase::testDouble public function Test the saving and restoring of a double.
MemCacheSavingCase::testInteger public function Test the saving and restoring of an integer.
MemCacheSavingCase::testIntegerValue function Test saving and restoring an integer value directly with dmemcache_set().
MemCacheSavingCase::testLargeValue function Test saving and restoring a very large value (>1MiB).
MemCacheSavingCase::testLongKeyLargeValue function Test save and restoring a string with a long key and a very large value.
MemCacheSavingCase::testObject public function Test the saving and restoring of an object.
MemCacheSavingCase::testString public function Test the saving and restoring of a string.
MemCacheSavingCase::testStringLongKey public function Test save and restoring a string with a long key.
MemCacheSavingCase::testStringSpecialKey public function Test save and restoring a string using a key with special characters.