You are here

public function SearchCrudTest::setUp in Search API Autocomplete 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/SearchCrudTest.php, line 35

Class

SearchCrudTest
Tests saving a Search API autocomplete config entity.

Namespace

Drupal\Tests\search_api_autocomplete\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('search_api_task');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('search_api', [
    'search_api_item',
  ]);
  $this
    ->installConfig('search_api');

  // Do not use a batch for tracking the initial items after creating an
  // index when running the tests via the GUI. Otherwise, it seems Drupal's
  // Batch API gets confused and the test fails.
  if (php_sapi_name() != 'cli') {
    \Drupal::state()
      ->set('search_api_use_tracking_batch', FALSE);
  }
  $server = Server::create([
    'id' => 'server',
    'name' => 'Server &!_1',
    'status' => TRUE,
    'backend' => 'search_api_db',
    'backend_config' => [
      'database' => 'default:default',
    ],
  ]);
  $server
    ->save();
  $index = Index::create([
    'id' => 'autocomplete_search_index',
    'name' => 'Index !1%$_',
    'status' => TRUE,
    'datasource_settings' => [
      'entity:user' => [],
    ],
    'server' => 'server',
    'tracker_settings' => [
      'default' => [],
    ],
  ]);
  $index
    ->setServer($server);
  $index
    ->save();
}