function BlockInvalidRegionTest::testBlockInInvalidRegion
Same name in other branches
- 8.9.x core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest::testBlockInInvalidRegion()
- 10 core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest::testBlockInInvalidRegion()
- 11.x core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest::testBlockInInvalidRegion()
Tests that blocks assigned to invalid regions work correctly.
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockInvalidRegionTest.php, line 44
Class
- BlockInvalidRegionTest
- Tests that blocks assigned to invalid regions are disabled with a warning.
Namespace
Drupal\Tests\block\FunctionalCode
public function testBlockInInvalidRegion() {
// Enable a test block and place it in an invalid region.
$block = $this->drupalPlaceBlock('test_html');
\Drupal::configFactory()->getEditable('block.block.' . $block->id())
->set('region', 'invalid_region')
->save();
$block = Block::load($block->id());
$warning_message = 'The block ' . $block->id() . ' was assigned to the invalid region invalid_region and has been disabled.';
// Clearing the cache should disable the test block placed in the invalid region.
$this->drupalGet('admin/config/development/performance');
$this->submitForm([], 'Clear all caches');
$this->assertSession()
->statusMessageContains($warning_message, 'warning');
// Clear the cache to check if the warning message is not triggered.
$this->drupalGet('admin/config/development/performance');
$this->submitForm([], 'Clear all caches');
$this->assertSession()
->statusMessageNotContains($warning_message, 'warning');
// Place disabled test block in the invalid region of the default theme.
\Drupal::configFactory()->getEditable('block.block.' . $block->id())
->set('region', 'invalid_region')
->save();
$block = Block::load($block->id());
// Clear the cache to check if the warning message is not triggered.
$this->drupalGet('admin/config/development/performance');
$this->submitForm([], 'Clear all caches');
$this->assertSession()
->statusMessageNotContains($warning_message, 'warning');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.