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