You are here

function SearchByPageUnitTest::testExcerpt in Search by Page 8

Tests the search_by_page_excerpt() function.

File

tests/src/Unit/SearchByPageUnitTest.php, line 60
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPageUnitTest
Unit tests for Search by Page functions.

Namespace

Drupal\Tests\search_by_page\Unit

Code

function testExcerpt() {

  // Our test class should have made the 'walking' key match walks, walker,
  // walking, and walked. They should now be highlighted with <strong> HTML
  // tags.
  $result = \Drupal::service('search_by_page.settings')
    ->excerpt('walking', 'He walks through the forest');
  $this
    ->assertTrue(strpos($result, '<strong>walks</strong>') > 0, "Excerpt highlights walks");
  $result = \Drupal::service('search_by_page.settings')
    ->excerpt('walking', 'He is a walker through the forest');
  $this
    ->assertTrue(strpos($result, '<strong>walker</strong>') > 0, "Excerpt highlights walker");
  $result = \Drupal::service('search_by_page.settings')
    ->excerpt('walking', 'He is walking through the forest');
  $this
    ->assertTrue(strpos($result, '<strong>walking</strong>') > 0, "Excerpt highlights walking");
  $result = \Drupal::service('search_by_page.settings')
    ->excerpt('walking', 'He walked through the forest');
  $this
    ->assertTrue(strpos($result, '<strong>walked</strong>') > 0, "Excerpt highlights walked");

  // Verify that an exact match after a stemmed match highlights the stemmed.
  $result = \Drupal::service('search_by_page.settings')
    ->excerpt('walking', 'He walked on the long walk in town');
  $this
    ->assertTrue(strpos($result, '<strong>walked</strong>') > 0, "Excerpt highlights walked");
}