| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Deferred\SearchUpdate; |
| 4 |
use MediaWiki\Page\PageIdentityValue; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class SearchUpdateTest extends MediaWikiIntegrationTestCase { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
private $su; |
| 16 |
|
| 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 ); |
| 21 |
} |
| 22 |
|
| 23 |
public function updateText( $text ) { |
| 24 |
return trim( $this->su->updateText( $text ) ); |
| 25 |
} |
| 26 |
|
| 27 |
public function testUpdateText() { |
| 28 |
$this->assertEquals( |
| 29 |
'test', |
| 30 |
$this->updateText( '<div>TeSt</div>' ), |
| 31 |
'HTML stripped, text lowercased' |
| 32 |
); |
| 33 |
|
| 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' ); |
| 43 |
|
| 44 |
$this->assertEquals( |
| 45 |
'a b', |
| 46 |
$this->updateText( 'a > b' ), |
| 47 |
'Handle unclosed tags' |
| 48 |
); |
| 49 |
|
| 50 |
$text = str_pad( "foo <barbarbar \n", 10000, 'x' ); |
| 51 |
|
| 52 |
$this->assertNotEquals( |
| 53 |
'', |
| 54 |
$this->updateText( $text ), |
| 55 |
'T20609' |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 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' |
| 69 |
); |
| 70 |
} |
| 71 |
} |