d46e683e1a607099ddff1e8ec24c8704a5c231c7
[lhc/web/wiklou.git] / tests / phpunit / includes / DiffHistoryBlobTest.php
1 <?php
2
3 class DiffHistoryBlobTest extends MediaWikiTestCase {
4 protected function setUp() {
5 if ( !extension_loaded( 'xdiff' ) ) {
6 $this->markTestSkipped( 'The xdiff extension is not available' );
7 return;
8 }
9 if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
10 $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
11 return;
12 }
13 if ( !extension_loaded( 'hash' ) && !extension_loaded( 'mhash' ) ) {
14 $this->markTestSkipped( 'Neither the hash nor mhash extension is available' );
15 return;
16 }
17 }
18
19 /**
20 * Test for DiffHistoryBlob::xdiffAdler32()
21 * @dataProvider provideXdiffAdler32
22 */
23 function testXdiffAdler32( $input ) {
24 $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
25 $dhb = new DiffHistoryBlob;
26 $myHash = $dhb->xdiffAdler32( $input );
27 $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
28 "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
29 }
30
31 public static function provideXdiffAdler32() {
32 return array(
33 array( '', 'Empty string' ),
34 array( "\0", 'Null' ),
35 array( "\0\0\0", "Several nulls" ),
36 array( "Hello", "An ASCII string" ),
37 array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )
38 );
39 }
40 }