Merge "Memory setting for djvutext is now a constant"
[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 parent::setUp();
18 }
19
20 /**
21 * Test for DiffHistoryBlob::xdiffAdler32()
22 * @dataProvider provideXdiffAdler32
23 */
24 function testXdiffAdler32( $input ) {
25 $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
26 $dhb = new DiffHistoryBlob;
27 $myHash = $dhb->xdiffAdler32( $input );
28 $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
29 "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
30 }
31
32 public static function provideXdiffAdler32() {
33 return array(
34 array( '', 'Empty string' ),
35 array( "\0", 'Null' ),
36 array( "\0\0\0", "Several nulls" ),
37 array( "Hello", "An ASCII string" ),
38 array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )
39 );
40 }
41 }