You are here

public function FixtureContext::setUp in Lightning Core 8.5

Same name and namespace in other branches
  1. 8.3 tests/src/FixtureContext.php \Drupal\Tests\lightning_core\FixtureContext::setUp()
  2. 8.4 tests/src/FixtureContext.php \Drupal\Tests\lightning_core\FixtureContext::setUp()

Performs set-up tasks before a test scenario.

@BeforeScenario

File

tests/src/FixtureContext.php, line 19

Class

FixtureContext
Performs set-up and tear-down tasks before and after test scenarios.

Namespace

Drupal\Tests\lightning_core

Code

public function setUp() {

  // Create the administrator role if it does not already exist.
  if (!Role::load('administrator')) {
    $role = Role::create([
      'id' => 'administrator',
      'label' => 'Administrator',
    ])
      ->setIsAdmin(TRUE);
    $this
      ->save($role);
  }

  // Install the Seven theme if not already installed.
  $this
    ->installTheme('seven');

  // Use Seven as both the default and administrative theme.
  $this
    ->config('system.theme')
    ->set('admin', 'seven')
    ->set('default', 'seven')
    ->save();

  // Place the main content block if it's not already there.
  if (!Block::load('seven_content')) {
    $block = Block::create([
      'id' => 'seven_content',
      'theme' => 'seven',
      'region' => 'content',
      'plugin' => 'system_main_block',
      'settings' => [
        'label_display' => '0',
      ],
    ]);
    $this
      ->save($block);
  }

  // Create a test content type to be automatically cleaned up at the end of
  // the scenario.
  $node_type = NodeType::create([
    'type' => 'test',
    'name' => 'Test',
  ]);
  $this
    ->save($node_type);
}