| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
namespace Wikimedia\Tests\Mime; |
| 18 |
|
| 19 |
use PHPUnit\Framework\TestCase; |
| 20 |
use Wikimedia\Mime\MSCompoundFileReader; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 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 |
|
| 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 |
|
| 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 |
} |