[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Imaging / IconRegistryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Imaging;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider;
18 use TYPO3\CMS\Core\Imaging\IconProviderInterface;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * TestCase for \TYPO3\CMS\Core\Imaging\IconRegistry
23 */
24 class IconRegistryTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
25 {
26 /**
27 * @var \TYPO3\CMS\Core\Imaging\IconRegistry
28 */
29 protected $subject = null;
30
31 /**
32 * @var string
33 */
34 protected $notRegisteredIconIdentifier = 'my-super-unregistered-identifier';
35
36 /**
37 * Set up
38 *
39 * @return void
40 */
41 protected function setUp()
42 {
43 $this->subject = new \TYPO3\CMS\Core\Imaging\IconRegistry();
44 }
45
46 /**
47 * @test
48 */
49 public function getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString()
50 {
51 $result = $this->subject->getDefaultIconIdentifier();
52 $this->assertEquals($result, 'default-not-found');
53 }
54
55 /**
56 * @test
57 */
58 public function isRegisteredReturnsTrueForRegisteredIcon()
59 {
60 $result = $this->subject->isRegistered($this->subject->getDefaultIconIdentifier());
61 $this->assertEquals($result, true);
62 }
63
64 /**
65 * @test
66 */
67 public function isRegisteredReturnsFalseForNotRegisteredIcon()
68 {
69 $result = $this->subject->isRegistered($this->notRegisteredIconIdentifier);
70 $this->assertEquals($result, false);
71 }
72
73 /**
74 * @test
75 */
76 public function registerIconAddNewIconToRegistry()
77 {
78 $unregisterdIcon = 'foo-bar-unregistered';
79 $this->assertFalse($this->subject->isRegistered($unregisterdIcon));
80 $this->subject->registerIcon($unregisterdIcon, FontawesomeIconProvider::class, [
81 'name' => 'pencil',
82 'additionalClasses' => 'fa-fw'
83 ]);
84 $this->assertTrue($this->subject->isRegistered($unregisterdIcon));
85 }
86
87 /**
88 * @test
89 */
90 public function registerIconThrowsInvalidArgumentExceptionWithInvalidIconProvider()
91 {
92 $this->expectException(\InvalidArgumentException::class);
93 $this->expectExceptionCode(1437425803);
94
95 $this->subject->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class);
96 }
97
98 /**
99 * @test
100 */
101 public function getIconConfigurationByIdentifierThrowsExceptionWithUnregisteredIconIdentifier()
102 {
103 $this->expectException(\TYPO3\CMS\Core\Exception::class);
104 $this->expectExceptionCode(1437425804);
105
106 $this->subject->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier);
107 }
108
109 /**
110 * @test
111 */
112 public function getIconConfigurationByIdentifierReturnsCorrectConfiguration()
113 {
114 $result = $this->subject->getIconConfigurationByIdentifier('default-not-found');
115 // result must contain at least provider and options array
116 $this->assertArrayHasKey('provider', $result);
117 $this->assertArrayHasKey('options', $result);
118 // the provider must implement the IconProviderInterface
119 $this->assertTrue(in_array(IconProviderInterface::class, class_implements($result['provider'])));
120 }
121
122 /**
123 * @test
124 */
125 public function getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentiefiers()
126 {
127 $this->assertInternalType('array', $this->subject->getAllRegisteredIconIdentifiers());
128 }
129
130 /**
131 * @test
132 */
133 public function getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers()
134 {
135 $result = $this->subject->getAllRegisteredIconIdentifiers();
136 $this->assertInternalType('array', $result);
137 $this->assertContains('default-not-found', $result);
138 }
139
140 /**
141 * @test
142 */
143 public function getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension()
144 {
145 $result = $this->subject->getIconIdentifierForFileExtension('');
146 $this->assertEquals('mimetypes-other-other', $result);
147 }
148
149 /**
150 * @test
151 */
152 public function getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension()
153 {
154 $result = $this->subject->getIconIdentifierForFileExtension('xyz');
155 $this->assertEquals('mimetypes-other-other', $result);
156 }
157
158 /**
159 * @test
160 */
161 public function getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension()
162 {
163 $result = $this->subject->getIconIdentifierForFileExtension('jpg');
164 $this->assertEquals('mimetypes-media-image', $result);
165 }
166
167 /**
168 * @test
169 */
170 public function registerFileExtensionRegisterAnIcon()
171 {
172 $this->subject->registerFileExtension('abc', 'xyz');
173 $result = $this->subject->getIconIdentifierForFileExtension('abc');
174 $this->assertEquals('xyz', $result);
175 }
176
177 /**
178 * @test
179 */
180 public function registerFileExtensionOverwriteAnExistingIcon()
181 {
182 $this->subject->registerFileExtension('jpg', 'xyz');
183 $result = $this->subject->getIconIdentifierForFileExtension('jpg');
184 $this->assertEquals('xyz', $result);
185 }
186
187 /**
188 * @test
189 */
190 public function registerMimeTypeIconRegisterAnIcon()
191 {
192 $this->subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar');
193 $result = $this->subject->getIconIdentifierForMimeType('foo/bar');
194 $this->assertEquals('mimetype-foo-bar', $result);
195 }
196
197 /**
198 * @test
199 */
200 public function registerMimeTypeIconOverwriteAnExistingIcon()
201 {
202 $this->subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar');
203 $result = $this->subject->getIconIdentifierForMimeType('video/*');
204 $this->assertEquals('mimetype-foo-bar', $result);
205 }
206
207 /**
208 * @test
209 */
210 public function getIconIdentifierForMimeTypeWithUnknowMimeTypeReturnNull()
211 {
212 $result = $this->subject->getIconIdentifierForMimeType('bar/foo');
213 $this->assertEquals(null, $result);
214 }
215 }