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' )
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 function getSoftwareLink() { }
26 function getServerVersion() { }
27 function getType() { }
30 class MockSearch
extends SearchEngine
{
35 public function __construct( $db ) {
38 public function update( $id, $title, $text ) {
40 self
::$title = $title;
45 class SearchUpdateTest
extends PHPUnit_Framework_TestCase
{
51 function update( $text, $title = 'Test', $id = 1 ) {
52 $u = new SearchUpdate( $id, $title, $text );
54 return array( MockSearch
::$title, MockSearch
::$text );
57 function updateText( $text ) {
58 list( $title, $resultText ) = $this->update( $text );
59 $resultText = trim( $resultText ); // abstract from some implementation details
64 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
66 self
::$searchType = $wgSearchType;
67 self
::$dbtype = $wgDBtype;
68 self
::$factoryconf = $wgLBFactoryConf;
69 self
::$dbservers = $wgDBservers;
71 $wgSearchType = 'MockSearch';
73 $wgLBFactoryConf['class'] = 'LBFactory_Simple';
75 LBFactory
::destroyInstance();
79 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
81 LBFactory
::destroyInstance();
83 $wgSearchType = self
::$searchType;
84 $wgDBtype = self
::$dbtype;
85 $wgLBFactoryConf = self
::$factoryconf;
86 $wgDBservers = self
::$dbservers;
89 function testUpdateText() {
92 $this->updateText( '<div>TeSt</div>' ),
93 'HTML stripped, text lowercased'
98 $this->updateText( <<<EOT
99 <table style="color:red; font-size:100px">
100 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
101 <tr><td>boz</td><tr>quux</td></tr>
104 ), 'Stripping HTML tables' );
108 $this->updateText( 'a > b' ),
109 'Handle unclosed tags'
112 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
114 $this->assertNotEquals(
116 $this->updateText( $text ),