You are here

public function ConfigImportRenameValidationTest::testRenameSimpleConfigValidation in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/config/src/Tests/ConfigImportRenameValidationTest.php \Drupal\config\Tests\ConfigImportRenameValidationTest::testRenameSimpleConfigValidation()

Tests configuration renaming validation for simple configuration.

File

core/modules/config/src/Tests/ConfigImportRenameValidationTest.php, line 122
Contains \Drupal\config\Tests\ConfigImportRenameValidationTest.

Class

ConfigImportRenameValidationTest
Tests validating renamed configuration in a configuration import.

Namespace

Drupal\config\Tests

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 = array(
    'config_test.old::config_test.new',
  );
  $renames = $this->configImporter
    ->getUnprocessedConfiguration('rename');
  $this
    ->assertIdentical($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) {
    $this
      ->pass('Expected ConfigImporterException thrown when simple configuration is renamed.');
    $expected = array(
      SafeMarkup::format('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', array(
        '@old_name' => 'config_test.old',
        '@new_name' => 'config_test.new',
      )),
    );
    $this
      ->assertEqual($expected, $this->configImporter
      ->getErrors());
  }
}