You are here

public function BlockUiTest::testBrokenBlockVisibility in Drupal 9

Tests that users without permission are not able to view broken blocks.

File

core/modules/block/tests/src/Functional/BlockUiTest.php, line 390

Class

BlockUiTest
Tests that the block configuration UI exists and stores data correctly.

Namespace

Drupal\Tests\block\Functional

Code

public function testBrokenBlockVisibility() {
  $assert_session = $this
    ->assertSession();
  $block = $this
    ->drupalPlaceBlock('broken');

  // Ensure that broken block configuration can be accessed.
  $this
    ->drupalGet('admin/structure/block/manage/' . $block
    ->id());
  $assert_session
    ->statusCodeEquals(200);

  // Login as an admin user to the site.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('');
  $assert_session
    ->statusCodeEquals(200);

  // Check that this user can view the Broken Block message.
  $assert_session
    ->pageTextContains('This block is broken or missing. You may be missing content or you might need to enable the original module.');
  $this
    ->drupalLogout();

  // Visit the same page as anonymous.
  $this
    ->drupalGet('');
  $assert_session
    ->statusCodeEquals(200);

  // Check that this user cannot view the Broken Block message.
  $assert_session
    ->pageTextNotContains('This block is broken or missing. You may be missing content or you might need to enable the original module.');

  // Visit same page as an authorized user that does not have access to
  // administer blocks.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access administration pages',
  ]));
  $this
    ->drupalGet('');
  $assert_session
    ->statusCodeEquals(200);

  // Check that this user cannot view the Broken Block message.
  $assert_session
    ->pageTextNotContains('This block is broken or missing. You may be missing content or you might need to enable the original module.');
}