Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / search / SearchUpdateTest.php
blob4bfa9d8665ef4d75815dc76e59473ce8046a986f
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 /**
13 * @var SearchUpdate
15 private $su;
17 protected function setUp(): void {
18 parent::setUp();
19 $pageIdentity = new PageIdentityValue( 42, NS_MAIN, 'Main_Page', PageIdentityValue::LOCAL );
20 $this->su = new SearchUpdate( 0, $pageIdentity );
23 public function updateText( $text ) {
24 return trim( $this->su->updateText( $text ) );
27 public function testUpdateText() {
28 $this->assertEquals(
29 'test',
30 $this->updateText( '<div>TeSt</div>' ),
31 'HTML stripped, text lowercased'
34 $this->assertEquals(
35 'foo bar boz quux',
36 $this->updateText( <<<EOT
37 <table style="color:red; font-size:100px">
38 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
39 <tr><td>boz</td><tr>quux</td></tr>
40 </table>
41 EOT
42 ), 'Stripping HTML tables' );
44 $this->assertEquals(
45 'a b',
46 $this->updateText( 'a > b' ),
47 'Handle unclosed tags'
50 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
52 $this->assertNotEquals(
53 '',
54 $this->updateText( $text ),
55 'T20609'
59 /**
60 * T34712: Test if unicode quotes in article links make its search index empty
62 public function testUnicodeLinkSearchIndexError() {
63 $text = "text „http://example.com“ text";
64 $result = $this->updateText( $text );
65 $processed = preg_replace( '/Q/u', 'Q', $result );
66 $this->assertTrue(
67 $processed != '',
68 'Link surrounded by unicode quotes should not fail UTF-8 validation'