You are here

final class FixtureContext in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.5 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

1 string reference to 'FixtureContext'
behat.yml in ./behat.yml
behat.yml

File

tests/src/FixtureContext.php, line 13

Namespace

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

  /**
   * @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);
    $this
      ->installModule('views');
    if ($this
      ->installModule('lightning_search')) {

      /** @var \Drupal\search_api\IndexInterface $index */
      $index = Index::load('content');
      $dependencies = $index
        ->getDependencies();
      $dependencies['enforced']['module'][] = 'lightning_search';
      $index
        ->set('dependencies', $dependencies)
        ->save();
    }

    /** @var \Drupal\block\BlockInterface $block */
    if (!Block::load('seven_search')) {
      $block = Block::create([
        'id' => 'seven_search',
        'theme' => 'seven',
        'region' => 'content',
        'plugin' => 'views_exposed_filter_block:search-page',
      ])
        ->setVisibilityConfig('request_path', [
        'pages' => '/search',
      ]);
      $this
        ->save($block);
    }
    $this
      ->config('views.view.search')
      ->set('display.default.display_options.cache', [
      'type' => 'none',
      'options' => [],
    ])
      ->save();
  }

  /**
   * @AfterScenario
   */
  public function tearDown() {
    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 @BeforeScenario
FixtureContext::tearDown public function @AfterScenario Overrides FixtureBase::tearDown