public function SearchByPageTesterTest::search_by_page_test_search_by_page_excerpt_match in Search by Page 8
Implements hook_search_by_page_excerpt_match().
For testing of the search_by_page_excerpt() function.
File
- tests/
src/ Functional/ SearchByPageTesterTest.php, line 180 - General Functional Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Class
- SearchByPageTesterTest
- Base class for testing Search by Page.
Namespace
Drupal\Tests\search_by_page\FunctionalCode
public function search_by_page_test_search_by_page_excerpt_match($key, $text, $offset, $boundary) {
// Find the root form of the keyword -- in this simple example,
// all but the last 3 characters.
$key = mb_substr($key, 0, -3);
if (mb_strlen($key) < 3) {
return FALSE;
}
// Look for this modified key at the start of a word.
$match = array();
if (!preg_match('/' . $boundary . $key . '/iu', $text, $match, PREG_OFFSET_CAPTURE, $offset)) {
// didn't match our modified key.
return FALSE;
}
// If we get here, we have a match. Find the end of the word we
// actually matched, so it can be highlighted.
$pos = $match[0][1];
if (preg_match('/' . $boundary . '/iu', $text, $match, PREG_OFFSET_CAPTURE, $pos + mb_strlen($key))) {
$keyfound = mb_substr($text, $pos, $match[0][1] - $pos);
}
return array(
'where' => $pos,
'keyword' => $keyfound,
);
}