You are here

protected function WebTestBase::drupalPlaceBlock in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/WebTestBase.php \Drupal\simpletest\WebTestBase::drupalPlaceBlock()

Creates a block instance based on default settings.

@todo Add support for creating custom block instances.

Parameters

string $plugin_id: The plugin ID of the block type for this block instance.

array $settings: (optional) An associative array of settings for the block entity. Override the defaults by specifying the key and value in the array, for example:

$this
  ->drupalPlaceBlock('system_powered_by_block', array(
  'label' => t('Hello, world!'),
));

The following defaults are provided:

  • label: Random string.
  • ID: Random string.
  • region: 'sidebar_first'.
  • theme: The default theme.
  • visibility: Empty array.

Return value

\Drupal\block\Entity\Block The block entity.

165 calls to WebTestBase::drupalPlaceBlock()
AccessDeniedTest::setUp in core/modules/system/src/Tests/System/AccessDeniedTest.php
Sets up a Drupal site for running functional and integration tests.
AccessDeniedTest::testAccessDenied in core/modules/system/src/Tests/System/AccessDeniedTest.php
AccessTestBase::setUp in core/modules/user/src/Tests/Views/AccessTestBase.php
Sets up a Drupal site for running functional and integration tests.
AddFeedTest::setUp in core/modules/aggregator/src/Tests/AddFeedTest.php
Sets up a Drupal site for running functional and integration tests.
AggregatorRenderingTest::setUp in core/modules/aggregator/src/Tests/AggregatorRenderingTest.php
Sets up a Drupal site for running functional and integration tests.

... See full list

File

core/modules/simpletest/src/WebTestBase.php, line 420
Contains \Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function drupalPlaceBlock($plugin_id, array $settings = array()) {
  $settings += array(
    'plugin' => $plugin_id,
    'region' => 'sidebar_first',
    'id' => strtolower($this
      ->randomMachineName(8)),
    'theme' => $this
      ->config('system.theme')
      ->get('default'),
    'label' => $this
      ->randomMachineName(8),
    'visibility' => array(),
    'weight' => 0,
  );
  $values = [];
  foreach (array(
    'region',
    'id',
    'theme',
    'plugin',
    'weight',
    'visibility',
  ) as $key) {
    $values[$key] = $settings[$key];

    // Remove extra values that do not belong in the settings array.
    unset($settings[$key]);
  }
  foreach ($values['visibility'] as $id => $visibility) {
    $values['visibility'][$id]['id'] = $id;
  }
  $values['settings'] = $settings;
  $block = entity_create('block', $values);
  $block
    ->save();
  return $block;
}