You are here

public function ContentEntityDatasourceTest::setUp in Search API 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Datasource/ContentEntityDatasourceTest.php, line 65

Class

ContentEntityDatasourceTest
Tests correct functionality 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);
  $this
    ->installSchema('search_api', [
    'search_api_item',
  ]);
  $this
    ->installEntitySchema('entity_test_mulrev_changed');
  $this
    ->installConfig([
    'language',
  ]);

  // Create some languages.
  for ($i = 0; $i < 2; ++$i) {
    ConfigurableLanguage::create([
      'id' => 'l' . $i,
      'label' => 'language - ' . $i,
      'weight' => $i,
    ])
      ->save();
  }

  // Create a test index.
  $this->index = Index::create([
    'name' => 'Test Index',
    'id' => 'test_index',
    'status' => FALSE,
    'datasource_settings' => [
      'entity:' . $this->testEntityTypeId => [],
    ],
    'tracker_settings' => [
      'default' => [],
    ],
  ]);
  $this->datasource = $this->index
    ->getDatasource('entity:' . $this->testEntityTypeId);
  $this
    ->setUpExampleStructure();
  foreach ([
    'item',
    'article',
  ] as $i => $bundle) {
    $entity = EntityTestMulRevChanged::create([
      'id' => $i + 1,
      'type' => $bundle,
      'langcode' => 'l0',
    ]);
    $entity
      ->save();
    $entity
      ->addTranslation('l1')
      ->save();
  }
  $this->allItemIds = [
    '1:l0',
    '1:l1',
    '2:l0',
    '2:l1',
  ];
}