2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class MockSearch extends SearchEngine {
|
|
|
|
|
public static $id;
|
|
|
|
|
public static $title;
|
|
|
|
|
public static $text;
|
|
|
|
|
|
|
|
|
|
public function __construct( $db ) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update( $id, $title, $text ) {
|
|
|
|
|
self::$id = $id;
|
|
|
|
|
self::$title = $title;
|
|
|
|
|
self::$text = $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Search
|
2013-06-18 20:06:49 +00:00
|
|
|
* @group Database
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
2010-12-28 18:17:16 +00:00
|
|
|
class SearchUpdateTest extends MediaWikiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
$this->setMwGlobals( 'wgSearchType', 'MockSearch' );
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
function updateText( $text ) {
|
2013-06-18 20:06:49 +00:00
|
|
|
return trim( SearchUpdate::updateText( $text ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 20:30:43 +00:00
|
|
|
/**
|
|
|
|
|
* @covers SearchUpdate::updateText
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testUpdateText() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'test',
|
|
|
|
|
$this->updateText( '<div>TeSt</div>' ),
|
|
|
|
|
'HTML stripped, text lowercased'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'foo bar boz quux',
|
|
|
|
|
$this->updateText( <<<EOT
|
|
|
|
|
<table style="color:red; font-size:100px">
|
|
|
|
|
<tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
|
|
|
|
|
<tr><td>boz</td><tr>quux</td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
EOT
|
|
|
|
|
), 'Stripping HTML tables' );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'a b',
|
|
|
|
|
$this->updateText( 'a > b' ),
|
|
|
|
|
'Handle unclosed tags'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$text = str_pad( "foo <barbarbar \n", 10000, 'x' );
|
|
|
|
|
|
|
|
|
|
$this->assertNotEquals(
|
|
|
|
|
'',
|
|
|
|
|
$this->updateText( $text ),
|
|
|
|
|
'Bug 18609'
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-11-30 00:36:34 +00:00
|
|
|
|
2013-10-24 20:30:43 +00:00
|
|
|
/**
|
|
|
|
|
* @covers SearchUpdate::updateText
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testBug32712() {
|
2011-11-30 00:36:34 +00:00
|
|
|
$text = "text „http://example.com“ text";
|
|
|
|
|
$result = $this->updateText( $text );
|
|
|
|
|
$processed = preg_replace( '/Q/u', 'Q', $result );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$processed != '',
|
|
|
|
|
'Link surrounded by unicode quotes should not fail UTF-8 validation'
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|