You are here

public function ConfigDependencyTest::testContentEntityDelete in Zircon Profile 8

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

Tests getConfigEntitiesToChangeOnDependencyRemoval() with content entities.

At the moment there is no runtime code that calculates configuration dependencies on content entity delete because this calculation is expensive and all content dependencies are soft. This test ensures that the code works for content entities.

See also

\Drupal\Core\Config\ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval()

File

core/modules/config/src/Tests/ConfigDependencyTest.php, line 422
Contains \Drupal\config\Tests\ConfigDependencyTest.

Class

ConfigDependencyTest
Tests for configuration dependencies.

Namespace

Drupal\config\Tests

Code

public function testContentEntityDelete() {
  $this
    ->installEntitySchema('entity_test');

  /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  $config_manager = \Drupal::service('config.manager');
  $content_entity = EntityTest::create();
  $content_entity
    ->save();

  /** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */
  $storage = $this->container
    ->get('entity.manager')
    ->getStorage('config_test');
  $entity1 = $storage
    ->create(array(
    'id' => 'entity1',
    'dependencies' => array(
      'enforced' => array(
        'content' => array(
          $content_entity
            ->getConfigDependencyName(),
        ),
      ),
    ),
  ));
  $entity1
    ->save();
  $entity2 = $storage
    ->create(array(
    'id' => 'entity2',
    'dependencies' => array(
      'enforced' => array(
        'config' => array(
          $entity1
            ->getConfigDependencyName(),
        ),
      ),
    ),
  ));
  $entity2
    ->save();

  // Create a configuration entity that is not in the dependency chain.
  $entity3 = $storage
    ->create(array(
    'id' => 'entity3',
  ));
  $entity3
    ->save();
  $config_entities = $config_manager
    ->getConfigEntitiesToChangeOnDependencyRemoval('content', [
    $content_entity
      ->getConfigDependencyName(),
  ]);
  $this
    ->assertEqual($entity1
    ->uuid(), $config_entities['delete'][0]
    ->uuid(), 'Entity 1 will be deleted.');
  $this
    ->assertEqual($entity2
    ->uuid(), $config_entities['delete'][1]
    ->uuid(), 'Entity 2 will be deleted.');
  $this
    ->assertTrue(empty($config_entities['update']), 'No dependencies of the content entity will be updated.');
  $this
    ->assertTrue(empty($config_entities['unchanged']), 'No dependencies of the content entity will be unchanged.');
}