ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MediaTypeManagerTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
20
21class MediaTypeManagerTest extends TestCase
22{
23 protected \ILIAS\MediaObjects\MediaType\MediaTypeManager $types;
24
25 protected function setUp(): void
26 {
27 parent::setUp();
28 }
29
30 protected function tearDown(): void
31 {
32 }
33
34 protected function getTypeManager(array $mime_blacklist = []): \ILIAS\MediaObjects\MediaType\MediaTypeManager
35 {
36 return new \ILIAS\MediaObjects\MediaType\MediaTypeManager($mime_blacklist);
37 }
38
39 public function testIsImage(): void
40 {
41 $this->assertEquals(
42 true,
43 $this->getTypeManager()->isImage("image/png")
44 );
45 }
46
47 public function testIsVideo(): void
48 {
49 $this->assertEquals(
50 true,
51 $this->getTypeManager()->isVideo("video/webm")
52 );
53 }
54
55 public function testIsAudio(): void
56 {
57 $this->assertEquals(
58 true,
59 $this->getTypeManager()->isAudio("audio/mpeg")
60 );
61 }
62
63 public function testGetAudioSuffixes(): void
64 {
65 $this->assertEquals(
66 ["mp3"],
67 iterator_to_array($this->getTypeManager()->getAudioSuffixes())
68 );
69 }
70
71 public function testGetVideoSuffixes(): void
72 {
73 $this->assertEquals(
74 ["mp4", "webm"],
75 iterator_to_array($this->getTypeManager()->getVideoSuffixes())
76 );
77 }
78
79 public function testGetImageSuffixes(): void
80 {
81 $this->assertEquals(
82 true,
83 in_array("png", iterator_to_array($this->getTypeManager()->getImageSuffixes()))
84 );
85 }
86
87 public function testGetOtherSuffixes(): void
88 {
89 $this->assertEquals(
90 true,
91 in_array("html", iterator_to_array($this->getTypeManager()->getOtherSuffixes()))
92 );
93 }
94
95 public function testGetAudioMimeTypes(): void
96 {
97 $this->assertEquals(
98 ["audio/mpeg"],
99 iterator_to_array($this->getTypeManager()->getAudioMimeTypes())
100 );
101 }
102
103 public function testGetVideoMimeTypes(): void
104 {
105 $this->assertEquals(
106 true,
107 in_array("video/mp4", iterator_to_array($this->getTypeManager()->getVideoMimeTypes()))
108 );
109 }
110
111 public function testGetImageMimeTypes(): void
112 {
113 $this->assertEquals(
114 true,
115 in_array("image/jpeg", iterator_to_array($this->getTypeManager()->getImageMimeTypes()))
116 );
117 }
118
119 public function testGetOtherMimeTypes(): void
120 {
121 $this->assertEquals(
122 true,
123 in_array("text/html", iterator_to_array($this->getTypeManager()->getOtherMimeTypes()))
124 );
125 }
126
127 public function testGetAllowedVideoMimeTypes(): void
128 {
129 $tm = $this->getTypeManager(["video/webm"]);
130
131 $this->assertEquals(
132 true,
133 in_array("video/mp4", iterator_to_array($tm->getAllowedVideoMimeTypes()), true)
134 );
135 $this->assertEquals(
136 false,
137 in_array("video/webm", iterator_to_array($tm->getAllowedVideoMimeTypes()), true)
138 );
139 }
140
141 public function testGetAllowedVideoSuffixes(): void
142 {
143 $tm = $this->getTypeManager(["video/webm"]);
144
145 $this->assertEquals(
146 true,
147 in_array("mp4", iterator_to_array($tm->getAllowedVideoSuffixes()), true)
148 );
149 $this->assertEquals(
150 false,
151 in_array("webm", iterator_to_array($tm->getAllowedVideoSuffixes()), true)
152 );
153 $this->assertEquals(
154 false,
155 in_array("png", iterator_to_array($tm->getAllowedVideoSuffixes()), true)
156 );
157 }
158
159 public function testIsHtmlAllowed(): void
160 {
161 $tm = $this->getTypeManager([""]);
162 $this->assertEquals(
163 true,
164 $tm->isHtmlAllowed()
165 );
166 $tm = $this->getTypeManager(["text/html"]);
167 $this->assertEquals(
168 false,
169 $tm->isHtmlAllowed()
170 );
171 }
172}
getTypeManager(array $mime_blacklist=[])
ILIAS MediaObjects MediaType MediaTypeManager $types
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.