public function BlockPlaceTest::testPlacingBlocksAdmin in Drupal 8
Tests placing blocks as an admin.
File
- core/
modules/ block_place/ tests/ src/ Functional/ BlockPlaceTest.php, line 31
Class
- BlockPlaceTest
- Tests the placing a block.
Namespace
Drupal\Tests\block_place\FunctionalCode
public function testPlacingBlocksAdmin() {
// Create administrative user.
$this
->drupalLogin($this
->drupalCreateUser([
'access administration pages',
'access toolbar',
'administer blocks',
'view the administration theme',
]));
$this
->drupalGet(Url::fromRoute('<front>'));
$this
->clickLink('Place block');
// Each region should have one link to place a block.
$theme_name = $this->container
->get('theme.manager')
->getActiveTheme()
->getName();
$visible_regions = system_region_list($theme_name, REGIONS_VISIBLE);
$this
->assertGreaterThan(0, count($visible_regions));
$default_theme = $this
->config('system.theme')
->get('default');
$block_library_url = Url::fromRoute('block.admin_library', [
'theme' => $default_theme,
]);
foreach ($visible_regions as $region => $name) {
$block_library_url
->setOption('query', [
'region' => $region,
]);
$links = $this
->xpath('//a[contains(@href, :href)]', [
':href' => $block_library_url
->toString(),
]);
$this
->assertCount(1, $links);
list(, $query_string) = explode('?', $links[0]
->getAttribute('href'), 2);
parse_str($query_string, $query_parts);
$this
->assertNotEmpty($query_parts['destination']);
// Get the text inside the div->a->span->em.
$demo_block = $this
->xpath('//div[@class="block-place-region"]/a/span[text()="Place block in the "]/em[text()="' . $name . '"]');
$this
->assertCount(1, $demo_block);
}
}