Merge "http://www.mediawiki.org --> https://www.mediawiki.org"
[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 $this->checkPHPExtension( 'hash' );
9 $this->checkPHPExtension( 'xdiff' );
10
11 if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
12 $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
13
14 return;
15 }
16 }
17
18 /**
19 * Test for DiffHistoryBlob::xdiffAdler32()
20 * @dataProvider provideXdiffAdler32
21 * @covers DiffHistoryBlob::xdiffAdler32
22 */
23 public 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 }