Debian Codegraph @

tests/phpunit/unit/includes/libs/DeflateTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright (C) 2018 Kunal Mehta <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21 namespace Wikimedia\Tests;
22
23 use Deflate;
24 use MediaWikiTestCaseTrait;
25 use PHPUnit\Framework\TestCase;
26
27 /**
28 * @covers \Deflate
29 */
30 class DeflateTest extends TestCase {
31 use MediaWikiTestCaseTrait;
32
33 public static function provideIsDeflated() {
34 return [
35 // mw.deflate('foobar')
36 [ 'rawdeflate,S8vPT0osAgA=', true ],
37 [ 'abcdefghijklmnopqrstuvwxyz', false ],
38 ];
39 }
40
41 /**
42 * @dataProvider provideIsDeflated
43 */
44 public function testIsDeflated( $data, $expected ) {
45 $actual = Deflate::isDeflated( $data );
46 $this->assertSame( $expected, $actual );
47 }
48
49 public static function provideInflate() {
50 return [
51 [ 'rawdeflate,S8vPT0osAgA=', true, 'foobar' ],
52 // Fails base64_decode
53 [ 'rawdeflate,🌻', false, 'deflate-invaliddeflate' ],
54 // Fails gzinflate
55 [ 'rawdeflate,S8vPT0dfdAgB=', false, 'deflate-invaliddeflate' ],
56 ];
57 }
58
59 /**
60 * @dataProvider provideInflate
61 */
62 public function testInflate( $data, $ok, $value ) {
63 $actual = Deflate::inflate( $data );
64 if ( $ok ) {
65 $this->assertStatusOK( $actual );
66 $this->assertStatusValue( $value, $actual );
67 } else {
68 $this->assertStatusError( $value, $actual );
69 }
70 }
71 }