public function ConfigEventsTest::testConfigEvents in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php \Drupal\KernelTests\Core\Config\ConfigEventsTest::testConfigEvents()
Tests configuration events.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigEventsTest.php, line 26
Class
- ConfigEventsTest
- Tests events fired on configuration objects.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testConfigEvents() {
$name = 'config_events_test.test';
$config = new Config($name, \Drupal::service('config.storage'), \Drupal::service('event_dispatcher'), \Drupal::service('config.typed'));
$config
->set('key', 'initial');
$this
->assertSame([], \Drupal::state()
->get('config_events_test.event', []), 'No events fired by creating a new configuration object');
$config
->save();
$event = \Drupal::state()
->get('config_events_test.event', []);
$this
->assertSame(ConfigEvents::SAVE, $event['event_name']);
$this
->assertSame([
'key' => 'initial',
], $event['current_config_data']);
$this
->assertSame([
'key' => 'initial',
], $event['raw_config_data']);
$this
->assertSame([], $event['original_config_data']);
$config
->set('key', 'updated')
->save();
$event = \Drupal::state()
->get('config_events_test.event', []);
$this
->assertSame(ConfigEvents::SAVE, $event['event_name']);
$this
->assertSame([
'key' => 'updated',
], $event['current_config_data']);
$this
->assertSame([
'key' => 'updated',
], $event['raw_config_data']);
$this
->assertSame([
'key' => 'initial',
], $event['original_config_data']);
$config
->delete();
$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' => 'updated',
], $event['original_config_data']);
}