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' );
|
2012-02-16 23:27:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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" ) );
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 02:01:16 +00:00
|
|
|
public function provideXdiffAdler32() {
|
|
|
|
|
// Hack non-empty early return since PHPUnit expands this provider before running
|
|
|
|
|
// the setUp() which marks the test as skipped.
|
|
|
|
|
if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ [ '', 'Empty string' ] ];
|
2015-11-17 02:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ '', 'Empty string' ],
|
|
|
|
|
[ "\0", 'Null' ],
|
|
|
|
|
[ "\0\0\0", "Several nulls" ],
|
|
|
|
|
[ "Hello", "An ASCII string" ],
|
|
|
|
|
[ str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" ]
|
|
|
|
|
];
|
2012-02-16 23:27:00 +00:00
|
|
|
}
|
|
|
|
|
}
|