You are here

function ConfigImporterTest::testSecondaryUpdateDeletedDeleteeFirst 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::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/modules/config/src/Tests/ConfigImporterTest.php, line 391
Contains \Drupal\config\Tests\ConfigImporterTest.

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\config\Tests

Code

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 = array(
    'id' => 'deleter',
    'label' => 'Deleter',
    'weight' => 0,
    'uuid' => $uuid
      ->generate(),
    // Add a dependency on deletee, to make sure that is synced first.
    'dependencies' => array(
      'config' => array(
        $name_deletee,
      ),
    ),
  );
  $storage
    ->write($name_deleter, $values_deleter);
  $values_deleter['label'] = 'Updated Deleter';
  $sync
    ->write($name_deleter, $values_deleter);
  $values_deletee = array(
    '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::entityManager()
    ->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
    ->assertFalse($entity_storage
    ->load('deleter'));
  $this
    ->assertFalse($entity_storage
    ->load('deletee'));
  $logs = $this->configImporter
    ->getErrors();
  $this
    ->assertEqual(count($logs), 0);
}