You are here

public function BlockContentCreationTest::testConfigDependencies in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testConfigDependencies()

Test that placed content blocks create a dependency in the block placement.

File

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

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
    ->drupalPostForm($url, $instance, t('Save block'));
  $dependencies = \Drupal::service('config.manager')
    ->findConfigEntityDependentsAsEntities('content', [
    $block
      ->getConfigDependencyName(),
  ]);
  $block_placement = reset($dependencies);
  $this
    ->assertEqual($block_placement_id, $block_placement
    ->id(), "The block placement config entity has a dependency on the block content entity.");
}