Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / libs / mime / MSCompoundFileReaderTest.php
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 /**
18 * @group Media
19 * @covers MSCompoundFileReader
20 */
21 class MSCompoundFileReaderTest extends PHPUnit\Framework\TestCase {
22
23 protected function setUp() {
24 parent::setUp();
25
26 if ( php_uname( 's' ) === 'Darwin' ) {
27 $this->markTestSkipped(
28 'T225019: Disable this test on macOS for now due to byte-order issues'
29 );
30 }
31 }
32
33 public static function provideValid() {
34 return [
35 [ 'calc.xls', 'application/vnd.ms-excel' ],
36 [ 'excel2016-compat97.xls', 'application/vnd.ms-excel' ],
37 [ 'gnumeric.xls', 'application/vnd.ms-excel' ],
38 [ 'impress.ppt', 'application/vnd.ms-powerpoint' ],
39 [ 'powerpoint2016-compat97.ppt', 'application/vnd.ms-powerpoint' ],
40 [ 'word2016-compat97.doc', 'application/msword' ],
41 [ 'writer.doc', 'application/msword' ],
42 ];
43 }
44
45 /** @dataProvider provideValid */
46 public function testReadFile( $fileName, $expectedMime ) {
47 global $IP;
48
49 $info = MSCompoundFileReader::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
50 $this->assertTrue( $info['valid'] );
51 $this->assertSame( $expectedMime, $info['mime'] );
52 }
53
54 public static function provideInvalid() {
55 return [
56 [ 'dir-beyond-end.xls', 'ERROR_READ_PAST_END' ],
57 [ 'fat-loop.xls', 'ERROR_INVALID_FORMAT' ],
58 [ 'invalid-signature.xls', 'ERROR_INVALID_SIGNATURE' ],
59 ];
60 }
61
62 /** @dataProvider provideInvalid */
63 public function testReadFileInvalid( $fileName, $expectedError ) {
64 global $IP;
65
66 $info = MSCompoundFileReader::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
67 $this->assertFalse( $info['valid'] );
68 $this->assertSame( constant( MSCompoundFileReader::class . '::' . $expectedError ),
69 $info['errorCode'] );
70 }
71 }