Update declaration of UploadFromUrlTest::doApiRequest
[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 return;
14 }
15 }
16
17 /**
18 * Test for DiffHistoryBlob::xdiffAdler32()
19 * @dataProvider provideXdiffAdler32
20 * @covers DiffHistoryBlob::xdiffAdler32
21 */
22 public function testXdiffAdler32( $input ) {
23 $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 );
24 $dhb = new DiffHistoryBlob;
25 $myHash = $dhb->xdiffAdler32( $input );
26 $this->assertSame( bin2hex( $xdiffHash ), bin2hex( $myHash ),
27 "Hash of " . addcslashes( $input, "\0..\37!@\@\177..\377" ) );
28 }
29
30 public function provideXdiffAdler32() {
31 // Hack non-empty early return since PHPUnit expands this provider before running
32 // the setUp() which marks the test as skipped.
33 if ( !function_exists( 'xdiff_string_rabdiff' ) ) {
34 return [ [ '', 'Empty string' ] ];
35 }
36
37 return [
38 [ '', 'Empty string' ],
39 [ "\0", 'Null' ],
40 [ "\0\0\0", "Several nulls" ],
41 [ "Hello", "An ASCII string" ],
42 [ str_repeat( "x", 6000 ), "A string larger than xdiff's NMAX (5552)" ]
43 ];
44 }
45 }