public function FixtureContext::setUp in Lightning Core 8.3
Same name and namespace in other branches
- 8.5 tests/src/FixtureContext.php \Drupal\Tests\lightning_core\FixtureContext::setUp()
- 8.4 tests/src/FixtureContext.php \Drupal\Tests\lightning_core\FixtureContext::setUp()
@BeforeScenario
File
- tests/
src/ FixtureContext.php, line 18
Class
- FixtureContext
- Performs set-up and tear-down tasks before and after test scenarios.
Namespace
Drupal\Tests\lightning_coreCode
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();
}