Chris@0: drupalCreateUser([ Chris@0: 'administer site configuration', Chris@0: 'access administration pages', Chris@0: 'administer blocks', Chris@0: ]); Chris@0: $this->drupalLogin($admin_user); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that blocks assigned to invalid regions work correctly. Chris@0: */ Chris@0: public function testBlockInInvalidRegion() { Chris@0: // Enable a test block and place it in an invalid region. Chris@0: $block = $this->drupalPlaceBlock('test_html'); Chris@0: \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save(); Chris@0: $block = Block::load($block->id()); Chris@0: Chris@0: $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block->id(), '%region' => 'invalid_region']); Chris@0: Chris@0: // Clearing the cache should disable the test block placed in the invalid region. Chris@0: $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches'); Chris@0: $this->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.'); Chris@0: Chris@0: // Clear the cache to check if the warning message is not triggered. Chris@0: $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches'); Chris@0: $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.'); Chris@0: Chris@0: // Place disabled test block in the invalid region of the default theme. Chris@0: \Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save(); Chris@0: $block = Block::load($block->id()); Chris@0: Chris@0: // Clear the cache to check if the warning message is not triggered. Chris@0: $this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches'); Chris@0: $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.'); Chris@0: } Chris@0: Chris@0: }