StorageReplaceDataWrapperTest.php 2.2 KB

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