function ConfigImportRenameValidationTest::testRenameSimpleConfigValidation

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php \Drupal\KernelTests\Core\Config\ConfigImportRenameValidationTest::testRenameSimpleConfigValidation()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php \Drupal\KernelTests\Core\Config\ConfigImportRenameValidationTest::testRenameSimpleConfigValidation()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php \Drupal\KernelTests\Core\Config\ConfigImportRenameValidationTest::testRenameSimpleConfigValidation()

Tests configuration renaming validation for simple configuration.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php, line 124

Class

ConfigImportRenameValidationTest
Tests validating renamed configuration in a configuration import.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testRenameSimpleConfigValidation() {
    $uuid = new Php();
    // Create a simple configuration with a UUID.
    $config = $this->config('config_test.new');
    $uuid_value = $uuid->generate();
    $config->set('uuid', $uuid_value)
        ->save();
    $active = $this->container
        ->get('config.storage');
    $sync = $this->container
        ->get('config.storage.sync');
    $this->copyConfig($active, $sync);
    $config->delete();
    // Create another simple configuration with the same UUID.
    $config = $this->config('config_test.old');
    $config->set('uuid', $uuid_value)
        ->save();
    // Confirm that the staged configuration is detected as a rename since the
    // UUIDs match.
    $this->configImporter
        ->reset();
    $expected = [
        'config_test.old::config_test.new',
    ];
    $renames = $this->configImporter
        ->getUnprocessedConfiguration('rename');
    $this->assertSame($expected, $renames);
    // Try to import the configuration. We expect an exception to be thrown
    // because the rename is for simple configuration.
    try {
        $this->configImporter
            ->import();
        $this->fail('Expected ConfigImporterException thrown when simple configuration is renamed.');
    } catch (ConfigImporterException $e) {
        $expected = [
            new FormattableMarkup('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', [
                '@old_name' => 'config_test.old',
                '@new_name' => 'config_test.new',
            ]),
        ];
        $this->assertEquals($expected, $this->configImporter
            ->getErrors());
    }
}

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