You are here

public function BlockTest::testBlockThemeSelector in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block/src/Tests/BlockTest.php \Drupal\block\Tests\BlockTest::testBlockThemeSelector()

Tests that the block form has a theme selector when not passed via the URL.

File

core/modules/block/src/Tests/BlockTest.php, line 198
Contains \Drupal\block\Tests\BlockTest.

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\block\Tests

Code

public function testBlockThemeSelector() {

  // Install all themes.
  \Drupal::service('theme_handler')
    ->install([
    'bartik',
    'seven',
    'stark',
  ]);
  $theme_settings = $this
    ->config('system.theme');
  foreach ([
    'bartik',
    'seven',
    'stark',
  ] as $theme) {
    $this
      ->drupalGet('admin/structure/block/list/' . $theme);
    $this
      ->assertTitle(t('Block layout') . ' | Drupal');

    // Select the 'Powered by Drupal' block to be placed.
    $block = array();
    $block['id'] = strtolower($this
      ->randomMachineName());
    $block['theme'] = $theme;
    $block['region'] = 'content';
    $this
      ->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
    $this
      ->assertText(t('The block configuration has been saved.'));
    $this
      ->assertUrl('admin/structure/block/list/' . $theme . '?block-placement=' . Html::getClass($block['id']));

    // Set the default theme and ensure the block is placed.
    $theme_settings
      ->set('default', $theme)
      ->save();
    $this
      ->drupalGet('');
    $elements = $this
      ->xpath('//div[@id = :id]', array(
      ':id' => Html::getUniqueId('block-' . $block['id']),
    ));
    $this
      ->assertTrue(!empty($elements), 'The block was found.');
  }
}