function ConfigEventsTest::testConfigEvents

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php \Drupal\KernelTests\Core\Config\ConfigEventsTest::testConfigEvents()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php \Drupal\KernelTests\Core\Config\ConfigEventsTest::testConfigEvents()
  3. 11.x 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\Config

Code

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->assertIdentical(\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->assertIdentical($event['event_name'], ConfigEvents::SAVE);
    $this->assertIdentical($event['current_config_data'], [
        'key' => 'initial',
    ]);
    $this->assertIdentical($event['raw_config_data'], [
        'key' => 'initial',
    ]);
    $this->assertIdentical($event['original_config_data'], []);
    $config->set('key', 'updated')
        ->save();
    $event = \Drupal::state()->get('config_events_test.event', []);
    $this->assertIdentical($event['event_name'], ConfigEvents::SAVE);
    $this->assertIdentical($event['current_config_data'], [
        'key' => 'updated',
    ]);
    $this->assertIdentical($event['raw_config_data'], [
        'key' => 'updated',
    ]);
    $this->assertIdentical($event['original_config_data'], [
        'key' => 'initial',
    ]);
    $config->delete();
    $event = \Drupal::state()->get('config_events_test.event', []);
    $this->assertIdentical($event['event_name'], ConfigEvents::DELETE);
    $this->assertIdentical($event['current_config_data'], []);
    $this->assertIdentical($event['raw_config_data'], []);
    $this->assertIdentical($event['original_config_data'], [
        'key' => 'updated',
    ]);
}

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