You are here

public function LangCodeTest::testStemSearching in Porter-Stemmer 8

Test that search variations return English language results.

File

tests/src/Functional/LangCodeTest.php, line 155

Class

LangCodeTest
Tests that EN language search terms are stemmed and return stemmed content.

Namespace

Drupal\Tests\porterstemmer\Functional

Code

public function testStemSearching() {
  foreach ($this->searches as $search) {
    $this
      ->drupalPostForm('search/node', [
      'keys' => $search,
    ], t('Search'));

    // Verify that all English-language test node variants show up in results.
    foreach ($this->testData as $title => $body) {
      $this
        ->assertText($title . ' (EN)', new FormattableMarkup('Search for %search returns English-language node with body %body', [
        '%search' => $search,
        '%body' => $body,
      ]));
    }

    // Check for results by language.
    switch ($search) {
      case 'walk':
        $this
          ->assertNoText('Second Page (FR)', new FormattableMarkup('Search for %search does not show stemmed non-English results.', [
          '%search' => $search,
        ]));
        $this
          ->assertNoText('Second Page (UND)', new FormattableMarkup('Search for %search does show stemmed language-unspecified results.', [
          '%search' => $search,
        ]));
        break;
      case 'walked':
        $this
          ->assertNoText('Second Page (FR)', new FormattableMarkup('Search for %search does not show stemmed non-English results.', [
          '%search' => $search,
        ]));
        $this
          ->assertNoText('Second Page (UND)', new FormattableMarkup('Search for %search does not show stemmed language-unspecified results.', [
          '%search' => $search,
        ]));
        break;
      case 'walking':
        $this
          ->assertText('First Page (FR)', new FormattableMarkup('Search for %search does show matching non-English results.', [
          '%search' => $search,
        ]));
        $this
          ->assertText('First Page (UND)', new FormattableMarkup('Search for %search does show matching language-unspecified results.', [
          '%search' => $search,
        ]));
        break;
    }
  }
}