(bug 34428) Fixed hash mismatch errors in DiffHistoryBlob::patch() by simulating...
[lhc/web/wiklou.git] / tests / phpunit / includes / DiffHistoryBlobTest.php
1 <?php
2
3 class DiffHistoryBlobTest extends MediaWikiTestCase {
4 function setUp() {
5 if ( !extension_loaded( 'xdiff' ) ) {
6 $this->markTestSkipped( 'The xdiff extension is not available' );
7 return;
8 }
9 if ( !extension_loaded( 'hash' ) && !extension_loaded( 'mhash' ) ) {
10 $this->markTestSkipped( 'Neither the hash nor mhash extension is available' );
11 return;
12 }
13 }
14
15 /**
16 * Test for DiffHistoryBlob::xdiffAdler32()
17 * @dataProvider provideXdiffAdler32
18 */
19 function testXdiffAdler32( $input ) {
20 $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
21 $dhb = new DiffHistoryBlob;
22 $myHash = $dhb->xdiffAdler32( $input );
23 $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
24 "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
25 }
26
27 function provideXdiffAdler32() {
28 return array(
29 array( '', 'Empty string' ),
30 array( "\0", 'Null' ),
31 array( "\0\0\0", "Several nulls" ),
32 array( "Hello", "An ASCII string" ),
33 array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )
34 );
35 }
36 }