3 class DiffHistoryBlobTest
extends MediaWikiTestCase
{
5 protected function setUp() {
8 $this->checkPHPExtension( 'hash' );
9 $this->checkPHPExtension( 'xdiff' );
11 if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
12 $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
18 * Test for DiffHistoryBlob::xdiffAdler32()
19 * @dataProvider provideXdiffAdler32
20 * @covers DiffHistoryBlob::xdiffAdler32
22 public function testXdiffAdler32( $input ) {
23 $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
24 $dhb = new DiffHistoryBlob
;
25 $myHash = $dhb->xdiffAdler32( $input );
26 $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
27 "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
30 public function provideXdiffAdler32() {
31 // Hack non-empty early return since PHPUnit expands this provider before running
32 // the setUp() which marks the test as skipped.
33 if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
34 return array( array( '', 'Empty string' ) );
38 array( '', 'Empty string' ),
39 array( "\0", 'Null' ),
40 array( "\0\0\0", "Several nulls" ),
41 array( "Hello", "An ASCII string" ),
42 array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )