function BlockTest::testBlockThemeSelector

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockThemeSelector()
  2. 10 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockThemeSelector()
  3. 11.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockThemeSelector()

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

File

core/modules/block/tests/src/Functional/BlockTest.php, line 250

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockThemeSelector() {
    // Install all themes.
    \Drupal::service('theme_installer')->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('Block layout | Drupal');
        // Select the 'Powered by Drupal' block to be placed.
        $block = [];
        $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]', [
            ':id' => Html::getUniqueId('block-' . $block['id']),
        ]);
        $this->assertTrue(!empty($elements), 'The block was found.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.