SplitTestTrait.php in Configuration Split 8
File
tests/src/Kernel/SplitTestTrait.php
View source
<?php
namespace Drupal\Tests\config_split\Kernel;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\MemoryStorage;
use Drupal\Core\Config\StorageInterface;
trait SplitTestTrait {
protected function createSplitConfig(string $name, array $data) : Config {
if (substr($name, 0, strlen('config_split.config_split.')) !== 'config_split.config_split.') {
$name = 'config_split.config_split.' . $name;
}
$data += [
'folder' => '',
'module' => [],
'theme' => [],
'blacklist' => [],
'graylist' => [],
'status' => TRUE,
'graylist_dependents' => TRUE,
'graylist_skip_equal' => TRUE,
'weight' => 0,
];
$data['id'] = substr($name, strlen('config_split.config_split.'));
$config = new Config($name, $this->container
->get('config.storage'), $this->container
->get('event_dispatcher'), $this->container
->get('config.typed'));
$config
->initWithData($data)
->save();
return $config;
}
protected function getSplitSourceStorage(Config $config) : StorageInterface {
$directory = $config
->get('folder');
if ($directory) {
return new FileStorage($directory);
}
return new DatabaseStorage($this->container
->get('database'), strtr($config
->getName(), [
'.' => '_',
]));
}
protected function getSplitPreviewStorage(Config $config) : StorageInterface {
$memory = new MemoryStorage();
$this
->copyConfig($this
->getSplitSourceStorage($config), $memory);
return $memory;
}
}