MediaWiki  REL1_22
DiffHistoryBlobTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class DiffHistoryBlobTest extends MediaWikiTestCase {
00004     protected function setUp() {
00005         if ( !extension_loaded( 'xdiff' ) ) {
00006             $this->markTestSkipped( 'The xdiff extension is not available' );
00007 
00008             return;
00009         }
00010         if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
00011             $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
00012 
00013             return;
00014         }
00015         if ( !extension_loaded( 'hash' ) ) {
00016             $this->markTestSkipped( 'The hash extension is not available' );
00017 
00018             return;
00019         }
00020         parent::setUp();
00021     }
00022 
00027     public function testXdiffAdler32( $input ) {
00028         $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
00029         $dhb = new DiffHistoryBlob;
00030         $myHash = $dhb->xdiffAdler32( $input );
00031         $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
00032             "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
00033     }
00034 
00035     public static function provideXdiffAdler32() {
00036         return array(
00037             array( '', 'Empty string' ),
00038             array( "\0", 'Null' ),
00039             array( "\0\0\0", "Several nulls" ),
00040             array( "Hello", "An ASCII string" ),
00041             array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )
00042         );
00043     }
00044 }