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() {}
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
{
47 function update( $text, $title = 'Test', $id = 1 ) {
48 $u = new SearchUpdate( $id, $title, $text );
50 return array( MockSearch
::$title, MockSearch
::$text );
53 function updateText( $text ) {
54 list( $title, $resultText ) = $this->update( $text );
55 $resultText = trim( $resultText ); // abstract from some implementation details
60 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
61 $wgSearchType = 'MockSearch';
63 $wgLBFactoryConf['class'] = 'LBFactory_Simple';
65 LBFactory
::destroyInstance();
69 LBFactory
::destroyInstance();
72 function testUpdateText() {
75 $this->updateText( '<div>TeSt</div>' ),
76 'HTML stripped, text lowercased'
81 $this->updateText( <<<EOT
82 <table style="color:red; font-size:100px">
83 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
84 <tr><td>boz</td><tr>quux</td></tr>
87 ), 'Stripping HTML tables' );
91 $this->updateText( 'a > b' ),
92 'Handle unclosed tags'
95 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
97 $this->assertNotEquals(
99 $this->updateText( $text ),