Merge "Slight improvements to FormSpecialPage behavior."
[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
32 return array( MockSearch::$title, MockSearch::$text );
33 }
34
35 function updateText( $text ) {
36 list( , $resultText ) = $this->update( $text );
37 $resultText = trim( $resultText ); // abstract from some implementation details
38 return $resultText;
39 }
40
41 function testUpdateText() {
42 $this->assertEquals(
43 'test',
44 $this->updateText( '<div>TeSt</div>' ),
45 'HTML stripped, text lowercased'
46 );
47
48 $this->assertEquals(
49 'foo bar boz quux',
50 $this->updateText( <<<EOT
51 <table style="color:red; font-size:100px">
52 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
53 <tr><td>boz</td><tr>quux</td></tr>
54 </table>
55 EOT
56 ), 'Stripping HTML tables' );
57
58 $this->assertEquals(
59 'a b',
60 $this->updateText( 'a > b' ),
61 'Handle unclosed tags'
62 );
63
64 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
65
66 $this->assertNotEquals(
67 '',
68 $this->updateText( $text ),
69 'Bug 18609'
70 );
71 }
72
73 function testBug32712() {
74 $text = "text „http://example.com“ text";
75 $result = $this->updateText( $text );
76 $processed = preg_replace( '/Q/u', 'Q', $result );
77 $this->assertTrue(
78 $processed != '',
79 'Link surrounded by unicode quotes should not fail UTF-8 validation'
80 );
81 }
82 }