Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / Storage / CachedStorageTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Config\Storage;
4
5 use Drupal\Core\Config\FileStorage;
6 use Drupal\Core\Config\CachedStorage;
7 use Drupal\Core\DependencyInjection\ContainerBuilder;
8 use Drupal\Core\StreamWrapper\PublicStream;
9 use Symfony\Component\DependencyInjection\Reference;
10
11 /**
12  * Tests CachedStorage operations.
13  *
14  * @group config
15  */
16 class CachedStorageTest extends ConfigStorageTestBase {
17
18   /**
19    * The cache backend the cached storage is using.
20    *
21    * @var \Drupal\Core\Cache\CacheBackendInterface
22    */
23   protected $cache;
24
25   /**
26    * The file storage the cached storage is using.
27    *
28    * @var \Drupal\Core\Config\FileStorage
29    */
30   protected $fileStorage;
31
32   protected function setUp() {
33     parent::setUp();
34     // Create a directory.
35     $dir = PublicStream::basePath() . '/config';
36     $this->fileStorage = new FileStorage($dir);
37     $this->storage = new CachedStorage($this->fileStorage, \Drupal::service('cache.config'));
38     $this->cache = \Drupal::service('cache_factory')->get('config');
39     // ::listAll() verifications require other configuration data to exist.
40     $this->storage->write('system.performance', []);
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function testInvalidStorage() {
47     // No-op as this test does not make sense.
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   protected function read($name) {
54     $data = $this->cache->get($name);
55     // Cache misses fall through to the underlying storage.
56     return $data ? $data->data : $this->fileStorage->read($name);
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   protected function insert($name, $data) {
63     $this->fileStorage->write($name, $data);
64     $this->cache->set($name, $data);
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   protected function update($name, $data) {
71     $this->fileStorage->write($name, $data);
72     $this->cache->set($name, $data);
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   protected function delete($name) {
79     $this->cache->delete($name);
80     unlink($this->fileStorage->getFilePath($name));
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function containerBuild(ContainerBuilder $container) {
87     parent::containerBuild($container);
88     // Use the regular database cache backend to aid testing.
89     $container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory')
90       ->addArgument(new Reference('database'))
91       ->addArgument(new Reference('cache_tags.invalidator.checksum'));
92   }
93
94 }