function BlockTestBase::setUp

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in Drupal\simpletest\WebTestBase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php, line 38
Contains \Drupal\block\Tests\BlockTestBase.

Class

BlockTestBase
Provides setup and helper methods for block module tests.

Namespace

Drupal\block\Tests

Code

function setUp() {
  parent::setUp();

  // Use the test page as the front page.
  config('system.site')
    ->set('page.front', 'test-page')
    ->save();

  // Create Full HTML text format.
  $full_html_format = entity_create('filter_format', array(
    'format' => 'full_html',
    'name' => 'Full HTML',
  ));
  $full_html_format
    ->save();
  $this
    ->checkPermissions(array(), TRUE);

  // Create and log in an administrative user having access to the Full HTML
  // text format.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'administer blocks',
    filter_permission_name($full_html_format),
    'access administration pages',
  ));
  $this
    ->drupalLogin($this->adminUser);

  // Define the existing regions.
  $this->regions = array(
    'header',
    'sidebar_first',
    'content',
    'sidebar_second',
    'footer',
  );
  $default_theme = variable_get('theme_default', 'stark');
  $manager = $this->container
    ->get('plugin.manager.block');
  $instances = config_get_storage_names_with_prefix('plugin.core.block.' . $default_theme);
  foreach ($instances as $plugin_id) {
    config($plugin_id)
      ->delete();
  }
}