function ConfigDependencyTest::testContentEntityDelete

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php \Drupal\KernelTests\Core\Config\ConfigDependencyTest::testContentEntityDelete()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php \Drupal\KernelTests\Core\Config\ConfigDependencyTest::testContentEntityDelete()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php \Drupal\KernelTests\Core\Config\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/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php, line 598

Class

ConfigDependencyTest
Tests for configuration dependencies.

Namespace

Drupal\KernelTests\Core\Config

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_type.manager')
        ->getStorage('config_test');
    $entity1 = $storage->create([
        'id' => 'entity1',
        'dependencies' => [
            'enforced' => [
                'content' => [
                    $content_entity->getConfigDependencyName(),
                ],
            ],
        ],
    ]);
    $entity1->save();
    $entity2 = $storage->create([
        'id' => 'entity2',
        'dependencies' => [
            'enforced' => [
                'config' => [
                    $entity1->getConfigDependencyName(),
                ],
            ],
        ],
    ]);
    $entity2->save();
    // Create a configuration entity that is not in the dependency chain.
    $entity3 = $storage->create([
        'id' => 'entity3',
    ]);
    $entity3->save();
    $config_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval('content', [
        $content_entity->getConfigDependencyName(),
    ]);
    $this->assertEquals($entity1->uuid(), $config_entities['delete'][1]->uuid(), 'Entity 1 will be deleted.');
    $this->assertEquals($entity2->uuid(), $config_entities['delete'][0]->uuid(), 'Entity 2 will be deleted.');
    $this->assertEmpty($config_entities['update'], 'No dependencies of the content entity will be updated.');
    $this->assertEmpty($config_entities['unchanged'], 'No dependencies of the content entity will be unchanged.');
}

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