You are here

function ConfigImporterTest::testSecondaryWritePrimaryFirst in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigImporterTest.php \Drupal\config\Tests\ConfigImporterTest::testSecondaryWritePrimaryFirst()

Tests that secondary writes are overwritten.

File

core/modules/config/src/Tests/ConfigImporterTest.php, line 213
Contains \Drupal\config\Tests\ConfigImporterTest.

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\config\Tests

Code

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 = array(
    'id' => 'primary',
    'label' => 'Primary',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
  );
  $sync
    ->write($name_primary, $values_primary);
  $values_secondary = array(
    'id' => 'secondary',
    'label' => 'Secondary Sync',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
    // Add a dependency on primary, to ensure that is synced first.
    'dependencies' => array(
      'config' => array(
        $name_primary,
      ),
    ),
  );
  $sync
    ->write($name_secondary, $values_secondary);

  // Import.
  $this->configImporter
    ->reset()
    ->import();
  $entity_storage = \Drupal::entityManager()
    ->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
    ->assertEqual(count($logs), 1);
  $this
    ->assertEqual($logs[0], SafeMarkup::format('Deleted and replaced configuration entity "@name"', array(
    '@name' => $name_secondary,
  )));
}