You are here

public function ConfigImporterTest::testSecondaryWriteSecondaryFirst in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryWriteSecondaryFirst()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryWriteSecondaryFirst()

Tests that secondary writes are overwritten.

File

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

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSecondaryWriteSecondaryFirst() {
  $name_primary = 'config_test.dynamic.primary';
  $name_secondary = 'config_test.dynamic.secondary';
  $sync = $this->container
    ->get('config.storage.sync');
  $uuid = $this->container
    ->get('uuid');
  $values_primary = [
    'id' => 'primary',
    'label' => 'Primary',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
    // Add a dependency on secondary, so that is synced first.
    'dependencies' => [
      'config' => [
        $name_secondary,
      ],
    ],
  ];
  $sync
    ->write($name_primary, $values_primary);
  $values_secondary = [
    'id' => 'secondary',
    'label' => 'Secondary Sync',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
  ];
  $sync
    ->write($name_secondary, $values_secondary);

  // Import.
  $this->configImporter
    ->reset()
    ->import();
  $entity_storage = \Drupal::entityTypeManager()
    ->getStorage('config_test');
  $primary = $entity_storage
    ->load('primary');
  $this
    ->assertEqual($primary
    ->id(), 'primary');
  $this
    ->assertEqual($primary
    ->uuid(), $values_primary['uuid']);
  $this
    ->assertEqual($primary
    ->label(), $values_primary['label']);
  $secondary = $entity_storage
    ->load('secondary');
  $this
    ->assertEqual($secondary
    ->id(), 'secondary');
  $this
    ->assertEqual($secondary
    ->uuid(), $values_secondary['uuid']);
  $this
    ->assertEqual($secondary
    ->label(), $values_secondary['label']);
  $logs = $this->configImporter
    ->getErrors();
  $this
    ->assertCount(1, $logs);
  $this
    ->assertEqual($logs[0], Html::escape("Unexpected error during import with operation create for {$name_primary}: 'config_test' entity with ID 'secondary' already exists."));
}