Merge "(bug 46463) Mark edit preview as in page view language"
[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 function testUpdateText() {
34 $this->assertEquals(
35 'test',
36 $this->updateText( '<div>TeSt</div>' ),
37 'HTML stripped, text lowercased'
38 );
39
40 $this->assertEquals(
41 'foo bar boz quux',
42 $this->updateText( <<<EOT
43 <table style="color:red; font-size:100px">
44 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
45 <tr><td>boz</td><tr>quux</td></tr>
46 </table>
47 EOT
48 ), 'Stripping HTML tables' );
49
50 $this->assertEquals(
51 'a b',
52 $this->updateText( 'a > b' ),
53 'Handle unclosed tags'
54 );
55
56 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
57
58 $this->assertNotEquals(
59 '',
60 $this->updateText( $text ),
61 'Bug 18609'
62 );
63 }
64
65 function testBug32712() {
66 $text = "text „http://example.com“ text";
67 $result = $this->updateText( $text );
68 $processed = preg_replace( '/Q/u', 'Q', $result );
69 $this->assertTrue(
70 $processed != '',
71 'Link surrounded by unicode quotes should not fail UTF-8 validation'
72 );
73 }
74 }