function BlockUiTest::testBrokenBlockVisibility

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testBrokenBlockVisibility()
  2. 11.x core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testBrokenBlockVisibility()

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

File

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

Class

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

Namespace

Drupal\Tests\block\Functional

Code

public function testBrokenBlockVisibility() : void {
    $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 install 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 install 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 install the original module.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.