function ConfigImporterTest::testStorageComparerTargetStorage

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testStorageComparerTargetStorage()

Tests the target storage caching during configuration import.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php, line 1019

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testStorageComparerTargetStorage() : void {
    $this->installConfig([
        'config_events_test',
    ]);
    $this->copyConfig($this->container
        ->get('config.storage'), $this->container
        ->get('config.storage.sync'));
    $this->assertTrue($this->container
        ->get('module_installer')
        ->uninstall([
        'config_test',
    ]));
    \Drupal::state()->set('config_events_test.all_events', []);
    \Drupal::state()->set('config_test_install.foo_value', 'transient');
    // Prime the active config cache. If the ConfigImporter and StorageComparer
    // do not manage the target storage correctly this cache can pollute the
    // data.
    \Drupal::configFactory()->get('config_test.system');
    // Import the configuration. This results in a save event with the value
    // changing from foo to bar.
    $this->configImporter()
        ->import();
    $all_events = \Drupal::state()->get('config_events_test.all_events');
    // Test that the values change as expected during the configuration import.
    $this->assertCount(3, $all_events[ConfigEvents::SAVE]['config_test.system']);
    // First, the values are set by the module installer using the configuration
    // import's source storage.
    $this->assertSame([], $all_events[ConfigEvents::SAVE]['config_test.system'][0]['original_config_data']);
    $this->assertSame('bar', $all_events[ConfigEvents::SAVE]['config_test.system'][0]['current_config_data']['foo']);
    // Next, the config_test_install() function changes the value.
    $this->assertSame('bar', $all_events[ConfigEvents::SAVE]['config_test.system'][1]['original_config_data']['foo']);
    $this->assertSame('transient', $all_events[ConfigEvents::SAVE]['config_test.system'][1]['current_config_data']['foo']);
    // Last, the config importer processes all the configuration in the source
    // storage and ensures the values are as expected.
    $this->assertSame('transient', $all_events[ConfigEvents::SAVE]['config_test.system'][2]['original_config_data']['foo']);
    $this->assertSame('bar', $all_events[ConfigEvents::SAVE]['config_test.system'][2]['current_config_data']['foo']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.