function SearchExcerptTest::doSearchExcerpt

Same name and namespace in other branches
  1. 9 core/modules/search/tests/src/Kernel/SearchExcerptTest.php \Drupal\Tests\search\Kernel\SearchExcerptTest::doSearchExcerpt()
  2. 8.9.x core/modules/search/tests/src/Kernel/SearchExcerptTest.php \Drupal\Tests\search\Kernel\SearchExcerptTest::doSearchExcerpt()
  3. 10 core/modules/search/tests/src/Kernel/SearchExcerptTest.php \Drupal\Tests\search\Kernel\SearchExcerptTest::doSearchExcerpt()

Calls search_excerpt() and renders output.

Parameters

string $keys: A string containing a search query.

string $render_array: The text to extract fragments from.

string|null $langcode: Language code for the language of $text, if known.

Return value

string A string containing HTML for the excerpt.

2 calls to SearchExcerptTest::doSearchExcerpt()
SearchExcerptTest::testSearchExcerpt in core/modules/search/tests/src/Kernel/SearchExcerptTest.php
Tests search_excerpt() with several simulated search keywords.
SearchExcerptTest::testSearchExcerptSimplified in core/modules/search/tests/src/Kernel/SearchExcerptTest.php
Tests search_excerpt() with search keywords matching simplified words.

File

core/modules/search/tests/src/Kernel/SearchExcerptTest.php, line 195

Class

SearchExcerptTest
Tests the <a href="/api/drupal/core%21modules%21search%21search.module/function/search_excerpt/11.x" title="Returns snippets from a piece of text, with search keywords highlighted." class="local">search_excerpt</a>() function.

Namespace

Drupal\Tests\search\Kernel

Code

protected function doSearchExcerpt($keys, $render_array, $langcode = NULL) {
    $render_array = search_excerpt($keys, $render_array, $langcode);
    $text = (string) \Drupal::service('renderer')->renderInIsolation($render_array);
    // The search_excerpt() function adds some extra spaces -- not
    // important for HTML formatting or this test. Remove these for comparison.
    return preg_replace('| +|', ' ', $text);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.