You are here

public function BackendTest::setUp in Search API 8

Overrides BackendTestBase::setUp

File

modules/search_api_db/tests/src/Kernel/BackendTest.php, line 56

Class

BackendTest
Tests index and search capabilities using the Database search backend.

Namespace

Drupal\Tests\search_api_db\Kernel

Code

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

  // Create a dummy table that will cause a naming conflict with the backend's
  // default table names, thus testing whether it correctly reacts to such
  // conflicts.
  \Drupal::database()
    ->schema()
    ->createTable('search_api_db_database_search_index', [
    'fields' => [
      'id' => [
        'type' => 'int',
      ],
    ],
  ]);
  $this
    ->installConfig([
    'search_api_test_db',
  ]);

  // Add additional fields to the search index that have the same ID as
  // column names used by this backend, to see whether this leads to any
  // conflicts.
  $index = $this
    ->getIndex();
  $fields_helper = \Drupal::getContainer()
    ->get('search_api.fields_helper');
  $column_names = [
    'item_id',
    'field_name',
    'word',
    'score',
    'value',
  ];
  $field_info = [
    'datasource_id' => 'entity:entity_test_mulrev_changed',
    'property_path' => 'type',
    'type' => 'string',
  ];
  foreach ($column_names as $column_name) {
    $field_info['label'] = "Test field {$column_name}";
    $field = $fields_helper
      ->createField($index, $column_name, $field_info);
    $index
      ->addField($field);
  }
  $index
    ->save();
}