public function ConfigImporterTest::testSecondaryUpdateDeletedDeleterFirst in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryUpdateDeletedDeleterFirst()
- 9 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryUpdateDeletedDeleterFirst()
Tests that secondary updates for deleted files work as expected.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigImporterTest.php, line 286
Class
- ConfigImporterTest
- Tests importing configuration from files into active configuration.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testSecondaryUpdateDeletedDeleterFirst() {
$name_deleter = 'config_test.dynamic.deleter';
$name_deletee = 'config_test.dynamic.deletee';
$name_other = 'config_test.dynamic.other';
$storage = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$uuid = $this->container
->get('uuid');
$values_deleter = [
'id' => 'deleter',
'label' => 'Deleter',
'weight' => 0,
'uuid' => $uuid
->generate(),
];
$storage
->write($name_deleter, $values_deleter);
$values_deleter['label'] = 'Updated Deleter';
$sync
->write($name_deleter, $values_deleter);
$values_deletee = [
'id' => 'deletee',
'label' => 'Deletee',
'weight' => 0,
'uuid' => $uuid
->generate(),
// Add a dependency on deleter, to make sure that is synced first.
'dependencies' => [
'config' => [
$name_deleter,
],
],
];
$storage
->write($name_deletee, $values_deletee);
$values_deletee['label'] = 'Updated Deletee';
$sync
->write($name_deletee, $values_deletee);
// Ensure that import will continue after the error.
$values_other = [
'id' => 'other',
'label' => 'Other',
'weight' => 0,
'uuid' => $uuid
->generate(),
// Add a dependency on deleter, to make sure that is synced first. This
// will also be synced after the deletee due to alphabetical ordering.
'dependencies' => [
'config' => [
$name_deleter,
],
],
];
$storage
->write($name_other, $values_other);
$values_other['label'] = 'Updated other';
$sync
->write($name_other, $values_other);
// Check update changelist order.
$config_importer = $this
->configImporter();
$updates = $config_importer
->getStorageComparer()
->getChangelist('update');
$expected = [
$name_deleter,
$name_deletee,
$name_other,
];
$this
->assertSame($expected, $updates);
// Import.
$config_importer
->import();
$entity_storage = \Drupal::entityTypeManager()
->getStorage('config_test');
$deleter = $entity_storage
->load('deleter');
$this
->assertEquals('deleter', $deleter
->id());
$this
->assertEquals($values_deleter['uuid'], $deleter
->uuid());
$this
->assertEquals($values_deleter['label'], $deleter
->label());
// The deletee was deleted in
// \Drupal\config_test\Entity\ConfigTest::postSave().
$this
->assertNull($entity_storage
->load('deletee'));
$other = $entity_storage
->load('other');
$this
->assertEquals('other', $other
->id());
$this
->assertEquals($values_other['uuid'], $other
->uuid());
$this
->assertEquals($values_other['label'], $other
->label());
$logs = $config_importer
->getErrors();
$this
->assertCount(1, $logs);
$this
->assertEquals(new FormattableMarkup('Update target "@name" is missing.', [
'@name' => $name_deletee,
]), $logs[0]);
}