Debian Codegraph @

tests/phpunit/unit/includes/libs/mime/MSCompoundFileReaderTest.php

raw symbols SCIP
1 <?php
2 /*
3 * Copyright 2019 Wikimedia Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software distributed
12 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
13 * OF ANY KIND, either express or implied. See the License for the
14 * specific language governing permissions and limitations under the License.
15 */
16
17 namespace Wikimedia\Tests\Mime;
18
19 use PHPUnit\Framework\TestCase;
20 use Wikimedia\Mime\MSCompoundFileReader;
21
22 /**
23 * @group Media
24 * @group Mime
25 * @covers \Wikimedia\Mime\MSCompoundFileReader
26 */
27 class MSCompoundFileReaderTest extends TestCase {
28 public static function provideValid() {
29 return [
30 [ 'calc.xls', 'application/vnd.ms-excel' ],
31 [ 'excel2016-compat97.xls', 'application/vnd.ms-excel' ],
32 [ 'gnumeric.xls', 'application/vnd.ms-excel' ],
33 [ 'impress.ppt', 'application/vnd.ms-powerpoint' ],
34 [ 'powerpoint2016-compat97.ppt', 'application/vnd.ms-powerpoint' ],
35 [ 'word2016-compat97.doc', 'application/msword' ],
36 [ 'writer.doc', 'application/msword' ],
37 ];
38 }
39
40 /** @dataProvider provideValid */
41 public function testReadFile( $fileName, $expectedMime ) {
42 global $IP;
43
44 $info = MSCompoundFileReader::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
45 $this->assertTrue( $info['valid'] );
46 $this->assertSame( $expectedMime, $info['mime'] );
47 }
48
49 public static function provideInvalid() {
50 return [
51 [ 'dir-beyond-end.xls', MSCompoundFileReader::ERROR_READ_PAST_END ],
52 [ 'fat-loop.xls', MSCompoundFileReader::ERROR_INVALID_FORMAT ],
53 [ 'invalid-signature.xls', MSCompoundFileReader::ERROR_INVALID_SIGNATURE ],
54 ];
55 }
56
57 /** @dataProvider provideInvalid */
58 public function testReadFileInvalid( $fileName, $expectedError ) {
59 global $IP;
60
61 $info = MSCompoundFileReader::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
62 $this->assertFalse( $info['valid'] );
63 $this->assertSame( $expectedError, $info['errorCode'] );
64 }
65 }