You are here

protected function SplitTestTrait::getSplitPreviewStorage in Configuration Split 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/SplitTestTrait.php \Drupal\Tests\config_split\Kernel\SplitTestTrait::getSplitPreviewStorage()

Get the preview storage for a split.

Parameters

\Drupal\Core\Config\Config $config: The split config.

\Drupal\Core\Config\StorageInterface $export: The export storage to graft collection storages on.

Return value

\Drupal\Core\Config\StorageInterface The storage.

5 calls to SplitTestTrait::getSplitPreviewStorage()
InactiveSplitTest::testActiveInactive in tests/src/Kernel/InactiveSplitTest.php
Test.
SplitMergeTest::testCompleteAndConditionalSplitExport in tests/src/Kernel/SplitMergeTest.php
Test complete and conditional split export.
SplitMergeTest::testConditionalSplitWithModuleConfig in tests/src/Kernel/SplitMergeTest.php
Test complete and conditional split export with modules.
SplitMergeTest::testIncludeDependency in tests/src/Kernel/SplitMergeTest.php
Test that dependencies are split too.
SplitMergeTest::testSimpleSplitExport in tests/src/Kernel/SplitMergeTest.php
Test a simple export split.

File

tests/src/Kernel/SplitTestTrait.php, line 89

Class

SplitTestTrait
Trait to facilitate creating split configurations.

Namespace

Drupal\Tests\config_split\Kernel

Code

protected function getSplitPreviewStorage(Config $config, StorageInterface $export = NULL) : StorageInterface {
  if ('collection' === $config
    ->get('storage')) {
    if ($export === NULL) {
      throw new \InvalidArgumentException();
    }
    return new SplitCollectionStorage($export, $config
      ->get('id'));
  }
  $name = substr($config
    ->getName(), strlen('config_split.config_split.'));
  $storage = new DatabaseStorage($this->container
    ->get('database'), 'config_split_preview_' . strtr($name, [
    '.' => '_',
  ]));

  // We cache it in its own memory storage so that it becomes decoupled.
  $memory = new MemoryStorage();
  $this
    ->copyConfig($storage, $memory);
  return $memory;
}