3 * Copyright 2019 Wikimedia Foundation
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @covers MSCompoundFileReader
21 class MSCompoundFileReaderTest
extends PHPUnit\Framework\TestCase
{
22 public static function provideValid() {
24 [ 'calc.xls', 'application/vnd.ms-excel' ],
25 [ 'excel2016-compat97.xls', 'application/vnd.ms-excel' ],
26 [ 'gnumeric.xls', 'application/vnd.ms-excel' ],
27 [ 'impress.ppt', 'application/vnd.ms-powerpoint' ],
28 [ 'powerpoint2016-compat97.ppt', 'application/vnd.ms-powerpoint' ],
29 [ 'word2016-compat97.doc', 'application/msword' ],
30 [ 'writer.doc', 'application/msword' ],
34 /** @dataProvider provideValid */
35 public function testReadFile( $fileName, $expectedMime ) {
38 $info = MSCompoundFileReader
::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
39 $this->assertTrue( $info['valid'] );
40 $this->assertSame( $expectedMime, $info['mime'] );
43 public static function provideInvalid() {
45 [ 'dir-beyond-end.xls', 'ERROR_READ_PAST_END' ],
46 [ 'fat-loop.xls', 'ERROR_INVALID_FORMAT' ],
47 [ 'invalid-signature.xls', 'ERROR_INVALID_SIGNATURE' ],
51 /** @dataProvider provideInvalid */
52 public function testReadFileInvalid( $fileName, $expectedError ) {
55 $info = MSCompoundFileReader
::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
56 $this->assertFalse( $info['valid'] );
57 $this->assertSame( constant( MSCompoundFileReader
::class . '::' . $expectedError ),