|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FileEye\MimeMap\Test; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
6
|
|
|
use FileEye\MimeMap\MapHandler; |
|
7
|
|
|
use FileEye\MimeMap\MapUpdater; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @coversDefaultClass \FileEye\MimeMap\MapUpdater |
|
11
|
|
|
* @backupStaticAttributes enabled |
|
12
|
|
|
*/ |
|
13
|
|
|
class MapUpdaterTest extends MimeMapTestBase |
|
14
|
|
|
{ |
|
15
|
|
|
protected $newMap; |
|
16
|
|
|
protected $updater; |
|
17
|
|
|
protected $fileSystem; |
|
18
|
|
|
|
|
19
|
|
|
public function fcSetUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->newMap = MapHandler::map('\FileEye\MimeMap\Map\EmptyMap'); |
|
22
|
|
|
$this->assertInstanceOf('\FileEye\MimeMap\Map\EmptyMap', $this->newMap); |
|
23
|
|
|
$this->updater = new MapUpdater($this->newMap); |
|
24
|
|
|
$this->fileSystem = new Filesystem(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function fcTearDown() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertInstanceOf('\FileEye\MimeMap\Map\EmptyMap', $this->newMap); |
|
30
|
|
|
$this->newMap->reset(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testLoadMapFromApacheFile() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt'); |
|
36
|
|
|
$expected = [ |
|
37
|
|
|
't' => [ |
|
38
|
|
|
'image/jpeg' => ['e' => ['jpeg', 'jpg', 'jpe']], |
|
39
|
|
|
'text/plain' => ['e' => ['txt']], |
|
40
|
|
|
], |
|
41
|
|
|
'e' => [ |
|
42
|
|
|
'jpe' => ['t' => ['image/jpeg']], |
|
43
|
|
|
'jpeg' => ['t' => ['image/jpeg']], |
|
44
|
|
|
'jpg' => ['t' => ['image/jpeg']], |
|
45
|
|
|
'txt' => ['t' => ['text/plain']], |
|
46
|
|
|
], |
|
47
|
|
|
]; |
|
48
|
|
|
$this->assertSame($expected, $this->newMap->getMapArray()); |
|
49
|
|
|
$this->assertSame(['image/jpeg', 'text/plain'], $this->newMap->listTypes()); |
|
50
|
|
|
$this->assertSame(['jpe', 'jpeg', 'jpg', 'txt'], $this->newMap->listExtensions()); |
|
51
|
|
|
$this->assertSame([], $this->newMap->listAliases()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testLoadMapFromApacheFileZeroLines() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/zero.mime-types.txt'); |
|
57
|
|
|
$this->assertSame([], $this->newMap->getMapArray()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testLoadMapFromFreedesktopFile() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->updater->applyOverrides([['addTypeExtensionMapping', ['application/x-pdf', 'pdf']]]); |
|
63
|
|
|
$errors = $this->updater->loadMapFromFreedesktopFile(dirname(__FILE__) . '/../fixtures/min.freedesktop.xml'); |
|
64
|
|
|
$this->assertSame(["Cannot set 'application/x-pdf' as alias for 'application/pdf', 'application/x-pdf' is already defined as a type"], $errors); |
|
65
|
|
|
$expected = [ |
|
66
|
|
|
't' => [ |
|
67
|
|
|
'application/pdf' => [ |
|
68
|
|
|
'a' => ['image/pdf', 'application/acrobat', 'application/nappdf'], |
|
69
|
|
|
'desc' => ['PDF document', 'PDF: Portable Document Format'], |
|
70
|
|
|
'e' => ['pdf'] |
|
71
|
|
|
], |
|
72
|
|
|
'application/x-atari-2600-rom' => [ |
|
73
|
|
|
'desc' => ['Atari 2600'], |
|
74
|
|
|
'e' => ['a26'] |
|
75
|
|
|
], |
|
76
|
|
|
'application/x-pdf' => [ |
|
77
|
|
|
'e' => ['pdf'] |
|
78
|
|
|
], |
|
79
|
|
|
'text/plain' => [ |
|
80
|
|
|
'desc' => ['plain text document'], |
|
81
|
|
|
'e' => ['txt', 'asc'] |
|
82
|
|
|
], |
|
83
|
|
|
], |
|
84
|
|
|
'e' => [ |
|
85
|
|
|
'a26' => ['t' => ['application/x-atari-2600-rom']], |
|
86
|
|
|
'asc' => ['t' => ['text/plain']], |
|
87
|
|
|
'pdf' => ['t' => ['application/x-pdf', 'application/pdf']], |
|
88
|
|
|
'txt' => ['t' => ['text/plain']], |
|
89
|
|
|
], |
|
90
|
|
|
'a' => [ |
|
91
|
|
|
'application/acrobat' => ['t' => ['application/pdf']], |
|
92
|
|
|
'application/nappdf' => ['t' => ['application/pdf']], |
|
93
|
|
|
'image/pdf' => ['t' => ['application/pdf']], |
|
94
|
|
|
], |
|
95
|
|
|
]; |
|
96
|
|
|
$this->assertSame($expected, $this->newMap->getMapArray()); |
|
97
|
|
|
$this->assertSame(['application/pdf', 'application/x-atari-2600-rom', 'application/x-pdf', 'text/plain'], $this->newMap->listTypes()); |
|
98
|
|
|
$this->assertSame(['a26', 'asc', 'pdf', 'txt'], $this->newMap->listExtensions()); |
|
99
|
|
|
$this->assertSame(['application/acrobat', 'application/nappdf', 'image/pdf'], $this->newMap->listAliases()); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testLoadMapFromFreedesktopFileZeroLines() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->updater->loadMapFromFreedesktopFile(dirname(__FILE__) . '/../fixtures/zero.freedesktop.xml'); |
|
105
|
|
|
$this->assertSame([], $this->newMap->getMapArray()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @expectedException \LogicException |
|
110
|
|
|
*/ |
|
111
|
|
|
public function testEmptyMapNotWriteable() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->assertNull($this->newMap->getFileName()); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testWriteMapToPhpClassFile() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->fileSystem->copy(__DIR__ . '/../../src/Map/MiniMap.php.test', __DIR__ . '/../../src/Map/MiniMap.php'); |
|
119
|
|
|
MapHandler::setDefaultMapClass('\FileEye\MimeMap\Map\MiniMap'); |
|
120
|
|
|
$map_a = MapHandler::map(); |
|
121
|
|
|
$this->assertContains('src/Map/MiniMap.php', $map_a->getFileName()); |
|
122
|
|
|
$content = file_get_contents($map_a->getFileName()); |
|
123
|
|
|
$this->assertNotContains('text/plain', $content); |
|
124
|
|
|
$this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt'); |
|
125
|
|
|
$this->updater->applyOverrides([['addTypeExtensionMapping', ['bing/bong', 'binbon']]]); |
|
126
|
|
|
$this->updater->writeMapToPhpClassFile($map_a->getFileName()); |
|
127
|
|
|
$content = file_get_contents($map_a->getFileName()); |
|
128
|
|
|
$this->assertContains('text/plain', $content); |
|
129
|
|
|
$this->assertContains('bing/bong', $content); |
|
130
|
|
|
$this->assertContains('binbon', $content); |
|
131
|
|
|
$this->fileSystem->remove(__DIR__ . '/../../src/Map/MiniMap.php'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function testGetDefaultMapBuildFile() |
|
135
|
|
|
{ |
|
136
|
|
|
$this->assertContains('default_map_build.yml', MapUpdater::getDefaultMapBuildFile()); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|