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

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();
    variable_set("cache_flush_cache", 0);
  }

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

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

}

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.