You are here

public function FacetsTestBase::getTestIndex in Facets 8

Creates or deletes an index.

Parameters

string $name: (optional) The name of the index.

string $id: (optional) The ID of the index.

string $server_id: (optional) The server to which the index should be attached.

string $datasource_id: (optional) The ID of a datasource to set for this index.

bool $reset: (optional) If TRUE, delete the index instead of creating it. (Only the index's ID is required in that case).

Return value

\Drupal\search_api\IndexInterface A search index.

File

tests/src/Functional/FacetsTestBase.php, line 146

Class

FacetsTestBase
Provides the base class for web tests for Search API.

Namespace

Drupal\Tests\facets\Functional

Code

public function getTestIndex($name = 'WebTest Index', $id = 'webtest_index', $server_id = 'webtest_server', $datasource_id = 'entity:node', $reset = FALSE) {
  if ($reset) {
    $index = Index::load($id);
    if ($index) {
      $index
        ->delete();
    }
  }
  else {
    $index = Index::create([
      'id' => $id,
      'name' => $name,
      'description' => $name,
      'server' => $server_id,
      'datasources' => [
        $datasource_id,
      ],
    ]);
    $index
      ->save();
    $this->indexId = $index
      ->id();
  }
  return $index;
}