de8bbda55396e64edd326b18ccad3a40992fccfa
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Cache / DatabaseBackendTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Cache;
4
5 use Drupal\Core\Cache\DatabaseBackend;
6
7 /**
8  * Unit test of the database backend using the generic cache unit test base.
9  *
10  * @group Cache
11  */
12 class DatabaseBackendTest extends GenericCacheBackendUnitTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['system'];
20
21   /**
22    * Creates a new instance of DatabaseBackend.
23    *
24    * @return
25    *   A new DatabaseBackend object.
26    */
27   protected function createCacheBackend($bin) {
28     return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags.invalidator.checksum'), $bin);
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function testSetGet() {
35     parent::testSetGet();
36     $backend = $this->getCacheBackend();
37
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.");
44
45     $cid_short = '愛1€';
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.");
49   }
50
51 }