Merge "Expand the info in 'resettokens-watchlist-token'"
[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
8 return;
9 }
10 if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
11 $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' );
12
13 return;
14 }
15 if ( !extension_loaded( 'hash' ) ) {
16 $this->markTestSkipped( 'The hash extension is not available' );
17
18 return;
19 }
20 parent::setUp();
21 }
22
23 /**
24 * Test for DiffHistoryBlob::xdiffAdler32()
25 * @dataProvider provideXdiffAdler32
26 */
27 function testXdiffAdler32( $input ) {
28 $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
29 $dhb = new DiffHistoryBlob;
30 $myHash = $dhb->xdiffAdler32( $input );
31 $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
32 "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
33 }
34
35 public static function provideXdiffAdler32() {
36 return array(
37 array( '', 'Empty string' ),
38 array( "\0", 'Null' ),
39 array( "\0\0\0", "Several nulls" ),
40 array( "Hello", "An ASCII string" ),
41 array( str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" )
42 );
43 }
44 }