wiki.techinc.nl/tests/phpunit/includes/search/SearchHighlighterTest.php
Umherirrender d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00

39 lines
1.1 KiB
PHP

<?php
/**
* @group Search
*/
class SearchHighlighterTest extends \MediaWikiIntegrationTestCase {
/**
* @dataProvider provideHighlightSimple
* @covers SearchHighlighter::highlightSimple
*/
public function testHighlightSimple( string $wikiText, string $searchTerm, string $expectedOutput, int $contextChars ) {
$highlighter = new \SearchHighlighter( false );
$actual = $highlighter->highlightSimple( $wikiText, [ $searchTerm ], 1, $contextChars );
$this->assertEquals( $expectedOutput, $actual );
}
public static function provideHighlightSimple() {
return [
'no match' => [
'this is a very simple text.',
'cannotmatch',
'',
10
],
'match a single word at the end of the string' => [
'this is a very simple text.',
'text',
"this is a very simple <span class=\"searchmatch\">text</span>.\n",
40
],
'utf-8 sequences should not be broken' => [
"text with long trailing UTF-8 sequences: " . str_repeat( "\u{1780}", 6 ) . ".",
'text',
"<span class=\"searchmatch\">text</span> with long trailing UTF-8 sequences: " . str_repeat( "\u{1780}", 5 ) . "\n",
41
],
];
}
}