Simplify SearchUpdate constructor and hard deprecate some param types
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / SearchUpdateTest.php
1 <?php
2
3 /**
4 * @group Search
5 */
6 class SearchUpdateTest extends MediaWikiTestCase {
7
8 /**
9 * @var SearchUpdate
10 */
11 private $su;
12
13 protected function setUp() {
14 parent::setUp();
15 $this->su = new SearchUpdate( 0, Title::newMainPage() );
16 }
17
18 public function updateText( $text ) {
19 return trim( $this->su->updateText( $text ) );
20 }
21
22 /**
23 * @covers SearchUpdate::updateText
24 */
25 public function testUpdateText() {
26 $this->assertEquals(
27 'test',
28 $this->updateText( '<div>TeSt</div>' ),
29 'HTML stripped, text lowercased'
30 );
31
32 $this->assertEquals(
33 'foo bar boz quux',
34 $this->updateText( <<<EOT
35 <table style="color:red; font-size:100px">
36 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
37 <tr><td>boz</td><tr>quux</td></tr>
38 </table>
39 EOT
40 ), 'Stripping HTML tables' );
41
42 $this->assertEquals(
43 'a b',
44 $this->updateText( 'a > b' ),
45 'Handle unclosed tags'
46 );
47
48 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
49
50 $this->assertNotEquals(
51 '',
52 $this->updateText( $text ),
53 'T20609'
54 );
55 }
56
57 /**
58 * @covers SearchUpdate::updateText
59 * Test T34712
60 * Test if unicode quotes in article links make its search index empty
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 }
72
73 class MockSearch extends SearchEngine {
74 public static $id;
75 public static $title;
76 public static $text;
77
78 public function update( $id, $title, $text ) {
79 self::$id = $id;
80 self::$title = $title;
81 self::$text = $text;
82 }
83 }