‪TYPO3CMS  9.5
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 
17 use Prophecy\Argument;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪IconRegistryTest extends UnitTestCase
30 {
34  protected ‪$notRegisteredIconIdentifier = 'my-super-unregistered-identifier';
35 
36  public function ‪setUp()
37  {
38  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
39  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
40  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
41  $cacheManagerProphecy->getCache('assets')->willReturn($cacheFrontendProphecy->reveal());
42  $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
43  $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
44  }
45 
46  public function ‪tearDown()
47  {
48  // Drop cache manager singleton again
49  GeneralUtility::purgeInstances();
50  parent::tearDown();
51  }
52 
57  {
58  $result = (new ‪IconRegistry)->getDefaultIconIdentifier();
59  $this->assertEquals($result, 'default-not-found');
60  }
61 
66  {
67  $subject = new IconRegistry();
68  $result = $subject->isRegistered($subject->getDefaultIconIdentifier());
69  $this->assertEquals($result, true);
70  }
71 
76  {
77  $result = (new IconRegistry)->isRegistered($this->notRegisteredIconIdentifier);
78  $this->assertEquals($result, false);
79  }
80 
84  public function ‪registerIconAddNewIconToRegistry()
85  {
86  $unregisterdIcon = 'foo-bar-unregistered';
87  $subject = new IconRegistry();
88  $this->assertFalse($subject->isRegistered($unregisterdIcon));
89  $subject->registerIcon($unregisterdIcon, FontawesomeIconProvider::class, [
90  'name' => 'pencil',
91  'additionalClasses' => 'fa-fw'
92  ]);
93  $this->assertTrue($subject->isRegistered($unregisterdIcon));
94  }
95 
100  {
101  $this->expectException(\InvalidArgumentException::class);
102  $this->expectExceptionCode(1437425803);
103 
104  (new IconRegistry)->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class);
105  }
106 
111  {
112  $this->expectException(\‪TYPO3\CMS\Core\Exception::class);
113  $this->expectExceptionCode(1437425804);
114 
115  (new IconRegistry)->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier);
116  }
117 
122  {
123  $result = (new IconRegistry)->getIconConfigurationByIdentifier('default-not-found');
124  // result must contain at least provider and options array
125  $this->assertArrayHasKey('provider', $result);
126  $this->assertArrayHasKey('options', $result);
127  // the provider must implement the IconProviderInterface
128  $this->assertTrue(in_array(IconProviderInterface::class, class_implements($result['provider'])));
129  }
130 
135  {
136  $this->assertInternalType('array', (new IconRegistry)->getAllRegisteredIconIdentifiers());
137  }
138 
143  {
144  $result = (new IconRegistry)->getAllRegisteredIconIdentifiers();
145  $this->assertInternalType('array', $result);
146  $this->assertContains('default-not-found', $result);
147  }
148 
153  {
154  $result = (new IconRegistry)->getIconIdentifierForFileExtension('');
155  $this->assertEquals('mimetypes-other-other', $result);
156  }
157 
162  {
163  $result = (new IconRegistry)->getIconIdentifierForFileExtension('xyz');
164  $this->assertEquals('mimetypes-other-other', $result);
165  }
166 
171  {
172  $result = (new IconRegistry)->getIconIdentifierForFileExtension('jpg');
173  $this->assertEquals('mimetypes-media-image', $result);
174  }
175 
180  {
181  $subject = new IconRegistry();
182  $subject->registerFileExtension('abc', 'xyz');
183  $result = $subject->getIconIdentifierForFileExtension('abc');
184  $this->assertEquals('xyz', $result);
185  }
186 
191  {
192  $subject = new IconRegistry();
193  $subject->registerFileExtension('jpg', 'xyz');
194  $result = $subject->getIconIdentifierForFileExtension('jpg');
195  $this->assertEquals('xyz', $result);
196  }
197 
201  public function ‪registerMimeTypeIconRegisterAnIcon()
202  {
203  $subject = new IconRegistry();
204  $subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar');
205  $result = $subject->getIconIdentifierForMimeType('foo/bar');
206  $this->assertEquals('mimetype-foo-bar', $result);
207  }
208 
213  {
214  $subject = new IconRegistry();
215  $subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar');
216  $result = $subject->getIconIdentifierForMimeType('video/*');
217  $this->assertEquals('mimetype-foo-bar', $result);
218  }
219 
224  {
225  $result = (new IconRegistry)->getIconIdentifierForMimeType('bar/foo');
226  $this->assertEquals(null, $result);
227  }
228 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension
‪getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension()
Definition: IconRegistryTest.php:151
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers
‪getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers()
Definition: IconRegistryTest.php:141
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\setUp
‪setUp()
Definition: IconRegistryTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\isRegisteredReturnsFalseForNotRegisteredIcon
‪isRegisteredReturnsFalseForNotRegisteredIcon()
Definition: IconRegistryTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerFileExtensionOverwriteAnExistingIcon
‪registerFileExtensionOverwriteAnExistingIcon()
Definition: IconRegistryTest.php:189
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest
Definition: IconRegistryTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension
‪getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension()
Definition: IconRegistryTest.php:160
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerFileExtensionRegisterAnIcon
‪registerFileExtensionRegisterAnIcon()
Definition: IconRegistryTest.php:178
‪TYPO3\CMS\Core\Tests\Unit\Imaging
Definition: DimensionTest.php:2
‪TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider
Definition: FontawesomeIconProvider.php:24
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\$notRegisteredIconIdentifier
‪string $notRegisteredIconIdentifier
Definition: IconRegistryTest.php:33
‪TYPO3\CMS\Core\Imaging\IconProviderInterface
Definition: IconProviderInterface.php:21
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForMimeTypeWithUnknowMimeTypeReturnNull
‪getIconIdentifierForMimeTypeWithUnknowMimeTypeReturnNull()
Definition: IconRegistryTest.php:222
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconConfigurationByIdentifierReturnsCorrectConfiguration
‪getIconConfigurationByIdentifierReturnsCorrectConfiguration()
Definition: IconRegistryTest.php:120
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension
‪getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension()
Definition: IconRegistryTest.php:169
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:34
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\tearDown
‪tearDown()
Definition: IconRegistryTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString
‪getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString()
Definition: IconRegistryTest.php:55
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerIconAddNewIconToRegistry
‪registerIconAddNewIconToRegistry()
Definition: IconRegistryTest.php:83
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerMimeTypeIconRegisterAnIcon
‪registerMimeTypeIconRegisterAnIcon()
Definition: IconRegistryTest.php:200
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\isRegisteredReturnsTrueForRegisteredIcon
‪isRegisteredReturnsTrueForRegisteredIcon()
Definition: IconRegistryTest.php:64
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentiefiers
‪getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentiefiers()
Definition: IconRegistryTest.php:133
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerIconThrowsInvalidArgumentExceptionWithInvalidIconProvider
‪registerIconThrowsInvalidArgumentExceptionWithInvalidIconProvider()
Definition: IconRegistryTest.php:98
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\getIconConfigurationByIdentifierThrowsExceptionWithUnregisteredIconIdentifier
‪getIconConfigurationByIdentifierThrowsExceptionWithUnregisteredIconIdentifier()
Definition: IconRegistryTest.php:109
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconRegistryTest\registerMimeTypeIconOverwriteAnExistingIcon
‪registerMimeTypeIconOverwriteAnExistingIcon()
Definition: IconRegistryTest.php:211