‪TYPO3CMS  10.4
IconRegistryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪IconRegistryTest extends UnitTestCase
32 {
36  protected ‪$notRegisteredIconIdentifier = 'my-super-unregistered-identifier';
37 
38  public function ‪setUp(): void
39  {
40  parent::setUp();
41  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
42  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
43  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
44  $cacheManagerProphecy->getCache('assets')->willReturn($cacheFrontendProphecy->reveal());
45  $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
46  $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
47  }
48 
49  public function ‪tearDown(): void
50  {
51  // Drop cache manager singleton again
52  GeneralUtility::purgeInstances();
53  parent::tearDown();
54  }
55 
60  {
61  $result = (new ‪IconRegistry())->getDefaultIconIdentifier();
62  self::assertEquals($result, 'default-not-found');
63  }
64 
69  {
70  $subject = new IconRegistry();
71  $result = $subject->isRegistered($subject->getDefaultIconIdentifier());
72  self::assertEquals($result, true);
73  }
74 
79  {
80  $result = (new IconRegistry())->isRegistered($this->notRegisteredIconIdentifier);
81  self::assertEquals($result, false);
82  }
83 
87  public function ‪registerIconAddNewIconToRegistry()
88  {
89  $unregisteredIcon = 'foo-bar-unregistered';
90  $subject = new IconRegistry();
91  self::assertFalse($subject->isRegistered($unregisteredIcon));
92  $subject->registerIcon($unregisteredIcon, FontawesomeIconProvider::class, [
93  'name' => 'pencil',
94  'additionalClasses' => 'fa-fw'
95  ]);
96  self::assertTrue($subject->isRegistered($unregisteredIcon));
97  }
98 
103  {
104  $this->expectException(\InvalidArgumentException::class);
105  $this->expectExceptionCode(1437425803);
106 
107  (new IconRegistry())->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class);
108  }
109 
114  {
115  $this->expectException(Exception::class);
116  $this->expectExceptionCode(1437425804);
117 
118  (new IconRegistry())->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier);
119  }
120 
125  {
126  $result = (new IconRegistry())->getIconConfigurationByIdentifier('default-not-found');
127  // result must contain at least provider and options array
128  self::assertArrayHasKey('provider', $result);
129  self::assertArrayHasKey('options', $result);
130  // the provider must implement the IconProviderInterface
131  self::assertTrue(in_array(IconProviderInterface::class, class_implements($result['provider'])));
132  }
133 
138  {
139  self::assertIsArray((new IconRegistry())->getAllRegisteredIconIdentifiers());
140  }
141 
146  {
147  $result = (new IconRegistry())->getAllRegisteredIconIdentifiers();
148  self::assertIsArray($result);
149  self::assertContains('default-not-found', $result);
150  }
151 
156  {
157  $result = (new IconRegistry())->getIconIdentifierForFileExtension('');
158  self::assertEquals('mimetypes-other-other', $result);
159  }
160 
165  {
166  $result = (new IconRegistry())->getIconIdentifierForFileExtension('xyz');
167  self::assertEquals('mimetypes-other-other', $result);
168  }
169 
174  {
175  $result = (new IconRegistry())->getIconIdentifierForFileExtension('jpg');
176  self::assertEquals('mimetypes-media-image', $result);
177  }
178 
183  {
184  $subject = new IconRegistry();
185  $subject->registerFileExtension('abc', 'xyz');
186  $result = $subject->getIconIdentifierForFileExtension('abc');
187  self::assertEquals('xyz', $result);
188  }
189 
194  {
195  $subject = new IconRegistry();
196  $subject->registerFileExtension('jpg', 'xyz');
197  $result = $subject->getIconIdentifierForFileExtension('jpg');
198  self::assertEquals('xyz', $result);
199  }
200 
204  public function ‪registerMimeTypeIconRegisterAnIcon()
205  {
206  $subject = new IconRegistry();
207  $subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar');
208  $result = $subject->getIconIdentifierForMimeType('foo/bar');
209  self::assertEquals('mimetype-foo-bar', $result);
210  }
211 
216  {
217  $subject = new IconRegistry();
218  $subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar');
219  $result = $subject->getIconIdentifierForMimeType('video/*');
220  self::assertEquals('mimetype-foo-bar', $result);
221  }
222 
227  {
228  $result = (new IconRegistry())->getIconIdentifierForMimeType('bar/foo');
229  self::assertNull($result);
230  }
231 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension
‪getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension()
Definition: IconRegistryTest.php:154
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers
‪getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers()
Definition: IconRegistryTest.php:144
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\setUp
‪setUp()
Definition: IconRegistryTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\isRegisteredReturnsFalseForNotRegisteredIcon
‪isRegisteredReturnsFalseForNotRegisteredIcon()
Definition: IconRegistryTest.php:77
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerFileExtensionOverwriteAnExistingIcon
‪registerFileExtensionOverwriteAnExistingIcon()
Definition: IconRegistryTest.php:192
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest
Definition: IconRegistryTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension
‪getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension()
Definition: IconRegistryTest.php:163
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForMimeTypeWithUnknownMimeTypeReturnNull
‪getIconIdentifierForMimeTypeWithUnknownMimeTypeReturnNull()
Definition: IconRegistryTest.php:225
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerFileExtensionRegisterAnIcon
‪registerFileExtensionRegisterAnIcon()
Definition: IconRegistryTest.php:181
‪TYPO3\CMS\Core\Tests\Unit\Imaging
Definition: DimensionTest.php:16
‪TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider
Definition: FontawesomeIconProvider.php:25
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\$notRegisteredIconIdentifier
‪string $notRegisteredIconIdentifier
Definition: IconRegistryTest.php:35
‪TYPO3\CMS\Core\Imaging\IconProviderInterface
Definition: IconProviderInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentifiers
‪getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentifiers()
Definition: IconRegistryTest.php:136
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconConfigurationByIdentifierReturnsCorrectConfiguration
‪getIconConfigurationByIdentifierReturnsCorrectConfiguration()
Definition: IconRegistryTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension
‪getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension()
Definition: IconRegistryTest.php:172
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:38
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\tearDown
‪tearDown()
Definition: IconRegistryTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString
‪getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString()
Definition: IconRegistryTest.php:58
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerIconAddNewIconToRegistry
‪registerIconAddNewIconToRegistry()
Definition: IconRegistryTest.php:86
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerMimeTypeIconRegisterAnIcon
‪registerMimeTypeIconRegisterAnIcon()
Definition: IconRegistryTest.php:203
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\isRegisteredReturnsTrueForRegisteredIcon
‪isRegisteredReturnsTrueForRegisteredIcon()
Definition: IconRegistryTest.php:67
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerIconThrowsInvalidArgumentExceptionWithInvalidIconProvider
‪registerIconThrowsInvalidArgumentExceptionWithInvalidIconProvider()
Definition: IconRegistryTest.php:101
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconConfigurationByIdentifierThrowsExceptionWithUnregisteredIconIdentifier
‪getIconConfigurationByIdentifierThrowsExceptionWithUnregisteredIconIdentifier()
Definition: IconRegistryTest.php:112
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerMimeTypeIconOverwriteAnExistingIcon
‪registerMimeTypeIconOverwriteAnExistingIcon()
Definition: IconRegistryTest.php:214