You are here

public function FacetsTestBase::getTestServer in Facets 8

Creates or deletes a server.

Parameters

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

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

string $backend_id: (optional) The ID of the backend to set for the server.

array $backend_config: (optional) The backend configuration to set for the server.

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

Return value

\Drupal\search_api\ServerInterface A search server.

File

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

Class

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

Namespace

Drupal\Tests\facets\Functional

Code

public function getTestServer($name = 'WebTest server', $id = 'webtest_server', $backend_id = 'search_api_db', array $backend_config = [], $reset = FALSE) {
  if ($reset) {
    $server = Server::load($id);
    if ($server) {
      $server
        ->delete();
    }
  }
  else {
    $server = Server::create([
      'id' => $id,
      'name' => $name,
      'description' => $name,
      'backend' => $backend_id,
      'backend_config' => $backend_config,
    ]);
    $server
      ->save();
  }
  return $server;
}