function BlockTest::moveBlockToRegion

Moves a block to a given region via the UI and confirms the result.

Parameters

array $block: An array of information about the block, including the following keys:

  • module: The module providing the block.
  • title: The title of the block.
  • delta: The block's delta key.

string $region: The machine name of the theme region to move the block to, for example 'header' or 'sidebar_first'.

5 calls to BlockTest::moveBlockToRegion()
BlockTest::testBlock in drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
Test configuring and moving a module-define block to specific regions.
BlockTest::testBlockVisibility in drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
Test block visibility.
BlockTest::testBlockVisibilityListedEmpty in drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
Test block visibility when using "pages" restriction but leaving "pages" textarea empty
BlockTest::testBlockVisibilityPerUser in drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
Test user customization of block visibility.
BlockTest::testCustomBlock in drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
Test creating custom block, moving it to a specific region and then deleting it.

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php, line 381
Definition of Drupal\block\Tests\BlockTest.

Class

BlockTest

Namespace

Drupal\block\Tests

Code

function moveBlockToRegion(array $block, $region) {

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

  // Confirm that the block is being displayed.
  $this
    ->drupalGet('');
  $this
    ->assertText(t($block['title']), '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 region-' . str_replace('_', '-', $region),
    ':block-id' => 'block-' . $block['module'] . '-' . $block['delta'],
  ));
  $this
    ->assertFieldByXPath($xpath, NULL, format_string('Custom block found in %region_name region.', array(
    '%region_name' => $region,
  )));
}