You are here

function ConfigEventsTest::testConfigEvents in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigEventsTest.php \Drupal\config\Tests\ConfigEventsTest::testConfigEvents()

Tests configuration events.

File

core/modules/config/src/Tests/ConfigEventsTest.php, line 31
Contains \Drupal\config\Tests\ConfigEventsTest.

Class

ConfigEventsTest
Tests events fired on configuration objects.

Namespace

Drupal\config\Tests

Code

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');
  \Drupal::state()
    ->get('config_events_test.event', FALSE);
  $this
    ->assertIdentical(\Drupal::state()
    ->get('config_events_test.event', array()), array(), 'No events fired by creating a new configuration object');
  $config
    ->save();
  $event = \Drupal::state()
    ->get('config_events_test.event', array());
  $this
    ->assertIdentical($event['event_name'], ConfigEvents::SAVE);
  $this
    ->assertIdentical($event['current_config_data'], array(
    'key' => 'initial',
  ));
  $this
    ->assertIdentical($event['raw_config_data'], array(
    'key' => 'initial',
  ));
  $this
    ->assertIdentical($event['original_config_data'], array());
  $config
    ->set('key', 'updated')
    ->save();
  $event = \Drupal::state()
    ->get('config_events_test.event', array());
  $this
    ->assertIdentical($event['event_name'], ConfigEvents::SAVE);
  $this
    ->assertIdentical($event['current_config_data'], array(
    'key' => 'updated',
  ));
  $this
    ->assertIdentical($event['raw_config_data'], array(
    'key' => 'updated',
  ));
  $this
    ->assertIdentical($event['original_config_data'], array(
    'key' => 'initial',
  ));
  $config
    ->delete();
  $event = \Drupal::state()
    ->get('config_events_test.event', array());
  $this
    ->assertIdentical($event['event_name'], ConfigEvents::DELETE);
  $this
    ->assertIdentical($event['current_config_data'], array());
  $this
    ->assertIdentical($event['raw_config_data'], array());
  $this
    ->assertIdentical($event['original_config_data'], array(
    'key' => 'updated',
  ));
}