Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / deferred / SearchUpdateTest.php
blob602a1757ec47d7ca6be202d5a52e835628a89cb8
1 <?php
3 class MockSearch extends SearchEngine {
4 public static $id;
5 public static $title;
6 public static $text;
8 public function __construct( $db ) {
11 public function update( $id, $title, $text ) {
12 self::$id = $id;
13 self::$title = $title;
14 self::$text = $text;
18 /**
19 * @group Search
21 class SearchUpdateTest extends MediaWikiTestCase {
23 /**
24 * @var SearchUpdate
26 private $su;
28 protected function setUp() {
29 parent::setUp();
30 $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
31 $this->su = new SearchUpdate( 0, "" );
34 public function updateText( $text ) {
35 return trim( $this->su->updateText( $text ) );
38 /**
39 * @covers SearchUpdate::updateText
41 public function testUpdateText() {
42 $this->assertEquals(
43 'test',
44 $this->updateText( '<div>TeSt</div>' ),
45 'HTML stripped, text lowercased'
48 $this->assertEquals(
49 'foo bar boz quux',
50 $this->updateText( <<<EOT
51 <table style="color:red; font-size:100px">
52 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
53 <tr><td>boz</td><tr>quux</td></tr>
54 </table>
55 EOT
56 ), 'Stripping HTML tables' );
58 $this->assertEquals(
59 'a b',
60 $this->updateText( 'a > b' ),
61 'Handle unclosed tags'
64 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
66 $this->assertNotEquals(
67 '',
68 $this->updateText( $text ),
69 'Bug 18609'
73 /**
74 * @covers SearchUpdate::updateText
75 * Test bug 32712
76 * Test if unicode quotes in article links make its search index empty
78 public function testUnicodeLinkSearchIndexError() {
79 $text = "text „http://example.com“ text";
80 $result = $this->updateText( $text );
81 $processed = preg_replace( '/Q/u', 'Q', $result );
82 $this->assertTrue(
83 $processed != '',
84 'Link surrounded by unicode quotes should not fail UTF-8 validation'