class BlockInvalidRegionTest
Same name and namespace in other branches
- 11.x core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest
- 10 core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest
- 8.9.x core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest
Tests that blocks assigned to invalid regions are disabled with a warning.
@group block
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\block\Functional\BlockInvalidRegionTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of BlockInvalidRegionTest
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockInvalidRegionTest.php, line 13
Namespace
Drupal\Tests\block\FunctionalView source
class BlockInvalidRegionTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'block',
'block_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create an admin user.
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'access administration pages',
'administer blocks',
]);
$this->drupalLogin($admin_user);
}
/**
* Tests that blocks assigned to invalid regions work correctly.
*/
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.