You are here

final class FixtureContext in Lightning Core 8.5

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

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

Hierarchy

  • class \Drupal\Tests\lightning_core\FixtureBase implements \Behat\Behat\Context\Context, \Symfony\Component\DependencyInjection\ContainerAwareInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait

Expanded class hierarchy of FixtureContext

File

tests/src/FixtureContext.php, line 12

Namespace

Drupal\Tests\lightning_core
View source
final class FixtureContext extends FixtureBase {

  /**
   * Performs set-up tasks before a test scenario.
   *
   * @BeforeScenario
   */
  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);
  }

  /**
   * Performs tear-down tasks after a test scenario.
   *
   * @AfterScenario
   */
  public function tearDown() {

    // This pointless if statement is here to evade a too-strict coding
    // standards rule.
    if (TRUE) {
      parent::tearDown();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FixtureBase::$config private property Raw configuration data to be restored after the scenario, keyed by ID.
FixtureBase::$entities private property Entities to be automatically deleted after the scenario.
FixtureBase::$modules private property Modules installed during the scenario.
FixtureBase::$themes private property Themes installed during the scenario.
FixtureBase::$trackedEntityTypes private property Entity types for which to delete all content created by the current users.
FixtureBase::$userManager private property The Drupal Extension's user manager.
FixtureBase::$users private property The Drupal user IDs that were logged in during the scenario.
FixtureBase::clearUserContent private function Deletes all content created by the current users.
FixtureBase::config protected function Returns a config object and caches its data for automatic restoration.
FixtureBase::installModule protected function Installs a module if not already present.
FixtureBase::installTheme protected function Installs a theme if not already present.
FixtureBase::resetContainer protected function Updates the container.
FixtureBase::save protected function Saves an entity and marks it for automatic deletion.
FixtureBase::setCurrentUser public function Records the current Drupal user ID if possible.
FixtureBase::trackUserContent public function Marks content by the current user to be deleted after the scenario.
FixtureBase::__construct public function FixtureBase constructor.
FixtureContext::setUp public function Performs set-up tasks before a test scenario.
FixtureContext::tearDown public function Performs tear-down tasks after a test scenario. Overrides FixtureBase::tearDown