Merge "content: Recognise .json as JsonContent in User and MediaWiki namespace"
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / SearchUpdateTest.php
1 <?php
2
3 class MockSearch extends SearchEngine {
4 public static $id;
5 public static $title;
6 public static $text;
7
8 public function __construct( $db ) {
9 }
10
11 public function update( $id, $title, $text ) {
12 self::$id = $id;
13 self::$title = $title;
14 self::$text = $text;
15 }
16 }
17
18 /**
19 * @group Search
20 */
21 class SearchUpdateTest extends MediaWikiTestCase {
22
23 protected function setUp() {
24 parent::setUp();
25 $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
26 }
27
28 public function updateText( $text ) {
29 return trim( SearchUpdate::updateText( $text ) );
30 }
31
32 /**
33 * @covers SearchUpdate::updateText
34 */
35 public function testUpdateText() {
36 $this->assertEquals(
37 'test',
38 $this->updateText( '<div>TeSt</div>' ),
39 'HTML stripped, text lowercased'
40 );
41
42 $this->assertEquals(
43 'foo bar boz quux',
44 $this->updateText( <<<EOT
45 <table style="color:red; font-size:100px">
46 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
47 <tr><td>boz</td><tr>quux</td></tr>
48 </table>
49 EOT
50 ), 'Stripping HTML tables' );
51
52 $this->assertEquals(
53 'a b',
54 $this->updateText( 'a > b' ),
55 'Handle unclosed tags'
56 );
57
58 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
59
60 $this->assertNotEquals(
61 '',
62 $this->updateText( $text ),
63 'Bug 18609'
64 );
65 }
66
67 /**
68 * @covers SearchUpdate::updateText
69 * Test bug 32712
70 * Test if unicode quotes in article links make its search index empty
71 */
72 public function testUnicodeLinkSearchIndexError() {
73 $text = "text „http://example.com“ text";
74 $result = $this->updateText( $text );
75 $processed = preg_replace( '/Q/u', 'Q', $result );
76 $this->assertTrue(
77 $processed != '',
78 'Link surrounded by unicode quotes should not fail UTF-8 validation'
79 );
80 }
81 }