function BlockUiTest::testBlockDemoUiPage

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

Tests block demo page exists and functions correctly.

File

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

Class

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

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockDemoUiPage() {
    $this->drupalPlaceBlock('help_block', [
        'region' => 'help',
    ]);
    $this->drupalGet('admin/structure/block');
    $this->clickLink('Demonstrate block regions (Stark)');
    $this->assertSession()
        ->elementExists('xpath', '//header[@role = "banner"]/div/div[contains(@class, "block-region") and contains(text(), "Header")]');
    // Ensure that other themes can use the block demo page.
    \Drupal::service('theme_installer')->install([
        'test_theme',
    ]);
    $this->drupalGet('admin/structure/block/demo/test_theme');
    $this->assertSession()
        ->assertEscaped('<strong>Test theme</strong>');
    // Ensure that a hidden theme cannot use the block demo page.
    \Drupal::service('theme_installer')->install([
        'stable9',
    ]);
    $this->drupalGet('admin/structure/block/demo/stable9');
    $this->assertSession()
        ->statusCodeEquals(404);
    // Delete all blocks and verify saving the block layout results in a
    // validation error.
    $block_storage = \Drupal::service('entity_type.manager')->getStorage('block');
    $blocks = $block_storage->loadMultiple();
    foreach ($blocks as $block) {
        $block->delete();
    }
    $this->drupalGet('admin/structure/block');
    $blocks_table = $this->xpath("//tr[@class='block-enabled']");
    $this->assertEmpty($blocks_table, 'The blocks table is now empty.');
    $this->submitForm([], 'Save blocks');
    $this->assertSession()
        ->pageTextContains('No blocks settings to update');
}

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