You are here

public function PermanentRedisBackendTest::testSetGet in Permanent Cache Bin 8

Testing the basic goals of the permanent redis cache.

Overrides GenericCacheBackendUnitTestBase::testSetGet

File

modules/pcb_redis/tests/src/Kernel/PermanentRedisBackendTest.php, line 63

Class

PermanentRedisBackendTest
Tests the PermanentRedisBackendTest.

Namespace

Drupal\Tests\pcb_redis\Kernel

Code

public function testSetGet() {
  $backend = $this
    ->getCacheBackend();
  $cid = 'test';
  $cache_value = 'This does not matter.';

  // Be sure that our cache key is empty.
  $this
    ->assertSame(FALSE, $backend
    ->get($cid), "Backend does not contain data for the used cache id.");

  // Initialize the cache value.
  $backend
    ->set($cid, $cache_value);
  $cached = $backend
    ->get($cid);
  $this
    ->assertEquals($cache_value, $cached->data, 'Backend returned the proper value before the normal deleting process.');

  // This is the original cache deleteAll method, so we don't want to delete
  // anything at this moment.
  $backend
    ->deleteAll();
  $cached = $backend
    ->get($cid);
  $this
    ->assertFalse(!is_object($cached), 'Backend did not provide result after the normal deleting process.');
  $this
    ->assertEquals($cache_value, $cached->data, 'Backend returned the proper value after the normal deleting process.');

  // Now flush the permanent cache!
  $backend
    ->deleteAllPermanent();
  $cached = $backend
    ->get($cid);
  $this
    ->assertFalse(is_object($cached), 'Backend returned result after the permanent cache was deleted.');
}