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 static function getSoftwareLink() { }
26 function getServerVersion() { }
27 function getType() { }
28 function getSearchEngine() { }
31 class MockSearch
extends SearchEngine
{
36 public function __construct( $db ) {
39 public function update( $id, $title, $text ) {
41 self
::$title = $title;
46 class SearchUpdateTest
extends PHPUnit_Framework_TestCase
{
52 function update( $text, $title = 'Test', $id = 1 ) {
53 $u = new SearchUpdate( $id, $title, $text );
55 return array( MockSearch
::$title, MockSearch
::$text );
58 function updateText( $text ) {
59 list( $title, $resultText ) = $this->update( $text );
60 $resultText = trim( $resultText ); // abstract from some implementation details
65 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
67 self
::$searchType = $wgSearchType;
68 self
::$dbtype = $wgDBtype;
69 self
::$factoryconf = $wgLBFactoryConf;
70 self
::$dbservers = $wgDBservers;
72 $wgSearchType = 'MockSearch';
74 $wgLBFactoryConf['class'] = 'LBFactory_Simple';
76 $wgContLang = Language
::factory( 'en' );
77 LBFactory
::destroyInstance();
81 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
83 LBFactory
::destroyInstance();
85 $wgSearchType = self
::$searchType;
86 $wgDBtype = self
::$dbtype;
87 $wgLBFactoryConf = self
::$factoryconf;
88 $wgDBservers = self
::$dbservers;
92 function testUpdateText() {
95 $this->updateText( '<div>TeSt</div>' ),
96 'HTML stripped, text lowercased'
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>
107 ), 'Stripping HTML tables' );
111 $this->updateText( 'a > b' ),
112 'Handle unclosed tags'
115 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
117 $this->assertNotEquals(
119 $this->updateText( $text ),