3 namespace Drupal\KernelTests\Core\Cache;
5 use Drupal\Core\Cache\DatabaseBackend;
8 * Unit test of the database backend using the generic cache unit test base.
12 class DatabaseBackendTest extends GenericCacheBackendUnitTestBase {
19 public static $modules = ['system'];
22 * Creates a new instance of DatabaseBackend.
25 * A new DatabaseBackend object.
27 protected function createCacheBackend($bin) {
28 return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags.invalidator.checksum'), $bin);
34 public function testSetGet() {
36 $backend = $this->getCacheBackend();
38 // Set up a cache ID that is not ASCII and longer than 255 characters so we
39 // can test cache ID normalization.
40 $cid_long = str_repeat('愛€', 500);
41 $cached_value_long = $this->randomMachineName();
42 $backend->set($cid_long, $cached_value_long);
43 $this->assertIdentical($cached_value_long, $backend->get($cid_long)->data, "Backend contains the correct value for long, non-ASCII cache id.");
46 $cached_value_short = $this->randomMachineName();
47 $backend->set($cid_short, $cached_value_short);
48 $this->assertIdentical($cached_value_short, $backend->get($cid_short)->data, "Backend contains the correct value for short, non-ASCII cache id.");