function BlockUiTest::testBlockAdminUiPage in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block/src/Tests/BlockUiTest.php \Drupal\block\Tests\BlockUiTest::testBlockAdminUiPage()
Test block admin page exists and functions correctly.
File
- core/
modules/ block/ src/ Tests/ BlockUiTest.php, line 102 - Contains \Drupal\block\Tests\BlockUiTest.
Class
- BlockUiTest
- Tests that the block configuration UI exists and stores data correctly.
Namespace
Drupal\block\TestsCode
function testBlockAdminUiPage() {
// Visit the blocks admin ui.
$this
->drupalGet('admin/structure/block');
// Look for the blocks table.
$blocks_table = $this
->xpath("//table[@id='blocks']");
$this
->assertTrue(!empty($blocks_table), 'The blocks table is being rendered.');
// Look for test blocks in the table.
foreach ($this->blockValues as $delta => $values) {
$block = $this->blocks[$delta];
$label = $block
->label();
$element = $this
->xpath('//*[@id="blocks"]/tbody/tr[' . $values['tr'] . ']/td[1]/text()');
$this
->assertTrue((string) $element[0] == $label, 'The "' . $label . '" block title is set inside the ' . $values['settings']['region'] . ' region.');
// Look for a test block region select form element.
$this
->assertField('blocks[' . $values['settings']['id'] . '][region]', 'The block "' . $values['label'] . '" has a region assignment field.');
// Move the test block to the header region.
$edit['blocks[' . $values['settings']['id'] . '][region]'] = 'header';
// Look for a test block weight select form element.
$this
->assertField('blocks[' . $values['settings']['id'] . '][weight]', 'The block "' . $values['label'] . '" has a weight assignment field.');
// Change the test block's weight.
$edit['blocks[' . $values['settings']['id'] . '][weight]'] = $values['test_weight'];
}
$this
->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));
foreach ($this->blockValues as $values) {
// Check if the region and weight settings changes have persisted.
$this
->assertOptionSelected('edit-blocks-' . $values['settings']['id'] . '-region', 'header', 'The block "' . $label . '" has the correct region assignment (header).');
$this
->assertOptionSelected('edit-blocks-' . $values['settings']['id'] . '-weight', $values['test_weight'], 'The block "' . $label . '" has the correct weight assignment (' . $values['test_weight'] . ').');
}
// Add a block with a machine name the same as a region name.
$this
->drupalPlaceBlock('system_powered_by_block', [
'region' => 'header',
'id' => 'header',
]);
$this
->drupalGet('admin/structure/block');
$element = $this
->xpath('//tr[contains(@class, :class)]', [
':class' => 'region-title-header',
]);
$this
->assertTrue(!empty($element));
// Ensure hidden themes do not appear in the UI. Enable another non base
// theme and place the local tasks block.
$this
->assertTrue(\Drupal::service('theme_handler')
->themeExists('classy'), 'The classy base theme is enabled');
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'header',
]);
\Drupal::service('theme_installer')
->install([
'stable',
'stark',
]);
$this
->drupalGet('admin/structure/block');
$theme_handler = \Drupal::service('theme_handler');
$this
->assertLink($theme_handler
->getName('classy'));
$this
->assertLink($theme_handler
->getName('stark'));
$this
->assertNoLink($theme_handler
->getName('stable'));
$this
->drupalGet('admin/structure/block/list/stable');
$this
->assertResponse(404, 'Placing blocks through UI is not possible for a hidden base theme.');
\Drupal::configFactory()
->getEditable('system.theme')
->set('admin', 'stable')
->save();
\Drupal::service('router.builder')
->rebuildIfNeeded();
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'header',
'theme' => 'stable',
]);
$this
->drupalGet('admin/structure/block');
$this
->assertLink($theme_handler
->getName('stable'));
$this
->drupalGet('admin/structure/block/list/stable');
$this
->assertResponse(200, 'Placing blocks through UI is possible for a hidden base theme that is the admin theme.');
}