You are here

public function StemmerTest::testSupportsIndex in Search API 8

Tests the supportsIndex() method.

@covers ::supportsIndex

File

tests/src/Unit/Processor/StemmerTest.php, line 45

Class

StemmerTest
Tests the "Stemmer" processor.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testSupportsIndex() {
  $index = $this
    ->createMock(IndexInterface::class);
  $language_manager = $this
    ->createMock(LanguageManagerInterface::class);
  $this->container
    ->set('language_manager', $language_manager);
  $language_manager
    ->method('getLanguages')
    ->willReturn([
    new Language([
      'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]),
  ]);
  $this
    ->assertFalse(Stemmer::supportsIndex($index));
  $language_manager = $this
    ->createMock(LanguageManagerInterface::class);
  $this->container
    ->set('language_manager', $language_manager);
  $language_manager
    ->method('getLanguages')
    ->willReturn([
    new Language([
      'id' => 'de',
    ]),
    new Language([
      'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]),
    new Language([
      'id' => 'fr',
    ]),
  ]);
  $this
    ->assertFalse(Stemmer::supportsIndex($index));
  $language_manager = $this
    ->createMock(LanguageManagerInterface::class);
  $this->container
    ->set('language_manager', $language_manager);
  $language_manager
    ->method('getLanguages')
    ->willReturn([
    new Language([
      'id' => 'en',
    ]),
    new Language([
      'id' => 'fr',
    ]),
    new Language([
      'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]),
  ]);
  $this
    ->assertTrue(Stemmer::supportsIndex($index));
  $language_manager = $this
    ->createMock(LanguageManagerInterface::class);
  $this->container
    ->set('language_manager', $language_manager);
  $language_manager
    ->method('getLanguages')
    ->willReturn([
    new Language([
      'id' => 'fr',
    ]),
    new Language([
      'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]),
    new Language([
      'id' => 'en-GB',
    ]),
  ]);
  $this
    ->assertTrue(Stemmer::supportsIndex($index));
}