SolrBackendTestBase.php in Search API Solr 8.3
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;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
defined('TRAVIS_BUILD_DIR') || define('TRAVIS_BUILD_DIR', getenv('TRAVIS_BUILD_DIR') ?: '.');
defined('SOLR_CLOUD') || define('SOLR_CLOUD', getenv('SOLR_CLOUD') ?: 'false');
abstract class SolrBackendTestBase extends BackendTestBase {
use SolrCommitTrait;
public static $modules = [
'devel',
'search_api_solr',
'search_api_solr_devel',
'search_api_solr_test',
];
protected $serverId = 'solr_search_server';
protected $indexId = 'solr_search_index';
protected $logger;
protected $travisLogger;
public function setUp() {
if ('true' === SOLR_CLOUD) {
$this->serverId .= '_cloud';
$this->indexId .= '_cloud';
}
parent::setUp();
$this
->installConfigs();
$this
->commonSolrBackendSetUp();
$this->logger = new InMemoryLogger();
\Drupal::service('logger.factory')
->addLogger($this->logger);
$this->travisLogger = new Logger('search_api_solr');
$this->travisLogger
->pushHandler(new StreamHandler(TRAVIS_BUILD_DIR . '/solr_query.log', Logger::DEBUG));
\Drupal::service('search_api_solr_devel.solarium_request_logger')
->setLogger($this->travisLogger);
}
protected function installConfigs() {
$this
->installConfig([
'devel',
'search_api_solr',
'search_api_solr_test',
]);
}
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);
return $index_status;
}
protected function clearIndex() {
$index = Index::load($this->indexId);
$index
->clear();
$this
->ensureCommit($index);
}
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);
}
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;
}
}