Index: trunk/phase3/tests/SearchUpdateTest.php |
— | — | @@ -0,0 +1,103 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class DatabaseMock extends DatabaseBase { |
| 5 | + function __construct( $server = false, $user = false, $password = false, $dbName = false, |
| 6 | + $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) |
| 7 | + { |
| 8 | + $this->mConn = true; |
| 9 | + $this->mOpened = true; |
| 10 | + } |
| 11 | + |
| 12 | + function open( $server, $user, $password, $dbName ) { return true; } |
| 13 | + function doQuery( $sql ) {} |
| 14 | + function fetchObject( $res ) {} |
| 15 | + function fetchRow( $res ) {} |
| 16 | + function numRows( $res ) {} |
| 17 | + function numFields( $res ) {} |
| 18 | + function fieldName( $res, $n ) {} |
| 19 | + function insertId() {} |
| 20 | + function dataSeek( $res, $row ) {} |
| 21 | + function lastErrno() { return 0; } |
| 22 | + function lastError() { return ''; } |
| 23 | + function affectedRows() {} |
| 24 | + function fieldInfo( $table, $field ) {} |
| 25 | + function strencode( $s ) {} |
| 26 | + function getSoftwareLink() {} |
| 27 | + function getServerVersion() {} |
| 28 | + function getType() {} |
| 29 | +} |
| 30 | + |
| 31 | +class MockSearch extends SearchEngine { |
| 32 | + public static $id; |
| 33 | + public static $title; |
| 34 | + public static $text; |
| 35 | + |
| 36 | + public function __construct( $db ) { |
| 37 | + } |
| 38 | + |
| 39 | + public function update( $id, $title, $text ) { |
| 40 | + self::$id = $id; |
| 41 | + self::$title = $title; |
| 42 | + self::$text = $text; |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +class SearchUpdateTest extends PHPUnit_Framework_TestCase { |
| 47 | + |
| 48 | + function update( $text, $title = 'Test', $id = 1 ) { |
| 49 | + $u = new SearchUpdate( $id, $title, $text ); |
| 50 | + $u->doUpdate(); |
| 51 | + return array( MockSearch::$title, MockSearch::$text ); |
| 52 | + } |
| 53 | + |
| 54 | + function updateText( $text ) { |
| 55 | + list( $title, $resultText ) = $this->update( $text ); |
| 56 | + $resultText = trim( $resultText ); // abstract from some implementation details |
| 57 | + return $resultText; |
| 58 | + } |
| 59 | + |
| 60 | + function setUp() { |
| 61 | + global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers; |
| 62 | + $wgSearchType = 'MockSearch'; |
| 63 | + $wgDBtype = 'mock'; |
| 64 | + $wgLBFactoryConf['class'] = 'LBFactory_Simple'; |
| 65 | + $wgDBservers = null; |
| 66 | + LBFactory::destroyInstance(); |
| 67 | + } |
| 68 | + |
| 69 | + function tearDown() { |
| 70 | + LBFactory::destroyInstance(); |
| 71 | + } |
| 72 | + |
| 73 | + function testUpdateText() { |
| 74 | + $this->assertEquals( |
| 75 | + 'test', |
| 76 | + $this->updateText( '<div>TeSt</div>' ), |
| 77 | + 'HTML stripped, text lowercased' |
| 78 | + ); |
| 79 | + |
| 80 | + $this->assertEquals( |
| 81 | + 'foo bar boz quux', |
| 82 | + $this->updateText( <<<EOT |
| 83 | +<table style="color:red; font-size:100px"> |
| 84 | + <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr> |
| 85 | + <tr><td>boz</td><tr>quux</td></tr> |
| 86 | +</table> |
| 87 | +EOT |
| 88 | + ), 'Stripping HTML tables' ); |
| 89 | + |
| 90 | + $this->assertEquals( |
| 91 | + 'a b', |
| 92 | + $this->updateText( 'a > b' ), |
| 93 | + 'Handle unclosed tags' |
| 94 | + ); |
| 95 | + |
| 96 | + $text = str_pad( "foo <barbarbar \n", 10000, 'x' ); |
| 97 | + |
| 98 | + $this->assertNotEquals( |
| 99 | + '', |
| 100 | + $this->updateText( $text ), |
| 101 | + 'Bug 18609' |
| 102 | + ); |
| 103 | + } |
| 104 | +} |
Property changes on: trunk/phase3/tests/SearchUpdateTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 105 | + native |