You are here

public function SplitMergeTest::testIncludeDependency 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::testIncludeDependency()

Test that dependencies are split too.

File

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

Class

SplitMergeTest
Test the splitting and merging.

Namespace

Drupal\Tests\config_split\Kernel

Code

public function testIncludeDependency() {
  $config = $this
    ->createSplitConfig('test_split', [
    'graylist' => [
      'system.menu.exclude_test',
    ],
    'graylist_dependents' => TRUE,
    'graylist_skip_equal' => TRUE,
  ]);
  $active = $this
    ->getActiveStorage();

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

  // Change only the indirectly dependent config.
  $originalSystem = $this
    ->config('system.menu.indirect_exclude_test')
    ->getRawData();
  $this
    ->config('system.menu.indirect_exclude_test')
    ->set('label', 'Split Test')
    ->save();
  $expectedExport = new MemoryStorage();
  $expectedSplit = new MemoryStorage();

  // Set up the expected data.
  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 === 'system.menu.indirect_exclude_test') {

        // We only changed the config in the default collection.
        if ($collection === StorageInterface::DEFAULT_COLLECTION) {

          // The unchanged value is in export, the changed value is split.
          $expectedSplit
            ->write($name, $data);
          $expectedExport
            ->write($name, $originalSystem);
        }
        else {

          // The option "skip equal" is false, write to export only.
          $expectedExport
            ->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());

  // If we don't include the dependants then the split will be empty.
  $config
    ->set('graylist_dependents', FALSE)
    ->save();
  static::assertStorageEquals($active, $this
    ->getExportStorage());
  static::assertStorageEquals(new MemoryStorage(), $this
    ->getSplitPreviewStorage($config));
}