You are here

public function PermanentDatabaseBackendTest::testSetGet in Permanent Cache Bin 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/PermanentDatabaseBackendTest.php \Drupal\Tests\pcb\Kernel\PermanentDatabaseBackendTest::testSetGet()

Testing the basic goals of the permanent cache.

Overrides GenericCacheBackendUnitTestBase::testSetGet

File

tests/src/Kernel/PermanentDatabaseBackendTest.php, line 59

Class

PermanentDatabaseBackendTest
Tests the PermanentDatabaseBackendTest.

Namespace

Drupal\Tests\pcb\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.');
}