You are here

public function SplitMergeTest::testIncludeDependency in Configuration Split 2.0.x

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

Test that dependencies are split too.

@dataProvider storageAlternativesProvider

File

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

Class

SplitMergeTest
Test the splitting and merging.

Namespace

Drupal\Tests\config_split\Kernel

Code

public function testIncludeDependency($storage) {
  $config = $this
    ->createSplitConfig('test_split', [
    'storage' => $storage,
    'complete_list' => [
      'system.menu.exclude_test',
    ],
  ]);

  // Export the configuration to sync without filtering.
  $this
    ->copyConfig($this
    ->getActiveStorage(), $this
    ->getSyncFileStorage());

  // Change some config.
  $this
    ->config('system.menu.indirect_exclude_test')
    ->set('label', 'Split Test')
    ->save();
  $active = $this
    ->getActiveStorage();
  $expectedExport = new MemoryStorage();
  $expectedSplit = new MemoryStorage();

  // Set up the expected data.
  foreach (array_merge([
    StorageInterface::DEFAULT_COLLECTION,
  ], $active
    ->getAllCollectionNames()) as $collection) {
    $active = $active
      ->createCollection($collection);
    $expectedExport = $expectedExport
      ->createCollection($collection);
    $expectedSplit = $expectedSplit
      ->createCollection($collection);
    foreach ($active
      ->listAll() as $name) {
      $data = $active
        ->read($name);
      if (in_array($name, [
        'system.menu.exclude_test',
        'system.menu.indirect_exclude_test',
      ])) {
        $expectedSplit
          ->write($name, $data);
      }
      else {
        $expectedExport
          ->write($name, $data);
      }
    }
  }
  if ($storage === 'collection') {
    $temp = new SplitCollectionStorage($expectedExport, $config
      ->get('id'));
    self::replaceStorageContents($expectedSplit, $temp);
  }
  $export = $this
    ->getExportStorage();
  static::assertStorageEquals($expectedExport, $export);
  static::assertStorageEquals($expectedSplit, $this
    ->getSplitPreviewStorage($config, $export));

  // 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());
}