You are here

public function BlockTest::moveBlockToRegion in MongoDB 7

Move block to a region.

3 calls to BlockTest::moveBlockToRegion()
BlockTest::testBlock in mongodb_block_ui/src/Tests/BlockTest.php
Test configuring and moving a module-define block to specific regions.
BlockTest::testBlockVisibility in mongodb_block_ui/src/Tests/BlockTest.php
Test block visibility.
BlockTest::testCustomBlock in mongodb_block_ui/src/Tests/BlockTest.php
Test creating custom block, moving it to a region and then deleting it.

File

mongodb_block_ui/src/Tests/BlockTest.php, line 266

Class

BlockTest
Class BlockTest.

Namespace

Drupal\mongodb_block_ui\Tests

Code

public function moveBlockToRegion($block, $region) {

  // If an id for an region hasn't been specified, we assume it's the same as
  // the name.
  if (!isset($region['class'])) {
    $region['class'] = 'region region-' . str_replace('_', '-', $region['name']);
  }

  // Set the created block to a specific region.
  $edit = array();
  $edit[$block['module'] . '_' . $block['delta'] . '[region]'] = $region['name'];
  $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 moved to %region_name region.', array(
    '%region_name' => $region['name'],
  )));

  // Confirm that the block is being displayed.
  $this
    ->drupalGet('node');
  $this
    ->assertText(t($block['title']), t('Block successfully being displayed on the page.'));

  // Confirm that the custom block was found at the proper region.
  $xpath = $this
    ->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
    ':region-class' => $region['class'],
    ':block-id' => 'block-' . $block['module'] . '-' . $block['delta'],
  ));
  $this
    ->assertFieldByXPath($xpath, FALSE, t('Custom block found in %region_name region.', array(
    '%region_name' => $region['name'],
  )));
}