function BlockTestBase::setUp

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTestBase.php \Drupal\Tests\block\Functional\BlockTestBase::setUp()
  2. 8.9.x core/modules/block/src/Tests/BlockTestBase.php \Drupal\block\Tests\BlockTestBase::setUp()
  3. 8.9.x core/modules/block/tests/src/Functional/BlockTestBase.php \Drupal\Tests\block\Functional\BlockTestBase::setUp()
  4. 11.x core/modules/block/tests/src/Functional/BlockTestBase.php \Drupal\Tests\block\Functional\BlockTestBase::setUp()

Overrides BrowserTestBase::setUp

1 call to BlockTestBase::setUp()
BlockSystemBrandingTest::setUp in core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php
1 method overrides BlockTestBase::setUp()
BlockSystemBrandingTest::setUp in core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php

File

core/modules/block/tests/src/Functional/BlockTestBase.php, line 43

Class

BlockTestBase
Provides setup and helper methods for block module tests.

Namespace

Drupal\Tests\block\Functional

Code

protected function setUp() : void {
  parent::setUp();
  // Use the test page as the front page.
  $this->config('system.site')
    ->set('page.front', '/test-page')
    ->save();
  // Create Full HTML text format.
  $full_html_format = FilterFormat::create([
    'format' => 'full_html',
    'name' => 'Full HTML',
  ]);
  $full_html_format->save();
  // Create and log in an administrative user having access to the Full HTML
  // text format.
  $this->adminUser = $this->drupalCreateUser([
    'administer blocks',
    $full_html_format->getPermissionName(),
    'access administration pages',
  ]);
  $this->drupalLogin($this->adminUser);
  // Define the existing regions.
  $this->regions = [
    'header',
    'sidebar_first',
    'content',
    'sidebar_second',
    'footer',
  ];
  $block_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('block');
  $blocks = $block_storage->loadByProperties([
    'theme' => $this->config('system.theme')
      ->get('default'),
  ]);
  foreach ($blocks as $block) {
    $block->delete();
  }
}

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