MediaWiki
REL1_21
|
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 00021 class SearchUpdateTest extends MediaWikiTestCase { 00022 00023 protected function setUp() { 00024 parent::setUp(); 00025 $this->setMwGlobals( 'wgSearchType', 'MockSearch' ); 00026 } 00027 00028 function update( $text, $title = 'Test', $id = 1 ) { 00029 $u = new SearchUpdate( $id, $title, $text ); 00030 $u->doUpdate(); 00031 return array( MockSearch::$title, MockSearch::$text ); 00032 } 00033 00034 function updateText( $text ) { 00035 list( , $resultText ) = $this->update( $text ); 00036 $resultText = trim( $resultText ); // abstract from some implementation details 00037 return $resultText; 00038 } 00039 00040 function testUpdateText() { 00041 $this->assertEquals( 00042 'test', 00043 $this->updateText( '<div>TeSt</div>' ), 00044 'HTML stripped, text lowercased' 00045 ); 00046 00047 $this->assertEquals( 00048 'foo bar boz quux', 00049 $this->updateText( <<<EOT 00050 <table style="color:red; font-size:100px"> 00051 <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr> 00052 <tr><td>boz</td><tr>quux</td></tr> 00053 </table> 00054 EOT 00055 ), 'Stripping HTML tables' ); 00056 00057 $this->assertEquals( 00058 'a b', 00059 $this->updateText( 'a > b' ), 00060 'Handle unclosed tags' 00061 ); 00062 00063 $text = str_pad( "foo <barbarbar \n", 10000, 'x' ); 00064 00065 $this->assertNotEquals( 00066 '', 00067 $this->updateText( $text ), 00068 'Bug 18609' 00069 ); 00070 } 00071 00072 function testBug32712() { 00073 $text = "text „http://example.com“ text"; 00074 $result = $this->updateText( $text ); 00075 $processed = preg_replace( '/Q/u', 'Q', $result ); 00076 $this->assertTrue( 00077 $processed != '', 00078 'Link surrounded by unicode quotes should not fail UTF-8 validation' 00079 ); 00080 } 00081 }