Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[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->setMwGlobals( 'wgSearchType', 'MockSearch' );
16 $this->su = new SearchUpdate( 0, "" );
17 }
18
19 public function updateText( $text ) {
20 return trim( $this->su->updateText( $text ) );
21 }
22
23 /**
24 * @covers SearchUpdate::updateText
25 */
26 public function testUpdateText() {
27 $this->assertEquals(
28 'test',
29 $this->updateText( '<div>TeSt</div>' ),
30 'HTML stripped, text lowercased'
31 );
32
33 $this->assertEquals(
34 'foo bar boz quux',
35 $this->updateText( <<<EOT
36 <table style="color:red; font-size:100px">
37 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
38 <tr><td>boz</td><tr>quux</td></tr>
39 </table>
40 EOT
41 ), 'Stripping HTML tables' );
42
43 $this->assertEquals(
44 'a b',
45 $this->updateText( 'a > b' ),
46 'Handle unclosed tags'
47 );
48
49 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
50
51 $this->assertNotEquals(
52 '',
53 $this->updateText( $text ),
54 'T20609'
55 );
56 }
57
58 /**
59 * @covers SearchUpdate::updateText
60 * Test T34712
61 * Test if unicode quotes in article links make its search index empty
62 */
63 public function testUnicodeLinkSearchIndexError() {
64 $text = "text „http://example.com“ text";
65 $result = $this->updateText( $text );
66 $processed = preg_replace( '/Q/u', 'Q', $result );
67 $this->assertTrue(
68 $processed != '',
69 'Link surrounded by unicode quotes should not fail UTF-8 validation'
70 );
71 }
72 }
73
74 class MockSearch extends SearchEngine {
75 public static $id;
76 public static $title;
77 public static $text;
78
79 public function update( $id, $title, $text ) {
80 self::$id = $id;
81 self::$title = $title;
82 self::$text = $text;
83 }
84 }