You are here

public function ConfigImporterTest::testSecondaryDeletedDeleteeSecond 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::testSecondaryDeletedDeleteeSecond()

Tests that secondary deletes for deleted files work as expected.

File

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

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSecondaryDeletedDeleteeSecond() {
  $name_deleter = 'config_test.dynamic.deleter';
  $name_deletee = 'config_test.dynamic.deletee';
  $storage = $this->container
    ->get('config.storage');
  $uuid = $this->container
    ->get('uuid');
  $values_deleter = [
    'id' => 'deleter',
    'label' => 'Deleter',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
    // Add a dependency on deletee, to make sure this delete is synced first.
    'dependencies' => [
      'config' => [
        $name_deletee,
      ],
    ],
  ];
  $storage
    ->write($name_deleter, $values_deleter);
  $values_deletee = [
    'id' => 'deletee',
    'label' => 'Deletee',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
  ];
  $storage
    ->write($name_deletee, $values_deletee);

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

  // The deletee entity does not exist as the delete worked and although the
  // delete occurred in \Drupal\config_test\Entity\ConfigTest::postDelete()
  // this does not matter.
  $logs = $this->configImporter
    ->getErrors();
  $this
    ->assertCount(0, $logs);
}