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