function ConfigImporterTest::testSecondaryUpdateDeletedChildFirst

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryUpdateDeletedChildFirst()

Tests that secondary updates for deleted files work as expected.

This test is completely hypothetical since we only support full configuration tree imports. Therefore, any configuration updates that cause secondary deletes should be reflected already in the staged configuration.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php, line 377

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSecondaryUpdateDeletedChildFirst() : void {
    $name_dependency = 'config_test.dynamic.dependency';
    $name_dependent = 'config_test.dynamic.dependent';
    $storage = $this->container
        ->get('config.storage');
    $sync = $this->container
        ->get('config.storage.sync');
    $uuid = $this->container
        ->get('uuid');
    $values_dependency = [
        'id' => 'dependency',
        'label' => 'Dependency',
        'weight' => 0,
        'uuid' => $uuid->generate(),
        // Add a dependency on dependent, to make sure that is synced first.
'dependencies' => [
            'config' => [
                $name_dependent,
            ],
        ],
    ];
    $storage->write($name_dependency, $values_dependency);
    $values_dependency['label'] = 'Updated Dependency';
    $sync->write($name_dependency, $values_dependency);
    $values_dependent = [
        'id' => 'dependent',
        'label' => 'Dependent',
        'weight' => 0,
        'uuid' => $uuid->generate(),
    ];
    $storage->write($name_dependent, $values_dependent);
    $values_dependent['label'] = 'Updated Dependent';
    $sync->write($name_dependent, $values_dependent);
    // Import.
    $config_importer = $this->configImporter();
    $config_importer->import();
    $entity_storage = \Drupal::entityTypeManager()->getStorage('config_test');
    // Both entities are deleted. ConfigTest::postSave() causes updates of the
    // dependency entity to delete the dependent entity. Since the dependency depends on
    // the dependent, removing the dependent causes the dependency to be removed.
    $this->assertNull($entity_storage->load('dependency'));
    $this->assertNull($entity_storage->load('dependent'));
    $logs = $config_importer->getErrors();
    $this->assertCount(0, $logs);
}

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