public function BlockTest::testBlock in MongoDB 7
Test configuring and moving a module-define block to specific regions.
File
- mongodb_block_ui/
src/ Tests/ BlockTest.php, line 212
Class
- BlockTest
- Class BlockTest.
Namespace
Drupal\mongodb_block_ui\TestsCode
public function testBlock() {
// Select the Navigation block to be configured and moved.
$block = array();
$block['module'] = 'system';
$block['delta'] = 'management';
$block['title'] = $this
->randomName(8);
// Set block title to confirm that interface works and override any custom
// titles.
$this
->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', array(
'title' => $block['title'],
), t('Save block'));
$this
->assertText(t('The block configuration has been saved.'), t('Block title set.'));
$bid = db_query("SELECT bid FROM {block} WHERE module = :module AND delta = :delta", array(
':module' => $block['module'],
':delta' => $block['delta'],
))
->fetchField();
// Check to see if the block was created by checking that it's in the
// database.
$this
->assertNotNull($bid, t('Block found in database'));
// Check if the block can be moved to all availble regions.
foreach ($this->regions as $region) {
$this
->moveBlockToRegion($block, $region);
}
// Set the block to the disabled region.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = '-1';
$this
->drupalPost('admin/structure/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
$this
->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
$this
->assertNoText(t($block['title']), t('Block no longer appears on page.'));
// Confirm that the regions xpath is not available.
$xpath = $this
->buildXPathQuery('//div[@id=:id]/*', array(
':id' => 'block-block-' . $bid,
));
$this
->assertNoFieldByXPath($xpath, FALSE, t('Custom block found in no regions.'));
// For convenience of developers, put the navigation block back.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = $this->regions[1]['name'];
$this
->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this
->assertText(t('The block settings have been updated.'), t('Block successfully move to first sidebar region.'));
$this
->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', array(
'title' => 'Navigation',
), t('Save block'));
$this
->assertText(t('The block configuration has been saved.'), t('Block title set.'));
}