2012-02-16 23:27:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class DiffHistoryBlobTest extends MediaWikiTestCase {
|
2013-11-24 00:20:46 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2013-11-24 00:20:46 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2013-11-23 19:20:23 +00:00
|
|
|
$this->checkPHPExtension( 'hash' );
|
|
|
|
|
$this->checkPHPExtension( 'xdiff' );
|
2013-04-26 12:00:22 +00:00
|
|
|
|
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-16 23:27:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for DiffHistoryBlob::xdiffAdler32()
|
|
|
|
|
* @dataProvider provideXdiffAdler32
|
2013-10-24 10:54:02 +00:00
|
|
|
* @covers DiffHistoryBlob::xdiffAdler32
|
2012-02-16 23:27:00 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public 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)" )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|