PermanentRedisBackendTest.php in Permanent Cache Bin 8
File
modules/pcb_redis/tests/src/Kernel/PermanentRedisBackendTest.php
View source
<?php
namespace Drupal\Tests\pcb_redis\Kernel;
use Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase;
class PermanentRedisBackendTest extends GenericCacheBackendUnitTestBase {
public static $modules = [
'system',
'pcb',
'pcb_redis',
'redis',
];
protected function createCacheBackend($bin) {
$cache = \Drupal::service('cache.backend.permanent_redis')
->get($bin);
$cache
->setMinTtl(10);
return $cache;
}
public function testDeleteAll() {
$backend_a = $this
->getCacheBackend();
$backend_b = $this
->getCacheBackend('bootstrap');
$backend_a
->set('test1', 1, Cache::PERMANENT);
$backend_a
->set('test2', 3, time() + 1000);
$backend_b
->set('test3', 4, Cache::PERMANENT);
$backend_a
->deleteAll();
$this
->assertTrue($backend_a
->get('test1'), 'First key has been deleted.');
$this
->assertTrue($backend_a
->get('test2'), 'Second key has been deleted.');
$this
->assertTrue($backend_b
->get('test3'), 'Item in other bin is preserved.');
}
public function testSetGet() {
$backend = $this
->getCacheBackend();
$cid = 'test';
$cache_value = 'This does not matter.';
$this
->assertSame(FALSE, $backend
->get($cid), "Backend does not contain data for the used cache id.");
$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.');
$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.');
$backend
->deleteAllPermanent();
$cached = $backend
->get($cid);
$this
->assertFalse(is_object($cached), 'Backend returned result after the permanent cache was deleted.');
}
}