function ConfigEventsTest::testConfigRenameEvent

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php \Drupal\KernelTests\Core\Config\ConfigEventsTest::testConfigRenameEvent()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigEventsTest.php \Drupal\KernelTests\Core\Config\ConfigEventsTest::testConfigRenameEvent()
  3. 11.x 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() : void {
    $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->assertSame(ConfigEvents::SAVE, $event['event_name']);
    $this->assertSame([
        'key' => 'initial',
    ], $event['current_config_data']);
    // Override applies when getting runtime config.
    $this->assertEquals($GLOBALS['config'][$name], \Drupal::config($name)->get());
    \Drupal::configFactory()->rename($name, $new_name);
    $event = \Drupal::state()->get('config_events_test.event', []);
    $this->assertSame(ConfigEvents::RENAME, $event['event_name']);
    $this->assertSame([
        'key' => 'new overridden',
    ], $event['current_config_data']);
    $this->assertSame([
        'key' => 'initial',
    ], $event['raw_config_data']);
    $this->assertSame([
        'key' => 'new overridden',
    ], $event['original_config_data']);
}

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