BlockInvalidRegionTest.php in Drupal 8
File
core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php
View source
<?php
namespace Drupal\Tests\block\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\block\Entity\Block;
class BlockInvalidRegionTest extends BrowserTestBase {
public static $modules = [
'block',
'block_test',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'access administration pages',
'administer blocks',
]);
$this
->drupalLogin($admin_user);
}
public function testBlockInInvalidRegion() {
$block = $this
->drupalPlaceBlock('test_html');
\Drupal::configFactory()
->getEditable('block.block.' . $block
->id())
->set('region', 'invalid_region')
->save();
$block = Block::load($block
->id());
$warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', [
'%info' => $block
->id(),
'%region' => 'invalid_region',
]);
$this
->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
$this
->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.');
$this
->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
$this
->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
\Drupal::configFactory()
->getEditable('block.block.' . $block
->id())
->set('region', 'invalid_region')
->save();
$block = Block::load($block
->id());
$this
->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
$this
->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
}
}
Classes
Name |
Description |
BlockInvalidRegionTest |
Tests that an active block assigned to a non-existing region triggers the
warning message and is disabled. |