You are here

protected function UtilitiesTest::doDynamicFieldNameConversions in Search API Multilingual Solr Search 8

Tests all conversion and extraction functions.

Parameters

string $prefix: The Solr field prefix.

string $langcode: The Drupal language ID.

string $field: The Drupal field name.

1 call to UtilitiesTest::doDynamicFieldNameConversions()
UtilitiesTest::testLanguageSpecificDynamicFieldNames in tests/src/Kernel/UtilitiesTest.php
Tests language-specific Solr field names.

File

tests/src/Kernel/UtilitiesTest.php, line 78

Class

UtilitiesTest
Provides tests for various utility functions.

Namespace

Drupal\Tests\search_api_solr_multilingual\Kernel

Code

protected function doDynamicFieldNameConversions($prefix = 'tm', $langcode = 'de', $field = 'body') {
  $sep = ';';

  // tm_body
  $dynamic_field_name = $prefix . '_' . $field;

  // tm;de_
  $language_specific_prefix = $prefix . $sep . $langcode . '_';

  // tm;de_body
  $language_specific_field_name = $language_specific_prefix . $field;
  $this
    ->assertEquals(Utility::getLanguageSpecificSolrDynamicFieldPrefix($prefix, $langcode), $language_specific_prefix);

  // tm_body => tm;de_body
  $language_specific_dynamic_field_name = Utility::getLanguageSpecificSolrDynamicFieldNameForSolrDynamicFieldName($dynamic_field_name, $langcode);
  $this
    ->assertEquals($language_specific_dynamic_field_name, $language_specific_field_name);

  // tm;de_body => tm_body
  $language_unspecific_dynamic_field_name = Utility::getSolrDynamicFieldNameForLanguageSpecificSolrDynamicFieldName($language_specific_dynamic_field_name);
  $this
    ->assertEquals($language_unspecific_dynamic_field_name, $dynamic_field_name);

  // tm;de_body => tm_X3b_de_body => tm_body
  $encoded_language_specific_dynamic_field_name = SASUtility::encodeSolrName($language_specific_dynamic_field_name);
  $encoded_language_unspecific_dynamic_field_name = Utility::getSolrDynamicFieldNameForLanguageSpecificSolrDynamicFieldName($encoded_language_specific_dynamic_field_name);
  $decoded_language_unspecific_dynamic_field_name = SASUtility::decodeSolrName($encoded_language_unspecific_dynamic_field_name);
  $this
    ->assertEquals($decoded_language_unspecific_dynamic_field_name, $dynamic_field_name);

  // tm_X3b_de_body => tm_X3b_de_*
  $field_definition = Utility::extractLanguageSpecificSolrDynamicFieldDefinition($encoded_language_specific_dynamic_field_name);
  $this
    ->assertEquals($field_definition, SASUtility::encodeSolrName($language_specific_prefix) . '*');

  // tm;de_body => de
  $this
    ->assertEquals(Utility::getLanguageIdFromLanguageSpecificSolrDynamicFieldName($language_specific_field_name), $langcode);

  // tm_body => FALSE
  $this
    ->assertFalse(Utility::getLanguageIdFromLanguageSpecificSolrDynamicFieldName($dynamic_field_name));
}