2012-02-16 23:27:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class DiffHistoryBlobTest extends MediaWikiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-02-16 23:27:00 +00:00
|
|
|
if ( !extension_loaded( 'xdiff' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'The xdiff extension is not available' );
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2012-02-16 23:27:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-02-20 16:03:40 +00:00
|
|
|
if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2012-02-20 16:03:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2013-07-30 15:44:03 +00:00
|
|
|
if ( !extension_loaded( 'hash' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'The hash extension is not available' );
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2012-02-16 23:27:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-12-06 16:22:18 +00:00
|
|
|
parent::setUp();
|
2012-02-16 23:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for DiffHistoryBlob::xdiffAdler32()
|
|
|
|
|
* @dataProvider provideXdiffAdler32
|
|
|
|
|
*/
|
|
|
|
|
function testXdiffAdler32( $input ) {
|
2013-01-28 10:27:15 +00:00
|
|
|
$xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
|
2012-02-16 23:27:00 +00:00
|
|
|
$dhb = new DiffHistoryBlob;
|
|
|
|
|
$myHash = $dhb->xdiffAdler32( $input );
|
|
|
|
|
$this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
|
|
|
|
|
"Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideXdiffAdler32() {
|
2012-02-16 23:27:00 +00:00
|
|
|
return array(
|
|
|
|
|
array( '', 'Empty string' ),
|
|
|
|
|
array( "\0", 'Null' ),
|
|
|
|
|
array( "\0\0\0", "Several nulls" ),
|
|
|
|
|
array( "Hello", "An ASCII string" ),
|
|
|
|
|
array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|