| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
class SearchHighlighterTest extends \MediaWikiIntegrationTestCase { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
public function testHighlightSimple( string $wikiText, string $searchTerm, string $expectedOutput, int $contextChars ) { |
| 12 |
$highlighter = new \SearchHighlighter( false ); |
| 13 |
$actual = $highlighter->highlightSimple( $wikiText, [ $searchTerm ], 1, $contextChars ); |
| 14 |
$this->assertEquals( $expectedOutput, $actual ); |
| 15 |
} |
| 16 |
|
| 17 |
public static function provideHighlightSimple() { |
| 18 |
return [ |
| 19 |
'no match' => [ |
| 20 |
'this is a very simple text.', |
| 21 |
'cannotmatch', |
| 22 |
'', |
| 23 |
10 |
| 24 |
], |
| 25 |
'match a single word at the end of the string' => [ |
| 26 |
'this is a very simple text.', |
| 27 |
'text', |
| 28 |
"this is a very simple <span class=\"searchmatch\">text</span>.\n", |
| 29 |
40 |
| 30 |
], |
| 31 |
'utf-8 sequences should not be broken' => [ |
| 32 |
"text with long trailing UTF-8 sequences: " . str_repeat( "\u{1780}", 6 ) . ".", |
| 33 |
'text', |
| 34 |
"<span class=\"searchmatch\">text</span> with long trailing UTF-8 sequences: " . str_repeat( "\u{1780}", 5 ) . "\n", |
| 35 |
41 |
| 36 |
], |
| 37 |
]; |
| 38 |
} |
| 39 |
} |