You are here

trait SolrBackendTrait in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/Processor/SolrBackendTrait.php \Drupal\Tests\search_api_solr\Kernel\Processor\SolrBackendTrait
  2. 8 tests/src/Kernel/Processor/SolrBackendTrait.php \Drupal\Tests\search_api_solr\Kernel\Processor\SolrBackendTrait
  3. 8.2 tests/src/Kernel/Processor/SolrBackendTrait.php \Drupal\Tests\search_api_solr\Kernel\Processor\SolrBackendTrait

Helper to exchange the DB backend for a Solr backend in processor tests.

Hierarchy

File

tests/src/Kernel/Processor/SolrBackendTrait.php, line 16

Namespace

Drupal\Tests\search_api_solr\Kernel\Processor
View source
trait SolrBackendTrait {
  use SolrCommitTrait;

  /**
   * Swap the DB backend for a Solr backend.
   *
   * This function has to be called from the test setUp() function.
   */
  protected function enableSolrServer() {
    $config = '/config/install/search_api.server.solr_search_server' . ('true' === SOLR_CLOUD ? '_cloud' : '') . '.yml';
    $this->server = Server::create(Yaml::parse(file_get_contents(drupal_get_path('module', 'search_api_solr_test') . $config)));
    $this->server
      ->save();
    $this->index
      ->setServer($this->server);
    $this->index
      ->save();
    $index_storage = $this->container
      ->get('entity_type.manager')
      ->getStorage('search_api_index');
    $index_storage
      ->resetCache([
      $this->index
        ->id(),
    ]);
    $this->index = $index_storage
      ->load($this->index
      ->id());
  }

  /**
   * {@inheritdoc}
   */
  protected function indexItems() {
    $index_status = parent::indexItems();
    $this
      ->ensureCommit($this->index);
    return $index_status;
  }

  /**
   * {@inheritdoc}
   */
  protected function tearDown() {
    $this->index
      ->clear();
    $this
      ->ensureCommit($this->index);
    parent::tearDown();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SolrBackendTrait::enableSolrServer protected function Swap the DB backend for a Solr backend. 3
SolrBackendTrait::indexItems protected function
SolrBackendTrait::tearDown protected function
SolrCommitTrait::ensureCommit protected function Explicitly sends a commit command to a Solr server.