public function BlockTest::testBlockThemeSelector in Drupal 10
Same name and namespace in other branches
- 8 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockThemeSelector()
- 9 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\FunctionalCode
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}']");
}
}