TYPO3 CMS  TYPO3_7-6
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 
25 {
29  protected $subject = null;
30 
34  protected $notRegisteredIconIdentifier = 'my-super-unregistered-identifier';
35 
41  protected function setUp()
42  {
43  $this->subject = new \TYPO3\CMS\Core\Imaging\IconRegistry();
44  }
45 
50  {
51  $result = $this->subject->getDefaultIconIdentifier();
52  $this->assertEquals($result, 'default-not-found');
53  }
54 
59  {
60  $result = $this->subject->isRegistered($this->subject->getDefaultIconIdentifier());
61  $this->assertEquals($result, true);
62  }
63 
68  {
69  $result = $this->subject->isRegistered($this->notRegisteredIconIdentifier);
70  $this->assertEquals($result, false);
71  }
72 
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 
92  {
93  $this->subject->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class);
94  }
95 
101  {
102  $this->subject->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier);
103  }
104 
109  {
110  $result = $this->subject->getIconConfigurationByIdentifier('default-not-found');
111  // result must contain at least provider and options array
112  $this->assertArrayHasKey('provider', $result);
113  $this->assertArrayHasKey('options', $result);
114  // the provider must implement the IconProviderInterface
115  $this->assertTrue(in_array(IconProviderInterface::class, class_implements($result['provider'])));
116  }
117 
122  {
123  $this->assertInternalType('array', $this->subject->getAllRegisteredIconIdentifiers());
124  }
125 
130  {
131  $result = $this->subject->getAllRegisteredIconIdentifiers();
132  $this->assertInternalType('array', $result);
133  $this->assertContains('default-not-found', $result);
134  }
135 
140  {
141  $result = $this->subject->getIconIdentifierForFileExtension('');
142  $this->assertEquals('mimetypes-other-other', $result);
143  }
144 
149  {
150  $result = $this->subject->getIconIdentifierForFileExtension('xyz');
151  $this->assertEquals('mimetypes-other-other', $result);
152  }
153 
158  {
159  $result = $this->subject->getIconIdentifierForFileExtension('jpg');
160  $this->assertEquals('mimetypes-media-image', $result);
161  }
162 
167  {
168  $this->subject->registerFileExtension('abc', 'xyz');
169  $result = $this->subject->getIconIdentifierForFileExtension('abc');
170  $this->assertEquals('xyz', $result);
171  }
172 
177  {
178  $this->subject->registerFileExtension('jpg', 'xyz');
179  $result = $this->subject->getIconIdentifierForFileExtension('jpg');
180  $this->assertEquals('xyz', $result);
181  }
182 
187  {
188  $this->subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar');
189  $result = $this->subject->getIconIdentifierForMimeType('foo/bar');
190  $this->assertEquals('mimetype-foo-bar', $result);
191  }
192 
197  {
198  $this->subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar');
199  $result = $this->subject->getIconIdentifierForMimeType('video/*');
200  $this->assertEquals('mimetype-foo-bar', $result);
201  }
202 
207  {
208  $result = $this->subject->getIconIdentifierForMimeType('bar/foo');
209  $this->assertEquals(null, $result);
210  }
211 }