View source
<?php
namespace Drupal\Tests\config_split\Kernel;
use Drupal\config_filter\Config\FilteredStorage;
use Drupal\config_split\Form\ConfigSplitEntityForm;
use Drupal\config_split\Plugin\ConfigFilter\SplitFilter;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
use org\bovigo\vfs\vfsStream;
class ConfigSplitKernelTest extends KernelTestBase {
public static $modules = [
'system',
'config_test',
'config_filter',
'config_split',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'config_test',
]);
}
public function testSerialisation() {
$vfs = vfsStream::setup('split');
$primary = new FileStorage($vfs
->url() . '/sync');
$folder_config = new Config('config_split.config_split.folder_split', $this->container
->get('config.storage'), $this->container
->get('event_dispatcher'), $this->container
->get('config.typed'));
$folder_config
->initWithData([
'id' => 'folder_split',
'folder' => $vfs
->url() . '/split',
'module' => [],
'theme' => [],
'blacklist' => [
'config_test.system',
],
'graylist' => [],
])
->save();
$folder_split = SplitFilter::create($this->container, [
'config_name' => 'config_split.config_split.folder_split',
], 'config_split:folder_split', []);
$db_config = new Config('config_split.config_split.db_split', $this->container
->get('config.storage'), $this->container
->get('event_dispatcher'), $this->container
->get('config.typed'));
$db_config
->initWithData([
'id' => 'db_split',
'folder' => '',
'module' => [],
'theme' => [],
'blacklist' => [
'config_test.types',
],
'graylist' => [],
])
->save();
$db_split = SplitFilter::create($this->container, [
'config_name' => 'config_split.config_split.db_split',
], 'config_split:db_split', []);
$filtered = new FilteredStorage($primary, [
$folder_split,
$db_split,
]);
$this
->copyConfig($this->container
->get('config.storage'), $filtered);
$test_system = $filtered
->read('config_test.system');
$test_types = $filtered
->read('config_test.types');
$test_validation = $filtered
->read('config_test.validation');
$this
->assertEquals($this->container
->get('config.storage')
->read('config_test.system'), $test_system);
$this
->assertEquals($this->container
->get('config.storage')
->read('config_test.types'), $test_types);
$this
->assertEquals($this->container
->get('config.storage')
->read('config_test.validation'), $test_validation);
$serialized = serialize($filtered);
$filtered = unserialize($serialized);
$this
->assertEquals($test_system, $filtered
->read('config_test.system'));
$this
->assertEquals($test_types, $filtered
->read('config_test.types'));
$this
->assertEquals($test_validation, $filtered
->read('config_test.validation'));
}
public function testSyncFolderIsConflicting($split, $sync, $expected) {
$settings = Settings::getAll();
$settings['config_sync_directory'] = $sync;
new Settings($settings);
$reflection = new \ReflectionClass(ConfigSplitEntityForm::class);
$method = $reflection
->getMethod('isConflicting');
$method
->setAccessible(TRUE);
$this
->assertEquals($expected, $method
->invoke(NULL, $split));
}
public function syncFolderIsConflictingProvider() {
return [
[
'../config/split',
'../config/sync',
FALSE,
],
[
'../config/config_split',
'../config/config',
FALSE,
],
[
'../config/sync/split',
'../config/sync',
TRUE,
],
[
'config/other/../sync',
'config/sync',
FALSE,
],
];
}
}