You are here

class SolrLegacyTest in Search API Solr 4.x

Tests index and search capabilities using the Solr search backend.

@group search_api_solr_legacy

Hierarchy

Expanded class hierarchy of SolrLegacyTest

File

modules/search_api_solr_legacy/tests/src/Kernel/SolrLegacyTest.php, line 15

Namespace

Drupal\Tests\search_api_solr_legacy\Kernel
View source
class SolrLegacyTest extends SearchApiSolrTest {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'search_api_solr_legacy',
    'search_api_solr_legacy_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected function installConfigs() {
    parent::installConfigs();
    $this
      ->installConfig([
      'search_api_solr_legacy',
      'search_api_solr_legacy_test',
    ]);

    // Swap the connector.
    Solr36TestConnector::adjustBackendConfig('search_api.server.solr_search_server');
  }

  /**
   * Tests the conversion of Search API queries into Solr queries.
   */
  protected function checkSchemaLanguages() {

    // Solr 3.6 doesn't provide the required REST API.
  }

  /**
   * Test generation of Solr configuration files.
   *
   * @dataProvider configGenerationDataProvider
   *
   * @throws \Drupal\search_api\SearchApiException
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  public function testConfigGeneration(array $files) {
    $server = $this
      ->getServer();
    $solr_major_version = $server
      ->getBackend()
      ->getSolrConnector()
      ->getSolrMajorVersion();
    $backend_config = $server
      ->getBackendConfig();
    $solr_configset_controller = new SolrConfigSetController();
    $solr_configset_controller
      ->setServer($server);
    $config_files = $solr_configset_controller
      ->getConfigFiles();
    foreach ($files as $file_name => $expected_strings) {
      $this
        ->assertArrayHasKey($file_name, $config_files);
      foreach ($expected_strings as $string) {
        $this
          ->assertStringContainsString($string, $config_files[$file_name]);
      }
    }
    $config_name = 'name="drupal-' . SolrBackendInterface::SEARCH_API_SOLR_SCHEMA_VERSION . '-solr-' . $solr_major_version . '.x-' . SEARCH_API_SOLR_JUMP_START_CONFIG_SET . '"';
    $this
      ->assertStringContainsString($config_name, $config_files['solrconfig.xml']);
    $this
      ->assertStringContainsString($config_name, $config_files['schema.xml']);
    $this
      ->assertStringContainsString($server
      ->id(), $config_files['test.txt']);
    $this
      ->assertStringNotContainsString('<jmx />', $config_files['solrconfig.xml']);
    $this
      ->assertStringContainsString('solr.luceneMatchVersion=' . $solr_major_version, $config_files['solrcore.properties']);
    $this
      ->assertStringNotContainsString('<statsCache', $config_files['solrconfig.xml']);
    $backend_config['connector_config']['jmx'] = TRUE;
    $backend_config['disabled_field_types'] = [
      'text_foo_en_3_6_0',
      'text_foo_en_4_5_0',
      'text_foo_en_6_0_0',
      'text_de_3_6_0',
      'text_de_4_5_0',
      'text_de_6_0_0',
      'text_de_7_0_0',
    ];
    $backend_config['disabled_caches'] = [
      'cache_document_default_7_0_0',
      'cache_filter_default_7_0_0',
    ];
    $server
      ->setBackendConfig($backend_config);
    $server
      ->save();

    // Reset static caches.
    $solr_configset_controller
      ->setServer($server);
    $config_files = $solr_configset_controller
      ->getConfigFiles();
    $this
      ->assertStringContainsString('<jmx />', $config_files['solrconfig.xml']);
    $this
      ->assertStringContainsString('text_en', $config_files['schema.xml']);
    $this
      ->assertStringNotContainsString('text_foo_en', $config_files['schema.xml']);
    $this
      ->assertStringNotContainsString('text_de', $config_files['schema.xml']);
    $this
      ->assertStringContainsString('httpCaching', $config_files['solrconfig.xml']);
    $this
      ->assertStringContainsString('never304="true"', $config_files['solrconfig.xml']);
    $this
      ->assertStringContainsString('ts_X3b_en_*', $config_files['schema.xml']);
    $this
      ->assertStringNotContainsString('ts_X3b_de_*', $config_files['schema.xml']);

    /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
    $backend = $server
      ->getBackend();
    $this
      ->assertStringContainsString('solr.install.dir', $config_files['solrcore.properties']);
    $this
      ->assertStringContainsString('solr.replication', $config_files['solrcore.properties']);
    $this
      ->assertStringContainsString('"/replication"', $config_files['solrconfig.xml']);
  }

  /**
   * Data provider for testConfigGeneration method.
   */
  public function configGenerationDataProvider() {

    // @codingStandardsIgnoreStart
    return [
      [
        [
          'schema.xml' => [
            # phonetic is currently not available for Solr <= 7.x.

            #'fieldType name="text_phonetic_en" class="solr.TextField"',
            'fieldType name="text_en" class="solr.TextField"',
            'fieldType name="text_de" class="solr.TextField"',
            '<fieldType name="text_foo_en" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LengthFilterFactory" min="2" max="100"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LengthFilterFactory" min="2" max="100"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>',
            '<dynamicField name="ts_X3b_en_*" type="text_en" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tm_X3b_en_*" type="text_en" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tos_X3b_en_*" type="text_en" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="true" />',
            '<dynamicField name="tom_X3b_en_*" type="text_en" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="true" />',
            '<dynamicField name="tus_X3b_en_*" type="text_unstemmed_en" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tum_X3b_en_*" type="text_unstemmed_en" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="ts_X3b_und_*" type="text_und" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tm_X3b_und_*" type="text_und" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tos_X3b_und_*" type="text_und" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="true" />',
            '<dynamicField name="tom_X3b_und_*" type="text_und" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="true" />',
            '<dynamicField name="tus_X3b_und_*" type="text_und" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tum_X3b_und_*" type="text_und" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tus_*" type="text_und" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tum_*" type="text_und" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="ts_X3b_de_*" type="text_de" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tm_X3b_de_*" type="text_de" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tos_X3b_de_*" type="text_de" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="true" />',
            '<dynamicField name="tom_X3b_de_*" type="text_de" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="true" />',
            '<dynamicField name="tus_X3b_de_*" type="text_unstemmed_de" stored="true" indexed="true" multiValued="false" termVectors="true" omitNorms="false" />',
            '<dynamicField name="tum_X3b_de_*" type="text_unstemmed_de" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="false" />',
            '<dynamicField name="spellcheck_und*" type="text_spell_und" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="true" />',
            '<dynamicField name="spellcheck_*" type="text_spell_und" stored="true" indexed="true" multiValued="true" termVectors="true" omitNorms="true" />',
          ],
          'solrconfig.xml' => [
            '<str name="name">en</str>',
            '<str name="name">de</str>',
          ],
          'stopwords_en.txt' => [],
          'synonyms_en.txt' => [
            'drupal, durpal',
          ],
          'protwords_en.txt' => [],
          'accents_en.txt' => [
            '"\\u00C4" => "A"',
          ],
          'stopwords_de.txt' => [],
          'synonyms_de.txt' => [
            'drupal, durpal',
          ],
          'protwords_de.txt' => [],
          'accents_de.txt' => [
            ' Not needed if German2 Porter stemmer is used.',
          ],
          'elevate.xml' => [],
          'test.txt' => [
            'hook_search_api_solr_config_files_alter() works',
          ],
        ],
      ],
    ];

    // @codingStandardsIgnoreEnd
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InvokeMethodTrait::invokeMethod protected function Calls protected/private method of a class.
SearchApiSolrTest::$fieldsHelper protected property The fields helper.
SearchApiSolrTest::$languageIds protected property
SearchApiSolrTest::assertIgnored protected function
SearchApiSolrTest::backendSpecificRegressionTests protected function
SearchApiSolrTest::checkBackendSpecificFeatures protected function Checks backend specific features.
SearchApiSolrTest::checkBasicAuth protected function Test that basic auth config gets passed to Solarium.
SearchApiSolrTest::checkDatasourceAdditionAndDeletion protected function Tests addition and deletion of a data source.
SearchApiSolrTest::checkHighlight protected function Tests highlight options.
SearchApiSolrTest::checkIndexFallback protected function Tests retrieve_data options.
SearchApiSolrTest::checkModuleUninstall protected function Overrides SolrBackendTestBase::checkModuleUninstall
SearchApiSolrTest::checkQueryConditions protected function Tests the conversion of Search API queries into Solr queries.
SearchApiSolrTest::checkQueryParsers protected function Tests the conversion of Search API queries into Solr queries.
SearchApiSolrTest::checkRetrieveData protected function Tests retrieve_data options.
SearchApiSolrTest::checkSearchResultGrouping public function Tests search result grouping.
SearchApiSolrTest::checkSearchResultSorts protected function Tests search result sorts.
SearchApiSolrTest::commonSolrBackendSetUp protected function Required parts of the setUp() function that are the same for all backends. Overrides SolrBackendTestBase::commonSolrBackendSetUp
SearchApiSolrTest::getExpectedFacetsOfRegressionTest2469547 protected function Return the expected facets for regression test 2469547.
SearchApiSolrTest::getItemIds protected function If the list of entity ids contains language codes it will be handled here, otherwise it will be handed over to the parent implementation.
SearchApiSolrTest::getLongText protected function Produces a string of given comprising diverse chars.
SearchApiSolrTest::indexPrefixTest protected function Tests index prefix.
SearchApiSolrTest::insertMultilingualExampleContent protected function Creates several test entities.
SearchApiSolrTest::regressionTest2469547 protected function Regression tests for #2469547.
SearchApiSolrTest::regressionTest2888629 protected function Regression tests for #2888629.
SearchApiSolrTest::searchSuccess public function
SearchApiSolrTest::testAutocompleteAndNgram public function Tests the autocomplete support and ngram results.
SearchApiSolrTest::testLanguageFallbackAndLanguageLimitedByOptions public function Tests language fallback and language limiting via options.
SolrBackendTestBase::$indexId protected property A Search API index ID. 1
SolrBackendTestBase::$logger protected property The in-memory logger.
SolrBackendTestBase::$serverId protected property A Search API server ID. 1
SolrBackendTestBase::assertLogMessage protected function Tests the last logged level and message.
SolrBackendTestBase::checkIndexWithoutFields protected function
SolrBackendTestBase::checkSecondServer protected function
SolrBackendTestBase::checkServerBackend protected function
SolrBackendTestBase::clearIndex protected function
SolrBackendTestBase::executeQueryWithoutPostProcessing protected function Executes a query and skips search_api post processing of results.
SolrBackendTestBase::getSolrVersion protected function Gets the Solr version.
SolrBackendTestBase::indexItems protected function
SolrBackendTestBase::setUp public function
SolrBackendTestBase::tearDown public function Clear the index after every test.
SolrBackendTestBase::updateIndex protected function
SolrCommitTrait::ensureCommit protected function Explicitly sends a commit command to a Solr server.
SolrLegacyTest::$modules public static property Modules to enable for this test. Overrides SearchApiSolrTest::$modules
SolrLegacyTest::checkSchemaLanguages protected function Tests the conversion of Search API queries into Solr queries. Overrides SearchApiSolrTest::checkSchemaLanguages
SolrLegacyTest::configGenerationDataProvider public function Data provider for testConfigGeneration method. Overrides SearchApiSolrTest::configGenerationDataProvider
SolrLegacyTest::installConfigs protected function Called by setUp() to install required configs. Overrides SearchApiSolrTest::installConfigs
SolrLegacyTest::testConfigGeneration public function Test generation of Solr configuration files. Overrides SearchApiSolrTest::testConfigGeneration