You are here

class MemCacheSavingCase in Zircon Profile 8

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

Hierarchy

Expanded class hierarchy of MemCacheSavingCase

File

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

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',
    );
  }
  function setUp() {
    parent::setUp();
  }

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

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

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

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

  /**
   * Test the saving and restoring of an object.
   */
  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, 'cache');
    $cache = cache_get('test_object', 'cache');
    $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.
   */
  function testStringLongKey() {
    $this
      ->checkVariable($this
      ->randomName(100), 'ThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydogThequickbrownfoxjumpsoverthelazydog');
  }

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

  /*
   * Check or a variable is stored and restored properly.
   **/
  function checkVariable($var, $key = 'test_var') {
    cache_set($key, $var, 'cache');
    $cache = cache_get($key, 'cache');
    $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 function
MemCacheSavingCase::getInfo public static function
MemCacheSavingCase::setUp function
MemCacheSavingCase::testArray function Test the saving and restoring of an array.
MemCacheSavingCase::testDouble function Test the saving and restoring of a double.
MemCacheSavingCase::testInteger function Test the saving and restoring of an integer.
MemCacheSavingCase::testObject function Test the saving and restoring of an object.
MemCacheSavingCase::testString function Test the saving and restoring of a string.
MemCacheSavingCase::testStringLongKey function Test save and restoring a string with a long key.
MemCacheSavingCase::testStringSpecialKey function Test save and restoring a string using a key with special characters.