Merge "mediawiki.content.json: Remove file and author annotations"
[mediawiki.git] / tests / phpunit / includes / search / SearchUpdateTest.php
blobb2b97293e5662d5f623b676426bd2bb2164dfb9f
1 <?php
3 use MediaWiki\Page\PageIdentityValue;
4 use MediaWiki\Search\SearchUpdate;
6 /**
7 * @group Search
8 * @covers \MediaWiki\Search\SearchUpdate
9 */
10 class SearchUpdateTest extends MediaWikiIntegrationTestCase {
12 private SearchUpdate $su;
14 protected function setUp(): void {
15 parent::setUp();
16 $pageIdentity = new PageIdentityValue( 42, NS_MAIN, 'Main_Page', PageIdentityValue::LOCAL );
17 $this->su = new SearchUpdate( 0, $pageIdentity );
20 public function updateText( $text ) {
21 return trim( $this->su->updateText( $text ) );
24 public function testUpdateText() {
25 $this->assertEquals(
26 'test',
27 $this->updateText( '<div>TeSt</div>' ),
28 'HTML stripped, text lowercased'
31 $this->assertEquals(
32 'foo bar boz quux',
33 $this->updateText( <<<EOT
34 <table style="color:red; font-size:100px">
35 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
36 <tr><td>boz</td><tr>quux</td></tr>
37 </table>
38 EOT
39 ), 'Stripping HTML tables' );
41 $this->assertEquals(
42 'a b',
43 $this->updateText( 'a > b' ),
44 'Handle unclosed tags'
47 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
49 $this->assertNotEquals(
50 '',
51 $this->updateText( $text ),
52 'T20609'
56 /**
57 * T34712: Test if unicode quotes in article links make its search index empty
59 public function testUnicodeLinkSearchIndexError() {
60 $text = "text „http://example.com“ text";
61 $result = $this->updateText( $text );
62 $processed = preg_replace( '/Q/u', 'Q', $result );
63 $this->assertTrue(
64 $processed != '',
65 'Link surrounded by unicode quotes should not fail UTF-8 validation'