You are here

public function Redis_Tests_Cache_AbstractFixesUnitTestCase::testTemporaryCacheExpire in Redis 7.2

File

lib/Redis/Tests/Cache/AbstractFixesUnitTestCase.php, line 8

Class

Redis_Tests_Cache_AbstractFixesUnitTestCase
Bugfixes made over time test class.

Code

public function testTemporaryCacheExpire() {
  global $conf;

  // We are in unit tests so variable table does not exist.
  $backend = $this
    ->getBackend();

  // Permanent entry.
  $backend
    ->set('test1', 'foo', CACHE_PERMANENT);
  $data = $backend
    ->get('test1');
  $this
    ->assertNotEqual(false, $data);
  $this
    ->assertIdentical('foo', $data->data);

  // Permanent entries should not be dropped on clear() call.
  $backend
    ->clear();
  $data = $backend
    ->get('test1');
  $this
    ->assertNotEqual(false, $data);
  $this
    ->assertIdentical('foo', $data->data);

  // Expiring entry with permanent default lifetime.
  $conf['cache_lifetime'] = 0;
  $backend
    ->set('test2', 'bar', CACHE_TEMPORARY);
  sleep(2);
  $data = $backend
    ->get('test2');
  $this
    ->assertNotEqual(false, $data);
  $this
    ->assertIdentical('bar', $data->data);
  sleep(2);
  $data = $backend
    ->get('test2');
  $this
    ->assertNotEqual(false, $data);
  $this
    ->assertIdentical('bar', $data->data);

  // Expiring entry with negative lifetime.
  $backend
    ->set('test3', 'baz', time() - 100);
  $data = $backend
    ->get('test3');
  $this
    ->assertEqual(false, $data);

  // Expiring entry with short lifetime.
  $backend
    ->set('test4', 'foobar', time() + 2);
  $data = $backend
    ->get('test4');
  $this
    ->assertNotEqual(false, $data);
  $this
    ->assertIdentical('foobar', $data->data);
  sleep(3);
  $data = $backend
    ->get('test4');
  $this
    ->assertEqual(false, $data);

  // Expiring entry with short default lifetime.
  $conf['cache_lifetime'] = 2;
  $backend
    ->set('test5', 'foobaz', CACHE_TEMPORARY);
  $data = $backend
    ->get('test5');
  $this
    ->assertNotEqual(false, $data);
  $this
    ->assertIdentical('foobaz', $data->data);
  sleep(3);
  $data = $backend
    ->get('test5');
  $this
    ->assertEqual(false, $data);
}