View source
<?php
namespace Drupal\Tests\config_split\Kernel;
use Drupal\Core\Config\MemoryStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\config_filter\Kernel\ConfigStorageTestTrait;
class SplitMergeTest extends KernelTestBase {
use ConfigStorageTestTrait;
use SplitTestTrait;
public static $modules = [
'system',
'language',
'user',
'node',
'field',
'text',
'config',
'config_test',
'config_exclude_test',
'config_split',
'config_filter',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installConfig([
'system',
'field',
'config_test',
'config_exclude_test',
]);
ConfigurableLanguage::createFromLangcode('fr')
->save();
ConfigurableLanguage::createFromLangcode('de')
->save();
}
public function testSimpleSplitExport() {
$config = $this
->createSplitConfig('test_split', [
'folder' => Settings::get('file_public_path') . '/config/split',
'module' => [
'config_test' => 0,
],
]);
$active = $this
->getActiveStorage();
$expectedExport = new MemoryStorage();
$expectedSplit = new MemoryStorage();
foreach (array_merge($active
->getAllCollectionNames(), [
StorageInterface::DEFAULT_COLLECTION,
]) as $collection) {
$active = $active
->createCollection($collection);
$expectedExport = $expectedExport
->createCollection($collection);
$expectedSplit = $expectedSplit
->createCollection($collection);
foreach ($active
->listAll() as $name) {
$data = $active
->read($name);
if ($name === 'core.extension') {
unset($data['module']['config_test']);
}
if (strpos($name, 'config_test') !== FALSE || in_array($name, [
'system.menu.exclude_test',
'system.menu.indirect_exclude_test',
])) {
$expectedSplit
->write($name, $data);
}
else {
$expectedExport
->write($name, $data);
}
}
}
static::assertStorageEquals($expectedExport, $this
->getExportStorage());
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config));
$this
->copyConfig($expectedExport, $this
->getSyncFileStorage());
$this
->copyConfig($expectedSplit, $this
->getSplitSourceStorage($config));
static::assertStorageEquals($active, $this
->getImportStorage());
}
public function testCompleteAndConditionalSplitExport() {
$config = $this
->createSplitConfig('test_split', [
'folder' => Settings::get('file_public_path') . '/config/split',
'blacklist' => [
'config_test.types',
],
'graylist' => [
'config_test.system',
],
'graylist_skip_equal' => TRUE,
]);
$active = $this
->getActiveStorage();
$this
->copyConfig($active, $this
->getSyncFileStorage());
$originalSystem = $this
->config('config_test.system')
->getRawData();
$this
->config('config_test.system')
->set('foo', 'baz')
->save();
$expectedExport = new MemoryStorage();
$expectedSplit = new MemoryStorage();
foreach (array_merge($active
->getAllCollectionNames(), [
StorageInterface::DEFAULT_COLLECTION,
]) as $collection) {
$active = $active
->createCollection($collection);
$expectedExport = $expectedExport
->createCollection($collection);
$expectedSplit = $expectedSplit
->createCollection($collection);
foreach ($active
->listAll() as $name) {
$data = $active
->read($name);
if ($name === 'config_test.types') {
$expectedSplit
->write($name, $data);
}
elseif ($name === 'config_test.system') {
if ($collection === StorageInterface::DEFAULT_COLLECTION) {
$expectedSplit
->write($name, $data);
$expectedExport
->write($name, $originalSystem);
}
else {
$expectedExport
->write($name, $data);
}
}
else {
$expectedExport
->write($name, $data);
}
}
}
static::assertStorageEquals($expectedExport, $this
->getExportStorage());
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config));
$config
->set('blacklist', [
'config_test.system',
])
->set('graylist', [])
->save();
$expectedExport
->write($config
->getName(), $config
->getRawData());
$expectedExport
->write('config_test.types', $active
->read('config_test.types'));
$expectedSplit
->delete('config_test.types');
foreach (array_merge($active
->getAllCollectionNames(), [
StorageInterface::DEFAULT_COLLECTION,
]) as $collection) {
$active = $active
->createCollection($collection);
$expectedExport = $expectedExport
->createCollection($collection);
$expectedSplit = $expectedSplit
->createCollection($collection);
$expectedExport
->delete('config_test.system');
$expectedSplit
->write('config_test.system', $active
->read('config_test.system'));
}
static::assertStorageEquals($expectedExport, $this
->getExportStorage());
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config));
$this
->copyConfig($expectedExport, $this
->getSyncFileStorage());
$this
->copyConfig($expectedSplit, $this
->getSplitSourceStorage($config));
static::assertStorageEquals($active, $this
->getImportStorage());
}
public function testConditionalSplitWithModuleConfig() {
$config = $this
->createSplitConfig('test_split', [
'folder' => Settings::get('file_public_path') . '/config/split',
'module' => [
'config_test' => 0,
],
'graylist' => [
'config_test.system',
],
'graylist_skip_equal' => FALSE,
]);
$active = $this
->getActiveStorage();
$this
->copyConfig($active, $this
->getSyncFileStorage());
$originalSystem = $this
->config('config_test.system')
->getRawData();
$this
->config('config_test.system')
->set('foo', 'baz')
->save();
$expectedExport = new MemoryStorage();
$expectedSplit = new MemoryStorage();
foreach (array_merge($active
->getAllCollectionNames(), [
StorageInterface::DEFAULT_COLLECTION,
]) as $collection) {
$active = $active
->createCollection($collection);
$expectedExport = $expectedExport
->createCollection($collection);
$expectedSplit = $expectedSplit
->createCollection($collection);
foreach ($active
->listAll() as $name) {
$data = $active
->read($name);
if ($name === 'core.extension') {
unset($data['module']['config_test']);
}
if ($name === 'config_test.system') {
if ($collection === StorageInterface::DEFAULT_COLLECTION) {
$expectedSplit
->write($name, $data);
$expectedExport
->write($name, $originalSystem);
}
else {
$expectedSplit
->write($name, $data);
$expectedExport
->write($name, $data);
}
}
elseif (strpos($name, 'config_test') !== FALSE || in_array($name, [
'system.menu.exclude_test',
'system.menu.indirect_exclude_test',
])) {
$expectedSplit
->write($name, $data);
}
else {
$expectedExport
->write($name, $data);
}
}
}
static::assertStorageEquals($expectedExport, $this
->getExportStorage());
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config));
$this
->copyConfig($expectedExport, $this
->getSyncFileStorage());
$this
->copyConfig($expectedSplit, $this
->getSplitSourceStorage($config));
static::assertStorageEquals($active, $this
->getImportStorage());
}
public function testIncludeDependency() {
$config = $this
->createSplitConfig('test_split', [
'graylist' => [
'system.menu.exclude_test',
],
'graylist_dependents' => TRUE,
'graylist_skip_equal' => TRUE,
]);
$active = $this
->getActiveStorage();
$this
->copyConfig($active, $this
->getSyncFileStorage());
$originalSystem = $this
->config('system.menu.indirect_exclude_test')
->getRawData();
$this
->config('system.menu.indirect_exclude_test')
->set('label', 'Split Test')
->save();
$expectedExport = new MemoryStorage();
$expectedSplit = new MemoryStorage();
foreach (array_merge($active
->getAllCollectionNames(), [
StorageInterface::DEFAULT_COLLECTION,
]) as $collection) {
$active = $active
->createCollection($collection);
$expectedExport = $expectedExport
->createCollection($collection);
$expectedSplit = $expectedSplit
->createCollection($collection);
foreach ($active
->listAll() as $name) {
$data = $active
->read($name);
if ($name === 'system.menu.indirect_exclude_test') {
if ($collection === StorageInterface::DEFAULT_COLLECTION) {
$expectedSplit
->write($name, $data);
$expectedExport
->write($name, $originalSystem);
}
else {
$expectedExport
->write($name, $data);
}
}
else {
$expectedExport
->write($name, $data);
}
}
}
static::assertStorageEquals($expectedExport, $this
->getExportStorage());
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config));
$this
->copyConfig($expectedExport, $this
->getSyncFileStorage());
$this
->copyConfig($expectedSplit, $this
->getSplitSourceStorage($config));
static::assertStorageEquals($active, $this
->getImportStorage());
$config
->set('graylist_dependents', FALSE)
->save();
static::assertStorageEquals($active, $this
->getExportStorage());
static::assertStorageEquals(new MemoryStorage(), $this
->getSplitPreviewStorage($config));
}
}