function BlockTest::testBlockThemeSelector

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

Tests that the block form has a theme selector when not passed via the URL.

File

core/modules/block/tests/src/Functional/BlockTest.php, line 270

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockThemeSelector() {
    // Install all themes.
    $themes = [
        'olivero',
        'claro',
        'stark',
    ];
    \Drupal::service('theme_installer')->install($themes);
    $theme_settings = $this->config('system.theme');
    foreach ($themes as $theme) {
        $this->drupalGet('admin/structure/block/list/' . $theme);
        $this->assertSession()
            ->titleEquals('Block layout | Drupal');
        // Select the 'Powered by Drupal' block to be placed.
        $block = [];
        $block['id'] = strtolower($this->randomMachineName());
        $block['theme'] = $theme;
        $block['region'] = 'content';
        $this->drupalGet('admin/structure/block/add/system_powered_by_block');
        $this->submitForm($block, 'Save block');
        $this->assertSession()
            ->statusMessageContains('The block configuration has been saved.', 'status');
        $this->assertSession()
            ->addressEquals('admin/structure/block/list/' . $theme . '?block-placement=' . Html::getClass($block['id']));
        // Set the default theme and ensure the block is placed.
        $theme_settings->set('default', $theme)
            ->save();
        $this->drupalGet('');
        $block_id = Html::getUniqueId('block-' . $block['id']);
        $this->assertSession()
            ->elementExists('xpath', "//div[@id = '{$block_id}']");
    }
}

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