public function BlockTest::testBlockThemeSelector in Drupal 9
Same name and namespace in other branches
- 8 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 268
Class
- BlockTest
- Tests basic block functionality.
Namespace
Drupal\Tests\block\FunctionalCode
public function testBlockThemeSelector() {
// Install all themes.
\Drupal::service('theme_installer')
->install([
'bartik',
'seven',
'stark',
]);
$theme_settings = $this
->config('system.theme');
foreach ([
'bartik',
'seven',
'stark',
] 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()
->pageTextContains('The block configuration has been saved.');
$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}']");
}
}