function BlockTest::moveBlockToRegion
Same name in other branches
- 8.9.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::moveBlockToRegion()
- 10 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::moveBlockToRegion()
- 11.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::moveBlockToRegion()
Moves a block to a given region via the UI and confirms the result.
Parameters
array $block: An array of information about the block, including the following keys:
- module: The module providing the block.
- title: The title of the block.
- delta: The block's delta key.
string $region: The machine name of the theme region to move the block to, for example 'header' or 'sidebar_first'.
1 call to BlockTest::moveBlockToRegion()
- BlockTest::testBlock in core/
modules/ block/ tests/ src/ Functional/ BlockTest.php - Tests configuring and moving a module-define block to specific regions.
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockTest.php, line 366
Class
- BlockTest
- Tests basic block functionality.
Namespace
Drupal\Tests\block\FunctionalCode
public function moveBlockToRegion(array $block, $region) {
// Set the created block to a specific region.
$block += [
'theme' => $this->config('system.theme')
->get('default'),
];
$edit = [];
$edit['blocks[' . $block['id'] . '][region]'] = $region;
$this->drupalGet('admin/structure/block');
$this->submitForm($edit, 'Save blocks');
// Confirm that the block was moved to the proper region.
$this->assertSession()
->statusMessageContains('The block settings have been updated.', 'status');
// Confirm that the block is being displayed.
$this->drupalGet('');
$this->assertSession()
->pageTextContains($block['settings[label]']);
$region_xpath = [
'header' => '//header[@role = "banner"]',
'sidebar_first' => '//aside[contains(@class, "layout-sidebar-first")]',
'content' => '//div[contains(@class, "layout-content")]',
'sidebar_second' => '//aside[contains(@class, "layout-sidebar-second")]',
'footer' => '//footer[@role = "contentinfo"]',
];
// Confirm that the custom block was found at the proper region.
$xpath = $this->assertSession()
->buildXPathQuery($region_xpath[$region] . '//div[@id=:block-id]/*', [
':block-id' => 'block-' . str_replace('_', '-', strtolower($block['id'])),
]);
$this->assertSession()
->elementExists('xpath', $xpath);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.