3 namespace Drupal\Tests\block\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\block\Entity\Block;
9 * Tests that an active block assigned to a non-existing region triggers the
10 * warning message and is disabled.
14 class BlockInvalidRegionTest extends BrowserTestBase {
21 public static $modules = ['block', 'block_test'];
23 protected function setUp() {
25 // Create an admin user.
26 $admin_user = $this->drupalCreateUser([
27 'administer site configuration',
28 'access administration pages',
31 $this->drupalLogin($admin_user);
35 * Tests that blocks assigned to invalid regions work correctly.
37 public function testBlockInInvalidRegion() {
38 // Enable a test block and place it in an invalid region.
39 $block = $this->drupalPlaceBlock('test_html');
40 \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
41 $block = Block::load($block->id());
43 $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block->id(), '%region' => 'invalid_region']);
45 // Clearing the cache should disable the test block placed in the invalid region.
46 $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
47 $this->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.');
49 // Clear the cache to check if the warning message is not triggered.
50 $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
51 $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
53 // Place disabled test block in the invalid region of the default theme.
54 \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
55 $block = Block::load($block->id());
57 // Clear the cache to check if the warning message is not triggered.
58 $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
59 $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');