Fixed dependencies for jquery.collapsibleTabs
[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 static $searchType;
23
24 function update( $text, $title = 'Test', $id = 1 ) {
25 $u = new SearchUpdate( $id, $title, $text );
26 $u->doUpdate();
27 return array( MockSearch::$title, MockSearch::$text );
28 }
29
30 function updateText( $text ) {
31 list( , $resultText ) = $this->update( $text );
32 $resultText = trim( $resultText ); // abstract from some implementation details
33 return $resultText;
34 }
35
36 function setUp() {
37 global $wgSearchType;
38
39 self::$searchType = $wgSearchType;
40 $wgSearchType = 'MockSearch';
41 }
42
43 function tearDown() {
44 global $wgSearchType;
45
46 $wgSearchType = self::$searchType;
47 }
48
49 function testUpdateText() {
50 $this->assertEquals(
51 'test',
52 $this->updateText( '<div>TeSt</div>' ),
53 'HTML stripped, text lowercased'
54 );
55
56 $this->assertEquals(
57 'foo bar boz quux',
58 $this->updateText( <<<EOT
59 <table style="color:red; font-size:100px">
60 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
61 <tr><td>boz</td><tr>quux</td></tr>
62 </table>
63 EOT
64 ), 'Stripping HTML tables' );
65
66 $this->assertEquals(
67 'a b',
68 $this->updateText( 'a > b' ),
69 'Handle unclosed tags'
70 );
71
72 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
73
74 $this->assertNotEquals(
75 '',
76 $this->updateText( $text ),
77 'Bug 18609'
78 );
79 }
80
81 function testBug32712() {
82 $text = "text „http://example.com“ text";
83 $result = $this->updateText( $text );
84 $processed = preg_replace( '/Q/u', 'Q', $result );
85 $this->assertTrue(
86 $processed != '',
87 'Link surrounded by unicode quotes should not fail UTF-8 validation'
88 );
89 }
90 }