TYPO3 CMS  TYPO3_8-7
IconRegistryTest.php
Go to the documentation of this file.
1 <?php
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 
20 
24 class IconRegistryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
29  protected $subject = null;
30 
34  protected $notRegisteredIconIdentifier = 'my-super-unregistered-identifier';
35 
39  protected function setUp()
40  {
41  $this->subject = new \TYPO3\CMS\Core\Imaging\IconRegistry();
42  }
43 
48  {
49  $result = $this->subject->getDefaultIconIdentifier();
50  $this->assertEquals($result, 'default-not-found');
51  }
52 
57  {
58  $result = $this->subject->isRegistered($this->subject->getDefaultIconIdentifier());
59  $this->assertEquals($result, true);
60  }
61 
66  {
67  $result = $this->subject->isRegistered($this->notRegisteredIconIdentifier);
68  $this->assertEquals($result, false);
69  }
70 
75  {
76  $unregisterdIcon = 'foo-bar-unregistered';
77  $this->assertFalse($this->subject->isRegistered($unregisterdIcon));
78  $this->subject->registerIcon($unregisterdIcon, FontawesomeIconProvider::class, [
79  'name' => 'pencil',
80  'additionalClasses' => 'fa-fw'
81  ]);
82  $this->assertTrue($this->subject->isRegistered($unregisterdIcon));
83  }
84 
89  {
90  $this->expectException(\InvalidArgumentException::class);
91  $this->expectExceptionCode(1437425803);
92 
93  $this->subject->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class);
94  }
95 
100  {
101  $this->expectException(\TYPO3\CMS\Core\Exception::class);
102  $this->expectExceptionCode(1437425804);
103 
104  $this->subject->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier);
105  }
106 
111  {
112  $result = $this->subject->getIconConfigurationByIdentifier('default-not-found');
113  // result must contain at least provider and options array
114  $this->assertArrayHasKey('provider', $result);
115  $this->assertArrayHasKey('options', $result);
116  // the provider must implement the IconProviderInterface
117  $this->assertTrue(in_array(IconProviderInterface::class, class_implements($result['provider'])));
118  }
119 
124  {
125  $this->assertInternalType('array', $this->subject->getAllRegisteredIconIdentifiers());
126  }
127 
132  {
133  $result = $this->subject->getAllRegisteredIconIdentifiers();
134  $this->assertInternalType('array', $result);
135  $this->assertContains('default-not-found', $result);
136  }
137 
142  {
143  $result = $this->subject->getIconIdentifierForFileExtension('');
144  $this->assertEquals('mimetypes-other-other', $result);
145  }
146 
151  {
152  $result = $this->subject->getIconIdentifierForFileExtension('xyz');
153  $this->assertEquals('mimetypes-other-other', $result);
154  }
155 
160  {
161  $result = $this->subject->getIconIdentifierForFileExtension('jpg');
162  $this->assertEquals('mimetypes-media-image', $result);
163  }
164 
169  {
170  $this->subject->registerFileExtension('abc', 'xyz');
171  $result = $this->subject->getIconIdentifierForFileExtension('abc');
172  $this->assertEquals('xyz', $result);
173  }
174 
179  {
180  $this->subject->registerFileExtension('jpg', 'xyz');
181  $result = $this->subject->getIconIdentifierForFileExtension('jpg');
182  $this->assertEquals('xyz', $result);
183  }
184 
189  {
190  $this->subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar');
191  $result = $this->subject->getIconIdentifierForMimeType('foo/bar');
192  $this->assertEquals('mimetype-foo-bar', $result);
193  }
194 
199  {
200  $this->subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar');
201  $result = $this->subject->getIconIdentifierForMimeType('video/*');
202  $this->assertEquals('mimetype-foo-bar', $result);
203  }
204 
209  {
210  $result = $this->subject->getIconIdentifierForMimeType('bar/foo');
211  $this->assertEquals(null, $result);
212  }
213 }