You are here

public function ConfigImporterTest::testSecondaryUpdateDeletedDeleteeFirst in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryUpdateDeletedDeleteeFirst()

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 393

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSecondaryUpdateDeletedDeleteeFirst() {
  $name_deleter = 'config_test.dynamic.deleter';
  $name_deletee = 'config_test.dynamic.deletee';
  $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(),
    // Add a dependency on deletee, to make sure that is synced first.
    'dependencies' => [
      'config' => [
        $name_deletee,
      ],
    ],
  ];
  $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(),
  ];
  $storage
    ->write($name_deletee, $values_deletee);
  $values_deletee['label'] = 'Updated Deletee';
  $sync
    ->write($name_deletee, $values_deletee);

  // Import.
  $this->configImporter
    ->reset()
    ->import();
  $entity_storage = \Drupal::entityTypeManager()
    ->getStorage('config_test');

  // Both entities are deleted. ConfigTest::postSave() causes updates of the
  // deleter entity to delete the deletee entity. Since the deleter depends on
  // the deletee, removing the deletee causes the deleter to be removed.
  $this
    ->assertNull($entity_storage
    ->load('deleter'));
  $this
    ->assertNull($entity_storage
    ->load('deletee'));
  $logs = $this->configImporter
    ->getErrors();
  $this
    ->assertCount(0, $logs);
}