public function SplitMergeTest::testCompleteAndConditionalSplitExport in Configuration Split 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/SplitMergeTest.php \Drupal\Tests\config_split\Kernel\SplitMergeTest::testCompleteAndConditionalSplitExport()
Test complete and conditional split export.
File
- tests/
src/ Kernel/ SplitMergeTest.php, line 112
Class
- SplitMergeTest
- Test the splitting and merging.
Namespace
Drupal\Tests\config_split\KernelCode
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();
// Export the configuration to sync without filtering.
$this
->copyConfig($active, $this
->getSyncFileStorage());
// Change the gray listed config to see if it is exported the same.
$originalSystem = $this
->config('config_test.system')
->getRawData();
$this
->config('config_test.system')
->set('foo', 'baz')
->save();
$expectedExport = new MemoryStorage();
$expectedSplit = new MemoryStorage();
// Set up the expected data.
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') {
// We only changed the config in the default collection.
if ($collection === StorageInterface::DEFAULT_COLLECTION) {
$expectedSplit
->write($name, $data);
$expectedExport
->write($name, $originalSystem);
}
else {
// The option "skip equal" is false, write to export only.
$expectedExport
->write($name, $data);
}
}
else {
$expectedExport
->write($name, $data);
}
}
}
static::assertStorageEquals($expectedExport, $this
->getExportStorage());
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config));
// Change the config.
$config
->set('blacklist', [
'config_test.system',
])
->set('graylist', [])
->save();
// Update expectations.
$expectedExport
->write($config
->getName(), $config
->getRawData());
$expectedExport
->write('config_test.types', $active
->read('config_test.types'));
$expectedSplit
->delete('config_test.types');
// Update multilingual expectations.
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));
// Write the export to the file system and assert the import to work.
$this
->copyConfig($expectedExport, $this
->getSyncFileStorage());
$this
->copyConfig($expectedSplit, $this
->getSplitSourceStorage($config));
static::assertStorageEquals($active, $this
->getImportStorage());
}