00001 <?php
00002
00003 class DatabaseMock extends DatabaseBase {
00004 function __construct( $server = false, $user = false, $password = false, $dbName = false,
00005 $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
00006 {
00007 $this->mConn = true;
00008 $this->mOpened = true;
00009 }
00010
00011 function open( $server, $user, $password, $dbName ) { return true; }
00012 function doQuery( $sql ) {}
00013 function fetchObject( $res ) {}
00014 function fetchRow( $res ) {}
00015 function numRows( $res ) {}
00016 function numFields( $res ) {}
00017 function fieldName( $res, $n ) {}
00018 function insertId() {}
00019 function dataSeek( $res, $row ) {}
00020 function lastErrno() { return 0; }
00021 function lastError() { return ''; }
00022 function affectedRows() {}
00023 function fieldInfo( $table, $field ) {}
00024 function strencode( $s ) {}
00025 function getSoftwareLink() {}
00026 function getServerVersion() {}
00027 function getType() {}
00028 }
00029
00030 class MockSearch extends SearchEngine {
00031 public static $id;
00032 public static $title;
00033 public static $text;
00034
00035 public function __construct( $db ) {
00036 }
00037
00038 public function update( $id, $title, $text ) {
00039 self::$id = $id;
00040 self::$title = $title;
00041 self::$text = $text;
00042 }
00043 }
00044
00045 class SearchUpdateTest extends PHPUnit_Framework_TestCase {
00046
00047 function update( $text, $title = 'Test', $id = 1 ) {
00048 $u = new SearchUpdate( $id, $title, $text );
00049 $u->doUpdate();
00050 return array( MockSearch::$title, MockSearch::$text );
00051 }
00052
00053 function updateText( $text ) {
00054 list( $title, $resultText ) = $this->update( $text );
00055 $resultText = trim( $resultText );
00056 return $resultText;
00057 }
00058
00059 function setUp() {
00060 global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
00061 $wgSearchType = 'MockSearch';
00062 $wgDBtype = 'mock';
00063 $wgLBFactoryConf['class'] = 'LBFactory_Simple';
00064 $wgDBservers = null;
00065 LBFactory::destroyInstance();
00066 }
00067
00068 function tearDown() {
00069 LBFactory::destroyInstance();
00070 }
00071
00072 function testUpdateText() {
00073 $this->assertEquals(
00074 'test',
00075 $this->updateText( '<div>TeSt</div>' ),
00076 'HTML stripped, text lowercased'
00077 );
00078
00079 $this->assertEquals(
00080 'foo bar boz quux',
00081 $this->updateText( <<<EOT
00082 <table style="color:red; font-size:100px">
00083 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
00084 <tr><td>boz</td><tr>quux</td></tr>
00085 </table>
00086 EOT
00087 ), 'Stripping HTML tables' );
00088
00089 $this->assertEquals(
00090 'a b',
00091 $this->updateText( 'a > b' ),
00092 'Handle unclosed tags'
00093 );
00094
00095 $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
00096
00097 $this->assertNotEquals(
00098 '',
00099 $this->updateText( $text ),
00100 'Bug 18609'
00101 );
00102 }
00103 }