function BlockContentCreationTest::testConfigDependencies

Same name in other branches
  1. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testConfigDependencies()
  2. 10 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testConfigDependencies()
  3. 11.x core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testConfigDependencies()

Tests placed content blocks create a dependency in the block placement.

File

core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php, line 280

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testConfigDependencies() {
    $block = $this->createBlockContent();
    // Place the block.
    $block_placement_id = mb_strtolower($block->label());
    $instance = [
        'id' => $block_placement_id,
        'settings[label]' => $block->label(),
        'region' => 'sidebar_first',
    ];
    $block = BlockContent::load(1);
    $url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')
        ->get('default');
    $this->drupalGet($url);
    $this->submitForm($instance, 'Save block');
    $dependencies = \Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('content', [
        $block->getConfigDependencyName(),
    ]);
    $block_placement = reset($dependencies);
    $this->assertEquals($block_placement_id, $block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
}

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