Merge "FormatJson: Remove whitespace from empty arrays and objects"
[lhc/web/wiklou.git] / tests / phpunit / includes / search / 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 * @group Database
21 */
22 class SearchUpdateTest extends MediaWikiTestCase {
23
24 protected function setUp() {
25 parent::setUp();
26 $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
27 }
28
29 function updateText( $text ) {
30 return trim( SearchUpdate::updateText( $text ) );
31 }
32
33 /**
34 * @covers SearchUpdate::updateText
35 */
36 public function testUpdateText() {
37 $this->assertEquals(
38 'test',
39 $this->updateText( '<div>TeSt</div>' ),
40 'HTML stripped, text lowercased'
41 );
42
43 $this->assertEquals(
44 'foo bar boz quux',
45 $this->updateText( <<<EOT
46 <table style="color:red; font-size:100px">
47 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
48 <tr><td>boz</td><tr>quux</td></tr>
49 </table>
50 EOT
51 ), 'Stripping HTML tables' );
52
53 $this->assertEquals(
54 'a b',
55 $this->updateText( 'a > b' ),
56 'Handle unclosed tags'
57 );
58
59 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
60
61 $this->assertNotEquals(
62 '',
63 $this->updateText( $text ),
64 'Bug 18609'
65 );
66 }
67
68 /**
69 * @covers SearchUpdate::updateText
70 */
71 public function testBug32712() {
72 $text = "text „http://example.com“ text";
73 $result = $this->updateText( $text );
74 $processed = preg_replace( '/Q/u', 'Q', $result );
75 $this->assertTrue(
76 $processed != '',
77 'Link surrounded by unicode quotes should not fail UTF-8 validation'
78 );
79 }
80 }