function ConfigImporterTest::testSecondaryWritePrimaryFirst

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryWritePrimaryFirst()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryWritePrimaryFirst()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testSecondaryWritePrimaryFirst()

Tests that secondary writes are overwritten.

File

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

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSecondaryWritePrimaryFirst() {
    $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(),
    ];
    $sync->write($name_primary, $values_primary);
    $values_secondary = [
        'id' => 'secondary',
        'label' => 'Secondary Sync',
        'weight' => 0,
        'uuid' => $uuid->generate(),
        // Add a dependency on primary, to ensure that is synced first.
'dependencies' => [
            'config' => [
                $name_primary,
            ],
        ],
    ];
    $sync->write($name_secondary, $values_secondary);
    // Import.
    $config_importer = $this->configImporter();
    $config_importer->import();
    $entity_storage = \Drupal::entityTypeManager()->getStorage('config_test');
    $primary = $entity_storage->load('primary');
    $this->assertEquals('primary', $primary->id());
    $this->assertEquals($values_primary['uuid'], $primary->uuid());
    $this->assertEquals($values_primary['label'], $primary->label());
    $secondary = $entity_storage->load('secondary');
    $this->assertEquals('secondary', $secondary->id());
    $this->assertEquals($values_secondary['uuid'], $secondary->uuid());
    $this->assertEquals($values_secondary['label'], $secondary->label());
    $logs = $config_importer->getErrors();
    $this->assertCount(1, $logs);
    $this->assertEquals(new FormattableMarkup('Deleted and replaced configuration entity "@name"', [
        '@name' => $name_secondary,
    ]), $logs[0]);
}

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