|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FileEye\MimeMap\test; |
|
4
|
|
|
|
|
5
|
|
|
use FileEye\MimeMap\Extension; |
|
6
|
|
|
use FileEye\MimeMap\MapHandler; |
|
7
|
|
|
use FileEye\MimeMap\Type; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class MapHandlerTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testAdd() |
|
13
|
|
|
{ |
|
14
|
|
|
$map = new MapHandler(); |
|
15
|
|
|
$map->addMapping('bingo/bongo', 'bngbng'); |
|
16
|
|
|
$this->assertSame(['bngbng'], (new Type('bingo/bongo'))->getExtensions()); |
|
17
|
|
|
$this->assertSame('bngbng', (new Type('bingo/bongo'))->getDefaultExtension()); |
|
18
|
|
|
$this->assertSame(['bingo/bongo'], (new Extension('bngbng'))->getTypes()); |
|
19
|
|
|
$this->assertSame('bingo/bongo', (new Extension('bngbng'))->getDefaultType()); |
|
20
|
|
|
|
|
21
|
|
|
// Adding an already existing mapping should not duplicate entries. |
|
22
|
|
|
$map->addMapping('bingo/bongo', 'bngbng'); |
|
23
|
|
|
$this->assertSame(['bngbng'], (new Type('bingo/bongo'))->getExtensions()); |
|
24
|
|
|
$this->assertSame(['bingo/bongo'], (new Extension('bngbng'))->getTypes()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testRemove() |
|
28
|
|
|
{ |
|
29
|
|
|
$map = new MapHandler(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertSame(['txt', 'text', 'conf', 'def', 'list', 'log', 'in'], (new Type('text/plain'))->getExtensions()); |
|
32
|
|
|
$this->assertSame('txt', (new Type('text/plain'))->getDefaultExtension()); |
|
33
|
|
|
$this->assertSame(['text/plain'], (new Extension('txt'))->getTypes()); |
|
34
|
|
|
$this->assertSame('text/plain', (new Extension('txt'))->getDefaultType()); |
|
35
|
|
|
|
|
36
|
|
|
$map->removeMapping('text/plain', 'txt'); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertSame(['text', 'conf', 'def', 'list', 'log', 'in'], (new Type('text/plain'))->getExtensions()); |
|
39
|
|
|
$this->assertSame('text', (new Type('text/plain'))->getDefaultExtension()); |
|
40
|
|
|
$this->assertSame(['application/octet-stream'], (new Extension('txt'))->getTypes(false)); |
|
41
|
|
|
$this->assertSame('application/octet-stream', (new Extension('txt'))->getDefaultType(false)); |
|
42
|
|
|
|
|
43
|
|
|
$map->removeType('text/plain'); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertSame([], (new Type('text/plain'))->getExtensions(false)); |
|
46
|
|
|
$this->assertSame(null, (new Type('text/plain'))->getDefaultExtension(false)); |
|
47
|
|
|
$this->assertSame(['application/octet-stream'], (new Extension('DEf'))->getTypes(false)); |
|
48
|
|
|
$this->assertSame('application/octet-stream', (new Extension('DeF'))->getDefaultType(false)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testSetExtensionDefaultType() |
|
52
|
|
|
{ |
|
53
|
|
|
$map = new MapHandler(); |
|
54
|
|
|
$this->assertSame(['text/vnd.dvb.subtitle', 'image/vnd.dvb.subtitle'], (new Extension('sub'))->getTypes()); |
|
55
|
|
|
$map->setExtensionDefaultType('SUB', 'image/vnd.dvb.subtitle'); |
|
56
|
|
|
$this->assertSame(['image/vnd.dvb.subtitle', 'text/vnd.dvb.subtitle'], (new Extension('SUB'))->getTypes()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testSetTypeDefaultExtension() |
|
60
|
|
|
{ |
|
61
|
|
|
$map = new MapHandler(); |
|
62
|
|
|
$this->assertSame(['jpeg', 'jpg', 'jpe'], (new Type('image/jpeg'))->getExtensions()); |
|
63
|
|
|
$map->setTypeDefaultExtension('image/jpeg', 'jpg'); |
|
64
|
|
|
$this->assertSame(['jpg', 'jpeg', 'jpe'], (new Type('image/JPEG'))->getExtensions()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|