public function ConfigSplitCliServiceTest::testGrayAndBlackListExport in Configuration Split 8
Test blacklist and gray list export.
File
- tests/
src/ Kernel/ ConfigSplitCliServiceTest.php, line 180
Class
- ConfigSplitCliServiceTest
- Test the cli service.
Namespace
Drupal\Tests\config_split\KernelCode
public function testGrayAndBlackListExport() {
$split = vfsStream::setup('split');
$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' => [],
'theme' => [],
'blacklist' => [
'config_test.types',
],
'graylist' => [
'config_test.system',
],
])
->save();
// Export the configuration like core.
$this->container
->get('config_split.cli')
->export($primary);
$original_config = [];
foreach ($split
->getChild('sync')
->getChildren() as $child) {
if ($child
->getType() == vfsStreamContent::TYPE_FILE && $child
->getName() != '.htaccess') {
$original_config[$child
->getName()] = $child
->getContent();
}
}
$this
->assertFalse($split
->hasChild('split'), 'The split directory is empty.');
$this
->assertTrue(isset($original_config['config_test.system.yml']), 'The graylisted config is exported.');
$this
->assertTrue(isset($original_config['config_test.types.yml']), 'The blacklisted config is exported.');
// Change the gray listed config to see if it is exported the same.
$this
->config('config_test.system')
->set('foo', 'baz')
->save();
// Export the configuration with filtering.
$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);
$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
->assertTrue(isset($split_config['config_test.system.yml']), 'The graylisted config is exported to the split.');
$this
->assertTrue(isset($split_config['config_test.types.yml']), 'The blacklisted config is exported to the split.');
$this
->assertTrue(isset($sync_config['config_test.system.yml']), 'The graylisted config is exported to the sync.');
$this
->assertFalse(isset($sync_config['config_test.types.yml']), 'The blacklisted config is not exported to the sync.');
$this
->assertEquals($original_config['config_test.types.yml'], $split_config['config_test.types.yml'], 'The split blacklisted config is the same..');
$this
->assertEquals($original_config['config_test.system.yml'], $sync_config['config_test.system.yml'], 'The graylisted config stayed the same.');
$this
->assertNotEquals($original_config['config_test.system.yml'], $split_config['config_test.system.yml'], 'The split graylisted config is different.');
// Change the filter.
$config
->initWithData([
'folder' => $split
->url() . '/split',
'module' => [],
'theme' => [],
'blacklist' => [
'config_test.system',
],
'graylist' => [],
])
->save();
// Export the configuration with filtering.
$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);
$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
->assertFalse(isset($sync_config['config_test.system.yml']), 'The newly blacklisted config is removed.');
$this
->assertTrue(isset($split_config['config_test.system.yml']), 'The newly blacklisted config is exported to the split.');
$this
->assertFalse(isset($split_config['config_test.types.yml']), 'The config no longer blacklisted is not exported to the split.');
$this
->assertTrue(isset($sync_config['config_test.types.yml']), 'The config no longer blacklisted is exported to the sync.');
}