You are here

public function LanguageWithFallbackTest::setUp in Search API 8

Performs setup tasks before each individual test method is run.

Installs commonly used schemas and sets up a search server and an index, with the specified processor enabled.

Parameters

string|null $processor: (optional) The plugin ID of the processor that should be set up for testing.

Overrides ProcessorTestBase::setUp

File

tests/src/Kernel/Processor/LanguageWithFallbackTest.php, line 42

Class

LanguageWithFallbackTest
Tests the "Language (with fallback)" processor at a higher level.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function setUp($processor = NULL) {
  parent::setUp('language_with_fallback');

  // search_api_test_language_fallback.module adds a fallback from 'fr' to
  // 'es'. When we then leave 'en' as site default language and set 'de' as
  // original node language, we are able to spot false fallbacks to either of
  // those.
  foreach ([
    'de',
    'fr',
    'es',
  ] as $langcode) {
    ConfigurableLanguage::createFromLangcode($langcode)
      ->enable()
      ->save();
  }
  NodeType::create([
    'type' => 'article',
  ])
    ->save();
  $lwf_field = new Field($this->index, 'language_with_fallback');
  $lwf_field
    ->setType('string');
  $lwf_field
    ->setPropertyPath('language_with_fallback');
  $lwf_field
    ->setLabel('Language (with fallback)');
  $this->index
    ->addField($lwf_field);
  $this->index
    ->setOption('index_directly', TRUE);
  $this->index
    ->save();
}