function ConfigImportRenameValidationTest::testRenameValidation
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php \Drupal\KernelTests\Core\Config\ConfigImportRenameValidationTest::testRenameValidation()
- 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php \Drupal\KernelTests\Core\Config\ConfigImportRenameValidationTest::testRenameValidation()
- 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImportRenameValidationTest.php \Drupal\KernelTests\Core\Config\ConfigImportRenameValidationTest::testRenameValidation()
Tests configuration renaming validation.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigImportRenameValidationTest.php, line 73
Class
- ConfigImportRenameValidationTest
- Tests validating renamed configuration in a configuration import.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testRenameValidation() : void {
// Create a test entity.
$test_entity_id = $this->randomMachineName();
$test_entity = \Drupal::entityTypeManager()->getStorage('config_test')
->create([
'id' => $test_entity_id,
'label' => $this->randomMachineName(),
]);
$test_entity->save();
$uuid = $test_entity->uuid();
// Stage the test entity and then delete it from the active storage.
$active = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$this->copyConfig($active, $sync);
$test_entity->delete();
// Create a content type with a matching UUID in the active storage.
$content_type = NodeType::create([
'type' => $this->randomMachineName(16),
'name' => $this->randomMachineName(),
'uuid' => $uuid,
]);
$content_type->save();
// Confirm that the staged configuration is detected as a rename since the
// UUIDs match.
$this->configImporter
->reset();
$expected = [
'node.type.' . $content_type->id() . '::config_test.dynamic.' . $test_entity_id,
];
$renames = $this->configImporter
->getUnprocessedConfiguration('rename');
$this->assertSame($expected, $renames);
// Try to import the configuration. We expect an exception to be thrown
// because the staged entity is of a different type.
try {
$this->configImporter
->import();
$this->fail('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
} catch (ConfigImporterException) {
$expected = [
"Entity type mismatch on rename. node_type not equal to config_test for existing configuration node.type.{$content_type->id()} and staged configuration config_test.dynamic.{$test_entity_id}.",
];
$this->assertEquals($expected, $this->configImporter
->getErrors());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.