You are here

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

Test complete and conditional split export with modules.

File

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

Class

SplitMergeTest
Test the splitting and merging.

Namespace

Drupal\Tests\config_split\Kernel

Code

public function testConditionalSplitWithModuleConfig() {
  $config = $this
    ->createSplitConfig('test_split', [
    'folder' => Settings::get('file_public_path') . '/config/split',
    'module' => [
      'config_test' => 0,
    ],
    'graylist' => [
      'config_test.system',
    ],
    'graylist_skip_equal' => FALSE,
  ]);
  $active = $this
    ->getActiveStorage();

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

  // Change the gray listed config to see if it is exported the same.
  $originalSystem = $this
    ->config('config_test.system')
    ->getRawData();
  $this
    ->config('config_test.system')
    ->set('foo', 'baz')
    ->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 === 'core.extension') {
        unset($data['module']['config_test']);
      }
      if ($name === 'config_test.system') {

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

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

          // The option "skip equal" is false, write to both.
          $expectedSplit
            ->write($name, $data);
          $expectedExport
            ->write($name, $data);
        }
      }
      elseif (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());
}