You are here

abstract class Redis_Tests_Cache_FlushUnitTestCase in Redis 7.3

Hierarchy

Expanded class hierarchy of Redis_Tests_Cache_FlushUnitTestCase

2 string references to 'Redis_Tests_Cache_FlushUnitTestCase'
CompressedPhpRedisFlushUnitTestCase.test in lib/Redis/Tests/Cache/CompressedPhpRedisFlushUnitTestCase.test
PhpRedisFlushUnitTestCase.test in lib/Redis/Tests/Cache/PhpRedisFlushUnitTestCase.test

File

lib/Redis/Tests/Cache/FlushUnitTestCase.php, line 3

View source
abstract class Redis_Tests_Cache_FlushUnitTestCase extends Redis_Tests_AbstractUnitTestCase {

  /**
   * @var Cache bin identifier
   */
  private static $id = 1;
  protected function createCacheInstance($name = null) {
    return new Redis_Cache($name);
  }

  /**
   * Get cache backend
   *
   * @return Redis_Cache
   */
  protected final function getBackend($name = null) {
    if (null === $name) {

      // This is needed to avoid conflict between tests, each test
      // seems to use the same Redis namespace and conflicts are
      // possible.
      $name = 'cache' . self::$id++;
    }
    $backend = $this
      ->createCacheInstance($name);
    $this
      ->assert(true, "Redis client is " . ($backend
      ->isSharded() ? '' : "NOT ") . " sharded");
    $this
      ->assert(true, "Redis client is " . ($backend
      ->allowTemporaryFlush() ? '' : "NOT ") . " allowed to flush temporary entries");
    $this
      ->assert(true, "Redis client is " . ($backend
      ->allowPipeline() ? '' : "NOT ") . " allowed to use pipeline");
    return $backend;
  }

  /**
   * Tests that with a default cache lifetime temporary non expired
   * items are kept even when in temporary flush mode.
   */
  public function testFlushIsTemporaryWithLifetime() {
    $GLOBALS['conf']['cache_lifetime'] = 112;
    $backend = $this
      ->getBackend();

    // Even though we set a flush mode into this bin, Drupal default
    // behavior when a cache_lifetime is set is to override the backend
    // one in order to keep the core behavior and avoid potential
    // nasty bugs.
    $this
      ->assertFalse($backend
      ->allowTemporaryFlush());
    $backend
      ->set('test7', 42, CACHE_PERMANENT);
    $backend
      ->set('test8', 'foo', CACHE_TEMPORARY);
    $backend
      ->set('test9', 'bar', time() + 1000);
    $backend
      ->clear();
    $cache = $backend
      ->get('test7');
    $this
      ->assertNotEqual(false, $cache);
    $this
      ->assertEqual($cache->data, 42);
    $cache = $backend
      ->get('test8');
    $this
      ->assertNotEqual(false, $cache);
    $this
      ->assertEqual($cache->data, 'foo');
    $cache = $backend
      ->get('test9');
    $this
      ->assertNotEqual(false, $cache);
    $this
      ->assertEqual($cache->data, 'bar');
  }

