function ConfigImporterTest::testConfigEvents
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testConfigEvents()
Tests config events during config import.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigImporterTest.php, line 951
Class
- ConfigImporterTest
- Tests importing configuration from files into active configuration.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testConfigEvents() : void {
$this->installConfig([
'config_events_test',
]);
$this->config('config_events_test.test')
->set('key', 'bar')
->save();
$this->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
$this->config('config_events_test.test')
->set('key', 'foo')
->save();
\Drupal::state()->set('config_events_test.event', []);
// Import the configuration. This results in a save event with the value
// changing from foo to bar.
$this->configImporter()
->import();
$event = \Drupal::state()->get('config_events_test.event', []);
$this->assertSame(ConfigEvents::SAVE, $event['event_name']);
$this->assertSame([
'key' => 'bar',
], $event['current_config_data']);
$this->assertSame([
'key' => 'bar',
], $event['raw_config_data']);
$this->assertSame([
'key' => 'foo',
], $event['original_config_data']);
// Import the configuration that deletes 'config_events_test.test'.
$this->container
->get('config.storage.sync')
->delete('config_events_test.test');
$this->configImporter()
->import();
$this->assertFalse($this->container
->get('config.storage')
->exists('config_events_test.test'));
$event = \Drupal::state()->get('config_events_test.event', []);
$this->assertSame(ConfigEvents::DELETE, $event['event_name']);
$this->assertSame([], $event['current_config_data']);
$this->assertSame([], $event['raw_config_data']);
$this->assertSame([
'key' => 'bar',
], $event['original_config_data']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.