public function ConfigSplitCliServiceTest::testSimpleSplitExport in Configuration Split 8
Test a simple export split.
File
- tests/
src/ Kernel/ ConfigSplitCliServiceTest.php, line 105
Class
- ConfigSplitCliServiceTest
- Test the cli service.
Namespace
Drupal\Tests\config_split\KernelCode
public function testSimpleSplitExport() {
// Set the split stream up.
$split = vfsStream::setup('split');
$split_root = vfsStreamWrapper::getRoot();
$primary = new FileStorage($split
->url() . '/sync');
$config = new Config('config_split.config_split.test_split', $this->container
->get('config.storage'), $this->container
->get('event_dispatcher'), $this->container
->get('config.typed'));
$config
->initWithData([
'id' => 'test_split',
'folder' => $split
->url() . '/split',
'module' => [
'config_test' => 0,
],
'theme' => [],
'blacklist' => [],
'graylist' => [],
])
->save();
// Export the configuration the way Drupal core does.
$vanilla = vfsStream::setup('vanilla');
vfsStreamWrapper::getRoot();
$vanilla_primary = new FileStorage($vanilla
->url());
$this->container
->get('config_split.cli')
->export($vanilla_primary);
vfsStreamWrapper::setRoot($split_root);
// Export the configuration without the test configuration.
$filter = $this->container
->get('plugin.manager.config_filter')
->getFilterInstance('config_split:test_split');
$storage = new FilteredStorage($primary, [
$filter,
]);
$this->container
->get('config_split.cli')
->export($storage);
// Extract the configuration for easier comparison.
$vanilla_config = [];
foreach ($vanilla
->getChildren() as $child) {
if ($child
->getType() == vfsStreamContent::TYPE_FILE && $child
->getName() != '.htaccess') {
$vanilla_config[$child
->getName()] = $child
->getContent();
}
}
$sync_config = [];
foreach ($split
->getChild('sync')
->getChildren() as $child) {
if ($child
->getType() == vfsStreamContent::TYPE_FILE && $child
->getName() != '.htaccess') {
$sync_config[$child
->getName()] = $child
->getContent();
}
}
$split_config = [];
foreach ($split
->getChild('split')
->getChildren() as $child) {
if ($child
->getType() == vfsStreamContent::TYPE_FILE && $child
->getName() != '.htaccess') {
$split_config[$child
->getName()] = $child
->getContent();
}
}
$this
->assertNotEmpty($split_config, 'There is split off configuration.');
$this
->assertEquals(count($vanilla_config), count($sync_config) + count($split_config), 'All the config is still here.');
foreach ($vanilla_config as $name => $content) {
if ($name == 'core.extension.yml') {
continue;
}
// All the filtered test config has config_test in its name.
if (strpos($name, 'config_test') === FALSE) {
$this
->assertEquals($content, $sync_config[$name], 'The configuration is complete.');
$this
->assertNotContains($name, array_keys($split_config), 'And it does not exist in the other folder.');
}
else {
$this
->assertEquals($content, $split_config[$name], 'The configuration is complete.');
$this
->assertNotContains($name, array_keys($sync_config), 'And it does not exist in the other folder.');
}
}
$this
->assertNotFalse(strpos($vanilla_config['core.extension.yml'], 'config_test'), 'config_test is enabled.');
$this
->assertFalse(strpos($sync_config['core.extension.yml'], 'config_test'), 'config_test is not enabled.');
}