You are here

public function SplitCollectionStorageTest::testCousins in Configuration Split 2.0.x

Test grafting storages that use different prefixes but same concept.

This test simulates using config_split together with the planned core module config_environment. It will not use the same code but likely do its transformations with the same effect.

File

tests/src/Kernel/SplitCollectionStorageTest.php, line 103

Class

SplitCollectionStorageTest
Test the SplitCollectionStorage.

Namespace

Drupal\Tests\config_split\Kernel

Code

public function testCousins() {
  $cousin = new TestSplitCollectionStorage($this->inner, 'cousin');

  // Empty out all of the underlying storage.
  $this
    ->copyConfig(new NullStorage(), $this->inner);

  // Add some data.
  $this->inner
    ->write('inner', [
    'test data',
  ]);
  $this->inner
    ->createCollection('collection')
    ->write('collection', [
    'collection data',
  ]);

  // Do a couple of copies to make sure all collections are created.
  $this
    ->copyConfig($this->inner, $this->storage);
  $this
    ->copyConfig($this->inner, $cousin);
  $this
    ->copyConfig($this->inner, $this->storage);
  $this
    ->copyConfig($this->inner, $cousin);
  self::assertEquals([
    'inner',
  ], $this->storage
    ->listAll());
  self::assertEquals([
    'collection',
    'test.cousin',
    'test.cousin.collection',
  ], $this->storage
    ->getAllCollectionNames());
  self::assertEquals([
    'test data',
  ], $this->storage
    ->read('inner'));
  self::assertEquals([
    'collection data',
  ], $this->storage
    ->createCollection('collection')
    ->read('collection'));
  self::assertEquals([
    'inner',
  ], $cousin
    ->listAll());
  self::assertEquals([
    'collection',
    'split.graft',
    'split.graft.collection',
  ], $cousin
    ->getAllCollectionNames());
  self::assertEquals([
    'test data',
  ], $cousin
    ->read('inner'));
  self::assertEquals([
    'collection data',
  ], $cousin
    ->createCollection('collection')
    ->read('collection'));
  $all = [
    'collection',
    'split.graft',
    'split.graft.collection',
    'split.graft.test.cousin',
    'split.graft.test.cousin.collection',
    'test.cousin',
    'test.cousin.collection',
    'test.cousin.split.graft',
    'test.cousin.split.graft.collection',
  ];
  self::assertEquals($all, $this->inner
    ->getAllCollectionNames());

  // Further copying collections will not create new ones.
  $this
    ->copyConfig($this->inner, $this->storage);
  $this
    ->copyConfig($this->inner, $cousin);
  self::assertEquals($all, $this->inner
    ->getAllCollectionNames());
}