class BlockInvalidRegionTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest
- 9 core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php \Drupal\Tests\block\Functional\BlockInvalidRegionTest
Tests that an active block assigned to a non-existing region triggers the warning message and is disabled.
@group block
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait- class \Drupal\Tests\block\Functional\BlockInvalidRegionTest
 
Expanded class hierarchy of BlockInvalidRegionTest
File
- core/modules/ block/ tests/ src/ Functional/ BlockInvalidRegionTest.php, line 14 
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';
  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');
  }
}