public function TypeBoostTest::setUp in Search API 8
Performs setup tasks before each individual test method is run.
Installs commonly used schemas and sets up a search server and an index, with the specified processor enabled.
Parameters
string|null $processor: (optional) The plugin ID of the processor that should be set up for testing.
Overrides ProcessorTestBase::setUp
File
- tests/
src/ Kernel/ Processor/ TypeBoostTest.php, line 30
Class
- TypeBoostTest
- Tests the "Type-specific boosting" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function setUp($processor = NULL) {
parent::setUp('type_boost');
// Create an article node type, if not already present.
if (!NodeType::load('article')) {
$article_node_type = NodeType::create([
'type' => 'article',
'name' => 'Article',
]);
$article_node_type
->save();
}
// Create a page node type, if not already present.
if (!NodeType::load('page')) {
$page_node_type = NodeType::create([
'type' => 'page',
'name' => 'Page',
]);
$page_node_type
->save();
}
// Setup a node index.
$datasources = \Drupal::getContainer()
->get('search_api.plugin_helper')
->createDatasourcePlugins($this->index, [
'entity:node',
]);
$this->index
->setDatasources($datasources);
$this->index
->save();
$this->container
->get('search_api.index_task_manager')
->addItemsAll($this->index);
$index_storage = $this->container
->get('entity_type.manager')
->getStorage('search_api_index');
$index_storage
->resetCache([
$this->index
->id(),
]);
$this->index = $index_storage
->load($this->index
->id());
}