Merge "(Bug 44987) Allow n=form in plural syntax"
[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 */
21 class SearchUpdateTest extends MediaWikiTestCase {
22
23 protected function setUp() {
24 parent::setUp();
25 $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
26 }
27
28 function update( $text, $title = 'Test', $id = 1 ) {
29 $u = new SearchUpdate( $id, $title, $text );
30 $u->doUpdate();
31 return array( MockSearch::$title, MockSearch::$text );
32 }
33
34 function updateText( $text ) {
35 list( , $resultText ) = $this->update( $text );
36 $resultText = trim( $resultText ); // abstract from some implementation details
37 return $resultText;
38 }
39
40 function testUpdateText() {
41 $this->assertEquals(
42 'test',
43 $this->updateText( '<div>TeSt</div>' ),
44 'HTML stripped, text lowercased'
45 );
46
47 $this->assertEquals(
48 'foo bar boz quux',
49 $this->updateText( <<<EOT
50 <table style="color:red; font-size:100px">
51 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
52 <tr><td>boz</td><tr>quux</td></tr>
53 </table>
54 EOT
55 ), 'Stripping HTML tables' );
56
57 $this->assertEquals(
58 'a b',
59 $this->updateText( 'a > b' ),
60 'Handle unclosed tags'
61 );
62
63 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
64
65 $this->assertNotEquals(
66 '',
67 $this->updateText( $text ),
68 'Bug 18609'
69 );
70 }
71
72 function testBug32712() {
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 }