You are here

protected function BackendTest::checkServerBackend in Search API 8

Tests that all tables and all columns have been created.

Overrides BackendTestBase::checkServerBackend

File

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

Class

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

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function checkServerBackend() {
  $db_info = $this
    ->getIndexDbInfo();
  $normalized_storage_table = $db_info['index_table'];
  $field_infos = $db_info['field_tables'];
  $expected_fields = [
    'body',
    'category',
    'created',
    'field_name',
    'id',
    'item_id',
    'keywords',
    'name',
    'score',
    'search_api_datasource',
    'search_api_language',
    'type',
    'value',
    'width',
    'word',
  ];
  $actual_fields = array_keys($field_infos);
  sort($actual_fields);
  $this
    ->assertEquals($expected_fields, $actual_fields, 'All expected field tables were created.');
  $this
    ->assertTrue(\Drupal::database()
    ->schema()
    ->tableExists($normalized_storage_table), 'Normalized storage table exists.');
  $this
    ->assertHasPrimaryKey($normalized_storage_table, 'Normalized storage table has a primary key.');
  foreach ($field_infos as $field_id => $field_info) {
    if ($field_id != 'search_api_id') {
      $this
        ->assertTrue(\Drupal::database()
        ->schema()
        ->tableExists($field_info['table']));
    }
    else {
      $this
        ->assertEmpty($field_info['table']);
    }
    $this
      ->assertTrue(\Drupal::database()
      ->schema()
      ->fieldExists($normalized_storage_table, $field_info['column']), new FormattableMarkup('Field column %column exists', [
      '%column' => $field_info['column'],
    ]));
  }
}