You are here

public function ConfigEventsTest::testConfigRenameEvent in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php \Drupal\KernelTests\Core\Config\ConfigEventsTest::testConfigRenameEvent()

Tests configuration rename event that is fired from the ConfigFactory.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php, line 58

Class

ConfigEventsTest
Tests events fired on configuration objects.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testConfigRenameEvent() {
  $name = 'config_events_test.test';
  $new_name = 'config_events_test.test_rename';
  $GLOBALS['config'][$name] = [
    'key' => 'overridden',
  ];
  $GLOBALS['config'][$new_name] = [
    'key' => 'new overridden',
  ];
  $config = $this
    ->config($name);
  $config
    ->set('key', 'initial')
    ->save();
  $event = \Drupal::state()
    ->get('config_events_test.event', []);
  $this
    ->assertIdentical($event['event_name'], ConfigEvents::SAVE);
  $this
    ->assertIdentical($event['current_config_data'], [
    'key' => 'initial',
  ]);

  // Override applies when getting runtime config.
  $this
    ->assertEqual($GLOBALS['config'][$name], \Drupal::config($name)
    ->get());
  \Drupal::configFactory()
    ->rename($name, $new_name);
  $event = \Drupal::state()
    ->get('config_events_test.event', []);
  $this
    ->assertIdentical($event['event_name'], ConfigEvents::RENAME);
  $this
    ->assertIdentical($event['current_config_data'], [
    'key' => 'new overridden',
  ]);
  $this
    ->assertIdentical($event['raw_config_data'], [
    'key' => 'initial',
  ]);
  $this
    ->assertIdentical($event['original_config_data'], [
    'key' => 'new overridden',
  ]);
}