public function SplitMergeTest::testCompleteAndConditionalSplitExport in Configuration Split 2.0.x
Same name and namespace in other branches
- 8 tests/src/Kernel/SplitMergeTest.php \Drupal\Tests\config_split\Kernel\SplitMergeTest::testCompleteAndConditionalSplitExport()
Test complete and conditional split export.
@dataProvider storageAlternativesProvider
File
- tests/
src/ Kernel/ SplitMergeTest.php, line 133
Class
- SplitMergeTest
- Test the splitting and merging.
Namespace
Drupal\Tests\config_split\KernelCode
public function testCompleteAndConditionalSplitExport($storage) {
$config = $this
->createSplitConfig('test_split', [
'storage' => $storage,
'complete_list' => [
'config_test.types',
],
'partial_list' => [
'config_test.system',
],
]);
$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();
$systemPatch = [
'added' => [
'foo' => 'bar',
],
'removed' => [
'foo' => 'baz',
],
];
$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('config_split.patch.' . $name, $systemPatch);
$expectedExport
->write($name, $originalSystem);
}
else {
$expectedExport
->write($name, $data);
}
}
else {
$expectedExport
->write($name, $data);
}
}
}
if ($storage === 'collection') {
$temp = new SplitCollectionStorage($expectedExport, $config
->get('id'));
self::replaceStorageContents($expectedSplit, $temp);
}
$export = $this
->getExportStorage();
static::assertStorageEquals($expectedExport, $export);
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config, $export));
// Change the config.
$config
->set('complete_list', [
'config_test.system',
])
->set('partial_list', [])
->save();
$active = $this
->getActiveStorage();
// Update expectations.
$expectedExport
->write($config
->getName(), $config
->getRawData());
$expectedExport
->write('config_test.types', $active
->read('config_test.types'));
$expectedSplit
->delete('config_test.types');
$expectedSplit
->delete('config_split.patch.config_test.system');
$expectedExport
->delete('config_test.system');
$expectedSplit
->write('config_test.system', $active
->read('config_test.system'));
// 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'));
}
if ($storage === 'collection') {
$temp = new SplitCollectionStorage($expectedExport, $config
->get('id'));
self::replaceStorageContents($expectedSplit, $temp);
}
$export = $this
->getExportStorage();
static::assertStorageEquals($expectedExport, $export);
static::assertStorageEquals($expectedSplit, $this
->getSplitPreviewStorage($config, $export));
// 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());
}