Version 1
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / Storage / StorageReplaceDataWrapperTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Config\Storage;
4
5 use Drupal\config\StorageReplaceDataWrapper;
6 use Drupal\Core\Config\StorageInterface;
7
8 /**
9  * Tests StorageReplaceDataWrapper operations.
10  *
11  * @group config
12  */
13 class StorageReplaceDataWrapperTest extends ConfigStorageTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setUp() {
19     parent::setUp();
20     $this->storage = new StorageReplaceDataWrapper($this->container->get('config.storage'));
21     // ::listAll() verifications require other configuration data to exist.
22     $this->storage->write('system.performance', []);
23     $this->storage->replaceData('system.performance', ['foo' => 'bar']);
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function read($name) {
30     return $this->storage->read($name);
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function insert($name, $data) {
37     $this->storage->write($name, $data);
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   protected function update($name, $data) {
44     $this->storage->write($name, $data);
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   protected function delete($name) {
51     $this->storage->delete($name);
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function testInvalidStorage() {
58     // No-op as this test does not make sense.
59   }
60
61   /**
62    * Tests if new collections created correctly.
63    *
64    * @param string $collection
65    *   The collection name.
66    *
67    * @dataProvider providerCollections
68    */
69   public function testCreateCollection($collection) {
70     $initial_collection_name = $this->storage->getCollectionName();
71
72     // Create new storage with given collection and check it is set correctly.
73     $new_storage = $this->storage->createCollection($collection);
74     $this->assertSame($collection, $new_storage->getCollectionName());
75
76     // Check collection not changed in the current storage instance.
77     $this->assertSame($initial_collection_name, $this->storage->getCollectionName());
78   }
79
80   /**
81    * Data provider for testing different collections.
82    *
83    * @return array
84    *   Returns an array of collection names.
85    */
86   public function providerCollections() {
87     return [
88       [StorageInterface::DEFAULT_COLLECTION],
89       ['foo.bar'],
90     ];
91   }
92
93 }