You are here

protected function BackendTest::updateIndex in Search API 8

Checks whether changes to the index's fields are picked up by the server.

Overrides BackendTestBase::updateIndex

File

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

Class

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

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function updateIndex() {

  /** @var \Drupal\search_api\IndexInterface $index */
  $index = $this
    ->getIndex();

  // Remove a field from the index and check if the change is matched in the
  // server configuration.
  $field = $index
    ->getField('keywords');
  if (!$field) {
    throw new \Exception();
  }
  $index
    ->removeField('keywords');
  $index
    ->save();
  $index_fields = array_keys($index
    ->getFields());

  // Include the three "magic" fields we're indexing with the DB backend.
  $index_fields[] = 'search_api_datasource';
  $index_fields[] = 'search_api_language';
  $db_info = $this
    ->getIndexDbInfo();
  $server_fields = array_keys($db_info['field_tables']);
  sort($index_fields);
  sort($server_fields);
  $this
    ->assertEquals($index_fields, $server_fields);

  // Add the field back for the next assertions.
  $index
    ->addField($field)
    ->save();
}