File: SearchHighlighterTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (39 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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
			],
		];
	}
}