svn:eol-style native
[lhc/web/wiklou.git] / t / inc / SearchUpdate.t
1 #!/usr/bin/env php
2 <?php
3
4 require 't/Test.php';
5
6 plan( 4 );
7
8 define( 'MEDIAWIKI', 1 );
9 require 'includes/Defines.php';
10 require 'includes/ProfilerStub.php';
11 require 'includes/AutoLoader.php';
12 require 'LocalSettings.php';
13
14 require 't/DatabaseMock.inc';
15
16 $wgSearchType = 'MockSearch';
17
18 require 'includes/Setup.php';
19
20
21 class MockSearch extends SearchEngine {
22 public static $id;
23 public static $title;
24 public static $text;
25
26 public function __construct( $db ) {
27 }
28
29 public function update( $id, $title, $text ) {
30 self::$id = $id;
31 self::$title = $title;
32 self::$text = $text;
33 }
34 }
35
36 function update( $text, $title = 'Test', $id = 1 ) {
37 $u = new SearchUpdate( $id, $title, $text );
38 $u->doUpdate();
39 return array( MockSearch::$title, MockSearch::$text );
40 }
41
42 function updateText( $text ) {
43 list( $title, $resultText ) = update( $text );
44 $resultText = trim( $resultText ); // abstract from some implementation details
45 return $resultText;
46 }
47
48 is( updateText( '<div>TeSt</div>' ), 'test', 'HTML stripped, text lowercased' );
49
50 is( 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 ), 'foo bar boz quux', 'Stripping HTML tables' );
57
58 is( updateText( 'a > b' ), 'a b', 'Handle unclosed tags' );
59
60 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
61 ok( updateText( $text ) != '', 'Bug 18609' );