final class FixtureContext in Lightning Core 8.3
Same name and namespace in other branches
- 8.5 tests/src/FixtureContext.php \Drupal\Tests\lightning_core\FixtureContext
- 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
- class \Drupal\Tests\lightning_core\FixtureContext
Expanded class hierarchy of FixtureContext
File
- tests/
src/ FixtureContext.php, line 13
Namespace
Drupal\Tests\lightning_coreView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FixtureBase:: |
private | property | Raw configuration data to be restored after the scenario, keyed by ID. | |
FixtureBase:: |
private | property | Entities to be automatically deleted after the scenario. | |
FixtureBase:: |
private | property | Modules installed during the scenario. | |
FixtureBase:: |
private | property | Themes installed during the scenario. | |
FixtureBase:: |
private | property | Entity types for which to delete all content created by the current users. | |
FixtureBase:: |
private | property | The Drupal Extension's user manager. | |
FixtureBase:: |
private | property | The Drupal user IDs that were logged in during the scenario. | |
FixtureBase:: |
private | function | Deletes all content created by the current users. | |
FixtureBase:: |
protected | function | Returns a config object and caches its data for automatic restoration. | |
FixtureBase:: |
protected | function | Installs a module if not already present. | |
FixtureBase:: |
protected | function | Installs a theme if not already present. | |
FixtureBase:: |
protected | function | Updates the container. | |
FixtureBase:: |
protected | function | Saves an entity and marks it for automatic deletion. | |
FixtureBase:: |
public | function | Records the current Drupal user ID if possible. | |
FixtureBase:: |
public | function | Marks content by the current user to be deleted after the scenario. | |
FixtureBase:: |
public | function | FixtureBase constructor. | |
FixtureContext:: |
public | function | @BeforeScenario | |
FixtureContext:: |
public | function |
@AfterScenario Overrides FixtureBase:: |