SolrBackendTestBase.php in Search API Solr 8.2
File
tests/src/Kernel/SolrBackendTestBase.php
View source
<?php
namespace Drupal\Tests\search_api_solr\Kernel;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Entity\Server;
use Drupal\search_api_solr_test\Logger\InMemoryLogger;
use Drupal\Tests\search_api\Kernel\BackendTestBase;
use Drupal\search_api_solr\Utility\SolrCommitTrait;
abstract class SolrBackendTestBase extends BackendTestBase {
use SolrCommitTrait;
public static $modules = [
'search_api_solr',
];
protected $serverId = 'solr_search_server';
protected $indexId = 'solr_search_index';
protected $logger;
public function setUp() {
parent::setUp();
$this
->installConfigs();
$this
->commonSolrBackendSetUp();
$this->logger = new InMemoryLogger();
\Drupal::service('logger.factory')
->addLogger($this->logger);
}
protected function installConfigs() {
$this
->installConfig([
'search_api_solr',
]);
}
protected function commonSolrBackendSetUp() {
}
public function tearDown() {
$this
->clearIndex();
parent::tearDown();
}
protected function assertLogMessage($level, $message) {
$last_message = $this->logger
->getLastMessage();
$this
->assertEquals($level, $last_message['level']);
$this
->assertEquals($message, $last_message['message']);
}
protected function indexItems($index_id) {
$index_status = parent::indexItems($index_id);
$index = Index::load($index_id);
$this
->ensureCommit($index
->getServerInstance());
return $index_status;
}
protected function clearIndex() {
$index = Index::load($this->indexId);
$index
->clear();
$this
->ensureCommit($index
->getServerInstance());
}
protected function executeQueryWithoutPostProcessing(QueryInterface $query) {
$index = Index::load($this->indexId);
$query
->preExecute();
return $index
->getServerInstance()
->search($query);
}
protected function checkIndexWithoutFields() {
$index = parent::checkIndexWithoutFields();
$index
->clear();
$this
->ensureCommit($index
->getServerInstance());
}
protected function checkServerBackend() {
}
protected function updateIndex() {
}
protected function checkSecondServer() {
}
protected function checkModuleUninstall() {
}
protected function getSolrVersion() {
static $solr_version = FALSE;
if (!$solr_version) {
$backend = Server::load($this->serverId)
->getBackend();
$connector = $backend
->getSolrConnector();
$solr_version = $connector
->getSolrVersion();
}
return $solr_version;
}
}