public function LanguageKernelTest::setUp in Search API 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Datasource/ LanguageKernelTest.php, line 68
Class
- LanguageKernelTest
- Tests translation handling of the content entity datasource.
Namespace
Drupal\Tests\search_api\Kernel\DatasourceCode
public function setUp() {
parent::setUp();
// Enable translation for the entity_test module.
\Drupal::state()
->set('entity_test.translation', TRUE);
$this
->installSchema('search_api', [
'search_api_item',
]);
$this
->installEntitySchema('entity_test_mulrev_changed');
$this
->installEntitySchema('search_api_task');
$this
->installEntitySchema('field_storage_config');
$this
->installEntitySchema('field_config');
$this
->installConfig('search_api');
// Create the default languages.
$this
->installConfig([
'language',
]);
$this->langcodes = [];
for ($i = 0; $i < 3; ++$i) {
/** @var \Drupal\language\Entity\ConfigurableLanguage $language */
$language = ConfigurableLanguage::create([
'id' => 'l' . $i,
'label' => 'language - ' . $i,
'weight' => $i,
]);
$this->langcodes[$i] = $language
->getId();
$language
->save();
}
// Create an entity reference field on the test entity type.
FieldStorageConfig::create([
'field_name' => 'link',
'entity_type' => 'entity_test_mulrev_changed',
'type' => 'entity_reference',
'cardinality' => 1,
'settings' => [
'target_type' => 'entity_test_mulrev_changed',
],
])
->save();
FieldConfig::create([
'field_name' => 'link',
'entity_type' => 'entity_test_mulrev_changed',
'bundle' => 'entity_test_mulrev_changed',
'label' => 'Link',
])
->save();
// Do not use a batch for tracking the initial items after creating an
// index when running the tests via the GUI. Otherwise, it seems Drupal's
// Batch API gets confused and the test fails.
if (!Utility::isRunningInCli()) {
\Drupal::state()
->set('search_api_use_tracking_batch', FALSE);
}
// Create a test server.
$this->server = Server::create([
'name' => 'Test Server',
'id' => 'test_server',
'status' => 1,
'backend' => 'search_api_test',
]);
$this->server
->save();
// Create a test index.
$this->index = Index::create([
'name' => 'Test Index',
'id' => 'test_index',
'status' => 1,
'datasource_settings' => [
'entity:' . $this->testEntityTypeId => [],
],
'tracker_settings' => [
'default' => [],
],
'field_settings' => [
'link' => [
'label' => 'Link name',
'type' => 'string',
'datasource_id' => 'entity:entity_test_mulrev_changed',
'property_path' => 'link:entity:name',
],
],
'server' => $this->server
->id(),
'options' => [
'index_directly' => FALSE,
],
]);
$this->index
->save();
}