|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace FileEye\MimeMap\Test; |
|
4
|
|
|
|
|
5
|
|
|
use FileEye\MimeMap\Extension; |
|
6
|
|
|
use FileEye\MimeMap\MappingException; |
|
7
|
|
|
|
|
8
|
|
|
class ExtensionTest extends MimeMapTestBase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testGetDefaultType(): void |
|
11
|
|
|
{ |
|
12
|
|
|
$this->assertSame('text/plain', (new Extension('txt'))->getDefaultType()); |
|
13
|
|
|
$this->assertSame('text/plain', (new Extension('TXT'))->getDefaultType()); |
|
14
|
|
|
$this->assertSame('image/png', (new Extension('png'))->getDefaultType()); |
|
15
|
|
|
$this->assertSame('application/vnd.oasis.opendocument.text', (new Extension('odt'))->getDefaultType()); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testGetStrictDefaultTypeUnknownExtension(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->expectException(MappingException::class); |
|
21
|
|
|
$this->expectExceptionMessage("No MIME type mapped to extension ohmygodthatisnoextension"); |
|
22
|
|
|
$this->assertSame('application/octet-stream', (new Extension('ohmygodthatisnoextension'))->getDefaultType()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testGetTypes(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->assertSame(['text/vnd.dvb.subtitle', 'image/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('sub'))->getTypes()); |
|
28
|
|
|
$this->assertSame(['text/vnd.dvb.subtitle', 'image/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('sUb'))->getTypes()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetStrictTypesUnknownExtension(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->expectException(MappingException::class); |
|
34
|
|
|
$this->expectExceptionMessage("No MIME type mapped to extension ohmygodthatisnoextension"); |
|
35
|
|
|
$this->assertSame(['application/octet-stream'], (new Extension('ohmygodthatisnoextension'))->getTypes()); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|