You are here

public function SplitMergeTest::testSimpleSplitExport in Configuration Split 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/SplitMergeTest.php \Drupal\Tests\config_split\Kernel\SplitMergeTest::testSimpleSplitExport()

Test a simple export split.

File

tests/src/Kernel/SplitMergeTest.php, line 66

Class

SplitMergeTest
Test the splitting and merging.

Namespace

Drupal\Tests\config_split\Kernel

Code

public function testSimpleSplitExport() {

  // Simple split with default configuration.
  $config = $this
    ->createSplitConfig('test_split', [
    'folder' => Settings::get('file_public_path') . '/config/split',
    'module' => [
      'config_test' => 0,
    ],
  ]);
  $active = $this
    ->getActiveStorage();
  $expectedExport = new MemoryStorage();
  $expectedSplit = new MemoryStorage();

  // Set up expectations.
  foreach (array_merge($active
    ->getAllCollectionNames(), [
    StorageInterface::DEFAULT_COLLECTION,
  ]) as $collection) {
    $active = $active
      ->createCollection($collection);
    $expectedExport = $expectedExport
      ->createCollection($collection);
    $expectedSplit = $expectedSplit
      ->createCollection($collection);
    foreach ($active
      ->listAll() as $name) {
      $data = $active
        ->read($name);
      if ($name === 'core.extension') {

        // We split off the module.
        unset($data['module']['config_test']);
      }
      if (strpos($name, 'config_test') !== FALSE || in_array($name, [
        'system.menu.exclude_test',
        'system.menu.indirect_exclude_test',
      ])) {

        // Expect config that depends on config_test directly and indirectly
        // to be split off.
        $expectedSplit
          ->write($name, $data);
      }
      else {
        $expectedExport
          ->write($name, $data);
      }
    }
  }
  static::assertStorageEquals($expectedExport, $this
    ->getExportStorage());
  static::assertStorageEquals($expectedSplit, $this
    ->getSplitPreviewStorage($config));

  // Write the export to the file system and assert the import to work.
  $this
    ->copyConfig($expectedExport, $this
    ->getSyncFileStorage());
  $this
    ->copyConfig($expectedSplit, $this
    ->getSplitSourceStorage($config));
  static::assertStorageEquals($active, $this
    ->getImportStorage());
}