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