re r71445 put static on the right method.
[lhc/web/wiklou.git] / maintenance / tests / SearchUpdateTest.php
1 <?php
2
3 class DatabaseMock extends DatabaseBase {
4 function __construct( $server = false, $user = false, $password = false, $dbName = false,
5 $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
6 {
7 $this->mConn = true;
8 $this->mOpened = true;
9 }
10
11 function open( $server, $user, $password, $dbName ) { return true; }
12 function doQuery( $sql ) { }
13 function fetchObject( $res ) { }
14 function fetchRow( $res ) { }
15 function numRows( $res ) { }
16 function numFields( $res ) { }
17 function fieldName( $res, $n ) { }
18 function insertId() { }
19 function dataSeek( $res, $row ) { }
20 function lastErrno() { return 0; }
21 function lastError() { return ''; }
22 function affectedRows() { }
23 function fieldInfo( $table, $field ) { }
24 function strencode( $s ) { }
25 static function getSoftwareLink() { }
26 function getServerVersion() { }
27 function getType() { }
28 function getSearchEngine() { }
29 }
30
31 class MockSearch extends SearchEngine {
32 public static $id;
33 public static $title;
34 public static $text;
35
36 public function __construct( $db ) {
37 }
38
39 public function update( $id, $title, $text ) {
40 self::$id = $id;
41 self::$title = $title;
42 self::$text = $text;
43 }
44 }
45
46 class SearchUpdateTest extends PHPUnit_Framework_TestCase {
47 static $searchType;
48 static $dbtype;
49 static $factoryconf;
50 static $dbservers;
51
52 function update( $text, $title = 'Test', $id = 1 ) {
53 $u = new SearchUpdate( $id, $title, $text );
54 $u->doUpdate();
55 return array( MockSearch::$title, MockSearch::$text );
56 }
57
58 function updateText( $text ) {
59 list( $title, $resultText ) = $this->update( $text );
60 $resultText = trim( $resultText ); // abstract from some implementation details
61 return $resultText;
62 }
63
64 function setUp() {
65 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
66
67 self::$searchType = $wgSearchType;
68 self::$dbtype = $wgDBtype;
69 self::$factoryconf = $wgLBFactoryConf;
70 self::$dbservers = $wgDBservers;
71
72 $wgSearchType = 'MockSearch';
73 $wgDBtype = 'mock';
74 $wgLBFactoryConf['class'] = 'LBFactory_Simple';
75 $wgDBservers = null;
76 $wgContLang = Language::factory( 'en' );
77 LBFactory::destroyInstance();
78 }
79
80 function tearDown() {
81 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
82
83 LBFactory::destroyInstance();
84
85 $wgSearchType = self::$searchType;
86 $wgDBtype = self::$dbtype;
87 $wgLBFactoryConf = self::$factoryconf;
88 $wgDBservers = self::$dbservers;
89 $wgContLang = null;
90 }
91
92 function testUpdateText() {
93 $this->assertEquals(
94 'test',
95 $this->updateText( '<div>TeSt</div>' ),
96 'HTML stripped, text lowercased'
97 );
98
99 $this->assertEquals(
100 'foo bar boz quux',
101 $this->updateText( <<<EOT
102 <table style="color:red; font-size:100px">
103 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
104 <tr><td>boz</td><tr>quux</td></tr>
105 </table>
106 EOT
107 ), 'Stripping HTML tables' );
108
109 $this->assertEquals(
110 'a b',
111 $this->updateText( 'a > b' ),
112 'Handle unclosed tags'
113 );
114
115 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
116
117 $this->assertNotEquals(
118 '',
119 $this->updateText( $text ),
120 'Bug 18609'
121 );
122 }
123 }