  /**
   * Tests that with no default cache lifetime all temporary items are
   * droppped when in temporary flush mode.
   */
  public function testFlushIsTemporaryWithoutLifetime() {
    $backend = $this
      ->getBackend();
    $this
      ->assertTrue($backend
      ->allowTemporaryFlush());
    $backend
      ->set('test10', 42, CACHE_PERMANENT);

    // Ugly concatenation with the mode, but it will be visible in tests
    // reports if the entry shows up, thus allowing us to know which real
    // test case is run at this time
    $backend
      ->set('test11', 'foo' . $backend
      ->isSharded(), CACHE_TEMPORARY);
    $backend
      ->set('test12', 'bar' . $backend
      ->isSharded(), time() + 10);
    $backend
      ->clear();
    $cache = $backend
      ->get('test10');
    $this
      ->assertNotEqual(false, $cache);
    $this
      ->assertEqual($cache->data, 42);
    $this
      ->assertFalse($backend
      ->get('test11'));
    $cache = $backend
      ->get('test12');
    $this
      ->assertNotEqual(false, $cache);
  }
  public function testNormalFlushing() {
    $backend = $this
      ->getBackend();
    $backendUntouched = $this
      ->getBackend();

    // Set a few entries.
    $backend
      ->set('test13', 'foo');
    $backend
      ->set('test14', 'bar', CACHE_TEMPORARY);
    $backend
      ->set('test15', 'baz', time() + 3);
    $backendUntouched
      ->set('test16', 'dog');
    $backendUntouched
      ->set('test17', 'cat', CACHE_TEMPORARY);
    $backendUntouched
      ->set('test18', 'xor', time() + 5);

    // This should not do anything (bugguy command)
    $backend
      ->clear('', true);
    $backend
      ->clear('', false);
    $this
      ->assertNotIdentical(false, $backend
      ->get('test13'));
    $this
      ->assertNotIdentical(false, $backend
      ->get('test14'));
    $this
      ->assertNotIdentical(false, $backend
      ->get('test15'));
    $this
      ->assertNotIdentical(false, $backendUntouched
      ->get('test16'));
    $this
      ->assertNotIdentical(false, $backendUntouched
      ->get('test17'));
    $this
      ->assertNotIdentical(false, $backendUntouched
      ->get('test18'));

    // This should clear every one, permanent and volatile
    $backend
      ->clear('*', true);
    $this
      ->assertFalse($backend
      ->get('test13'));
    $this
      ->assertFalse($backend
      ->get('test14'));
    $this
      ->assertFalse($backend
      ->get('test15'));
    $this
      ->assertNotIdentical(false, $backendUntouched
      ->get('test16'));
    $this
      ->assertNotIdentical(false, $backendUntouched
      ->get('test17'));
    $this
      ->assertNotIdentical(false, $backendUntouched
      ->get('test18'));
  }
  public function testPrefixDeletionWithSeparatorChar() {
    $backend = $this
      ->getBackend();
    $backend
      ->set('testprefix10', 'foo');
    $backend
      ->set('testprefix11', 'foo');
    $backend
      ->set('testprefix:12', 'bar');
    $backend
      ->set('testprefix:13', 'baz');
    $backend
      ->set('testnoprefix14', 'giraffe');
    $backend
      ->set('testnoprefix:15', 'elephant');
    $backend
      ->clear('testprefix:', true);
    $this
      ->assertFalse($backend
      ->get('testprefix:12'));
    $this
      ->assertFalse($backend
      ->get('testprefix:13'));

    // @todo Temporary fix
    // At the moment shard enabled backends will erase all data instead
    // of just removing by prefix, so those tests won't pass
    if (!$backend
      ->isSharded()) {
      $this
        ->assertNotIdentical(false, $backend
        ->get('testprefix10'));
      $this
        ->assertNotIdentical(false, $backend
        ->get('testprefix11'));
      $this
        ->assertNotIdentical(false, $backend
        ->get('testnoprefix14'));
      $this
        ->assertNotIdentical(false, $backend
        ->get('testnoprefix:15'));
    }
    $backend
      ->clear('testprefix', true);
    $this
      ->assertFalse($backend
      ->get('testprefix10'));
    $this
      ->assertFalse($backend
      ->get('testprefix11'));

    // @todo Temporary fix
    // At the moment shard enabled backends will erase all data instead
    // of just removing by prefix, so those tests won't pass
    if (!$backend
      ->isSharded()) {
      $this
        ->assertNotIdentical(false, $backend
        ->get('testnoprefix14'));
      $this
        ->assertNotIdentical(false, $backend
        ->get('testnoprefix:15'));
    }
  }
  public function testOrder() {
    $backend = $this
      ->getBackend();
    for ($i = 0; $i < 10; ++$i) {
      $id = 'speedtest' . $i;
      $backend
        ->set($id, 'somevalue');
      $this
        ->assertNotIdentical(false, $backend
        ->get($id));
      $backend
        ->clear('*', true);

      // Value created the same second before is dropped
      $this
        ->assertFalse($backend
        ->get($id));
      $backend
        ->set($id, 'somevalue');

      // Value created the same second after is kept
      $this
        ->assertNotIdentical(false, $backend
        ->get($id));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct
Redis_Tests_AbstractUnitTestCase::$loaderEnabled protected static property
Redis_Tests_AbstractUnitTestCase::$originalConf private property Drupal $conf array backup
Redis_Tests_AbstractUnitTestCase::enableAutoload protected static function Enable the autoloader
Redis_Tests_AbstractUnitTestCase::getClientInterface abstract protected function Set up the Redis configuration. 21
Redis_Tests_AbstractUnitTestCase::prepareClientManager final private function Prepare client manager
Redis_Tests_AbstractUnitTestCase::prepareDrupalEnvironment final private function Prepare Drupal environmment for testing
Redis_Tests_AbstractUnitTestCase::restoreClientManager final private function Restore client manager
Redis_Tests_AbstractUnitTestCase::restoreDrupalEnvironment final private function Restore Drupal environment after testing.
Redis_Tests_AbstractUnitTestCase::setUp public function Sets up unit test environment. Overrides DrupalUnitTestCase::setUp 1
Redis_Tests_AbstractUnitTestCase::tearDown public function Overrides DrupalUnitTestCase::tearDown 2
Redis_Tests_Cache_FlushUnitTestCase::$id private static property
Redis_Tests_Cache_FlushUnitTestCase::createCacheInstance protected function 2
Redis_Tests_Cache_FlushUnitTestCase::getBackend final protected function Get cache backend
Redis_Tests_Cache_FlushUnitTestCase::testFlushIsTemporaryWithLifetime public function Tests that with a default cache lifetime temporary non expired items are kept even when in temporary flush mode.
Redis_Tests_Cache_FlushUnitTestCase::testFlushIsTemporaryWithoutLifetime public function Tests that with no default cache lifetime all temporary items are droppped when in temporary flush mode.
Redis_Tests_Cache_FlushUnitTestCase::testNormalFlushing public function
Redis_Tests_Cache_FlushUnitTestCase::testOrder public function
Redis_Tests_Cache_FlushUnitTestCase::testPrefixDeletionWithSeparatorChar public function