View source
<?php
namespace Drupal\Tests\config_split\Kernel;
use Drupal\config_split\Config\SplitCollectionStorage;
use Drupal\Core\Config\NullStorage;
use Drupal\KernelTests\Core\Config\Storage\MemoryStorageTest;
class SplitCollectionStorageTest extends MemoryStorageTest {
protected $inner;
protected function setUp() : void {
parent::setUp();
$this->inner = $this->storage;
$this->storage = new SplitCollectionStorage($this->inner, 'graft');
$this->storage
->write('system.performance', []);
}
public function testGraft() {
$this
->copyConfig(new NullStorage(), $this->inner);
$this->inner
->write('inner', [
'test data',
]);
$this->inner
->createCollection('collection')
->write('collection', [
'collection data',
]);
$collection = $this->storage
->createCollection('test');
$collection
->write('random', [
'more',
]);
$this
->copyConfig($this->inner, $this->storage);
self::assertEquals([
'inner',
], $this->storage
->listAll());
self::assertEquals([
'collection',
], $this->storage
->getAllCollectionNames());
self::assertEquals([
'test data',
], $this->storage
->read('inner'));
self::assertEquals([
'collection data',
], $this->storage
->createCollection('collection')
->read('collection'));
self::assertEquals([
'collection',
'split.graft',
'split.graft.collection',
], $this->inner
->getAllCollectionNames());
$collection
->write('graft', [
'grafted',
]);
self::assertEquals([
'collection',
'split.graft',
'split.graft.collection',
'split.graft.test',
], $this->inner
->getAllCollectionNames());
self::assertEquals([
'grafted',
], $this->inner
->createCollection('split.graft.test')
->read('graft'));
}
public function testSiblings() {
$sibling = new SplitCollectionStorage($this->inner, 'sibling');
$this
->copyConfig(new NullStorage(), $this->inner);
$this->inner
->write('inner', [
'test data',
]);
$this->inner
->createCollection('collection')
->write('collection', [
'collection data',
]);
$this
->copyConfig($this->inner, $this->storage);
$this
->copyConfig($this->inner, $sibling);
$this
->copyConfig($this->inner, $this->storage);
self::assertEquals([
'inner',
], $this->storage
->listAll());
self::assertEquals([
'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',
], $sibling
->listAll());
self::assertEquals([
'collection',
], $sibling
->getAllCollectionNames());
self::assertEquals([
'test data',
], $sibling
->read('inner'));
self::assertEquals([
'collection data',
], $sibling
->createCollection('collection')
->read('collection'));
self::assertEquals([
'collection',
'split.graft',
'split.graft.collection',
'split.sibling',
'split.sibling.collection',
], $this->inner
->getAllCollectionNames());
}
public function testCousins() {
$cousin = new TestSplitCollectionStorage($this->inner, 'cousin');
$this
->copyConfig(new NullStorage(), $this->inner);
$this->inner
->write('inner', [
'test data',
]);
$this->inner
->createCollection('collection')
->write('collection', [
'collection data',
]);
$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());
$this
->copyConfig($this->inner, $this->storage);
$this
->copyConfig($this->inner, $cousin);
self::assertEquals($all, $this->inner
->getAllCollectionNames());
}
}
class TestSplitCollectionStorage extends SplitCollectionStorage {
const PREFIX = 'test.';
}