public function BlockGroupTest::testBlockGroupDisplay in Block Group 8
Tests creating a block group programmatically.
Throws
\Behat\Mink\Exception\ResponseTextException
\Behat\Mink\Exception\ElementNotFoundException
\Behat\Mink\Exception\ExpectationException
File
- tests/
src/ Functional/ BlockGroupTest.php, line 99
Class
- BlockGroupTest
- Tests the access of block groups and CRUD.
Namespace
Drupal\Tests\blockgroup\FunctionalCode
public function testBlockGroupDisplay() {
$this
->drupalLogin($this->rootUser);
$theme = $this
->config('system.theme')
->get('default');
// Create a block group..
$blockgroup_label = 'TestBlockGroup';
$blockgroup_machine_name = 'block_group_test';
$block_group = [
'label' => $blockgroup_label,
'id' => $blockgroup_machine_name,
];
$this
->drupalPostForm('/admin/structure/block_group_content/add', $block_group, $this
->t('Save'));
// Check if the created blockgroup is in the list.
$this
->drupalGet('/admin/structure/block_group_content');
$this
->assertSession()
->pageTextContains($blockgroup_machine_name);
// Check if the region for the created blockgroup is in on the block page.
$this
->drupalGet("admin/structure/block/list/{$theme}");
$this
->assertSession()
->pageTextContains("Block group: {$blockgroup_label}");
// Place a block in that region.
$block_label = 'BlockInBlockGroup';
$block_id = 'block_in_block_group';
$block = [];
$block['id'] = $block_id;
$block['theme'] = $theme;
$block['region'] = $blockgroup_machine_name;
$block['settings[label]'] = $block_label;
$block['settings[label_display]'] = TRUE;
$this
->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, $this
->t('Save block'));
$this
->assertSession()
->addressEquals("admin/structure/block/list/{$theme}?block-placement=" . Html::getClass($block['id']));
// Check that the block is not visible on the front page.
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($block_label);
// Place the block group's block in the sidebar.
$group_block_label = 'TheGroupBlock';
$group_block = [];
$group_block['id'] = 'the_group_block';
$group_block['theme'] = $theme;
$group_block['region'] = 'content';
$group_block['settings[label]'] = $group_block_label;
$group_block['settings[label_display]'] = TRUE;
$this
->drupalPostForm("admin/structure/block/add/block_group:{$blockgroup_machine_name}", $group_block, $this
->t('Save block'));
$this
->assertSession()
->addressEquals("admin/structure/block/list/{$theme}?block-placement=" . Html::getClass($group_block['id']));
// Check that the block is visible on the front page.
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($block_label);
}