You are here

public function DatasourceTaskTest::setUp in Search API 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Datasource/DatasourceTaskTest.php, line 62

Class

DatasourceTaskTest
Tests task integration of the content entity datasource.

Namespace

Drupal\Tests\search_api\Kernel\Datasource

Code

public function setUp() {
  parent::setUp();

  // Enable translation for the entity_test module.
  \Drupal::state()
    ->set('entity_test.translation', TRUE);

  // Define the bundles for our test entity type. (Should happen before we
  // install its entity schema.)
  $bundles = [
    'article' => [
      'label' => 'Article',
    ],
    'item' => [
      'label' => 'Item',
    ],
  ];
  \Drupal::state()
    ->set($this->testEntityTypeId . '.bundles', $bundles);
  $this
    ->installSchema('search_api', [
    'search_api_item',
  ]);
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('entity_test_mulrev_changed');
  $this
    ->installEntitySchema('search_api_task');
  $this->taskManager = $this->container
    ->get('search_api.task_manager');

  // Create some languages.
  $this
    ->installConfig([
    'language',
  ]);
  for ($i = 0; $i < 3; ++$i) {

    /** @var \Drupal\language\ConfigurableLanguageInterface $language */
    $language = ConfigurableLanguage::create([
      'id' => 'l' . $i,
      'label' => 'language - ' . $i,
      'weight' => $i,
    ]);
    $language
      ->save();
  }
  $this
    ->installConfig('search_api');

  // 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' => [],
    ],
    'server' => $this->server
      ->id(),
    'options' => [
      'index_directly' => FALSE,
    ],
  ]);
  $this->index
    ->save();
  $this->taskManager
    ->deleteTasks();
}