MediaWiki  REL1_22
SearchUpdateTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class MockSearch extends SearchEngine {
00004     public static $id;
00005     public static $title;
00006     public static $text;
00007 
00008     public function __construct( $db ) {
00009     }
00010 
00011     public function update( $id, $title, $text ) {
00012         self::$id = $id;
00013         self::$title = $title;
00014         self::$text = $text;
00015     }
00016 }
00017 
00022 class SearchUpdateTest extends MediaWikiTestCase {
00023 
00024     protected function setUp() {
00025         parent::setUp();
00026         $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
00027     }
00028 
00029     function updateText( $text ) {
00030         return trim( SearchUpdate::updateText( $text ) );
00031     }
00032 
00033     public function testUpdateText() {
00034         $this->assertEquals(
00035             'test',
00036             $this->updateText( '<div>TeSt</div>' ),
00037             'HTML stripped, text lowercased'
00038         );
00039 
00040         $this->assertEquals(
00041             'foo bar boz quux',
00042             $this->updateText( <<<EOT
00043 <table style="color:red; font-size:100px">
00044     <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
00045     <tr><td>boz</td><tr>quux</td></tr>
00046 </table>
00047 EOT
00048             ), 'Stripping HTML tables' );
00049 
00050         $this->assertEquals(
00051             'a b',
00052             $this->updateText( 'a > b' ),
00053             'Handle unclosed tags'
00054         );
00055 
00056         $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
00057 
00058         $this->assertNotEquals(
00059             '',
00060             $this->updateText( $text ),
00061             'Bug 18609'
00062         );
00063     }
00064 
00065     public function testBug32712() {
00066         $text = "text „http://example.com“ text";
00067         $result = $this->updateText( $text );
00068         $processed = preg_replace( '/Q/u', 'Q', $result );
00069         $this->assertTrue(
00070             $processed != '',
00071             'Link surrounded by unicode quotes should not fail UTF-8 validation'
00072         );
00073     }
00074 }