function ConfigActionsTest::testPlaceBlockInDynamicRegion

@testWith ["placeBlockInDefaultTheme", "olivero", "header"]
["placeBlockInAdminTheme", "claro", "page_bottom"]

1 call to ConfigActionsTest::testPlaceBlockInDynamicRegion()
ConfigActionsTest::testPlaceBlockInDefaultRegion in core/modules/block/tests/src/Kernel/ConfigActionsTest.php
Tests placing a block in the default theme's region.

File

core/modules/block/tests/src/Kernel/ConfigActionsTest.php, line 107

Class

ConfigActionsTest
@covers \Drupal\block\Plugin\ConfigAction\PlaceBlock[[api-linebreak]] @covers \Drupal\block\Plugin\ConfigAction\PlaceBlockDeriver[[api-linebreak]] @group block

Namespace

Drupal\Tests\block\Kernel

Code

public function testPlaceBlockInDynamicRegion(string $action, string $expected_theme, string $expected_region) : void {
  $this->configActionManager
    ->applyAction($action, 'block.block.test_block', [
    'plugin' => 'system_powered_by_block',
    'region' => [
      'olivero' => 'header',
      'claro' => 'page_bottom',
    ],
    'default_region' => 'content',
  ]);
  $block = Block::load('test_block');
  $this->assertInstanceOf(Block::class, $block);
  $this->assertSame('system_powered_by_block', $block->getPluginId());
  $this->assertSame($expected_theme, $block->getTheme());
  $this->assertSame($expected_region, $block->getRegion());
  $this->expectException(ConfigActionException::class);
  $this->expectExceptionMessage('Cannot determine which region to place this block into, because no default region was provided.');
  $this->configActionManager
    ->applyAction($action, 'block.block.no_region', [
    'plugin' => 'system_powered_by_block',
    'region' => [],
  ]);
}

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