[BUGFIX] Catch exceptions for inaccessible storages
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Utility / IconUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Utility;
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 /**
18 * Test case
19 *
20 * @author Fabien Udriot <fabien.udriot@ecodev.ch>
21 * @author Oliver Klee <typo3-coding@oliverklee.de>
22 */
23 class IconUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
24
25 /**
26 * @var array Simulate a tt_content record
27 */
28 protected $mockRecord = array(
29 'header' => 'dummy content header',
30 'uid' => '1',
31 'pid' => '1',
32 'image' => '',
33 'hidden' => '0',
34 'starttime' => '0',
35 'endtime' => '0',
36 'fe_group' => '',
37 'CType' => 'text',
38 't3ver_id' => '0',
39 't3ver_state' => '0',
40 't3ver_wsid' => '0',
41 'sys_language_uid' => '0',
42 'l18n_parent' => '0',
43 'subheader' => '',
44 'bodytext' => '',
45 );
46
47 /**
48 * @var \TYPO3\CMS\Backend\Utility\IconUtility A testable overlay with disabled cache
49 */
50 protected $subject;
51
52 /**
53 * Set up test case
54 *
55 * @return void
56 */
57 public function setUp() {
58 // Create a wrapper for IconUtility, so the static property $spriteIconCache is
59 // not polluted. Use this as subject!
60 $className = $this->getUniqueId('IconUtility');
61 eval(
62 'namespace ' . __NAMESPACE__ . ';' .
63 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\IconUtility {' .
64 ' static protected $spriteIconCache = array();' .
65 '}'
66 );
67 $this->subject = __NAMESPACE__ . '\\' . $className;
68 }
69
70 /**
71 * Create folder object to use as test subject
72 *
73 * @param string $identifier
74 * @return \TYPO3\CMS\Core\Resource\Folder
75 */
76 protected function getTestSubjectFolderObject($identifier) {
77 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
78 $mockedStorage->expects($this->any())->method('getRootLevelFolder')->will($this->returnValue(
79 new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, '/', '/')
80 ));
81 $mockedStorage->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(TRUE));
82 $mockedStorage->expects($this->any())->method('isBrowsable')->will($this->returnValue(TRUE));
83 return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $identifier, $identifier);
84 }
85
86 /**
87 * Create file object to use as test subject
88 *
89 * @param $extension
90 * @return \TYPO3\CMS\Core\Resource\File
91 */
92 protected function getTestSubjectFileObject($extension) {
93 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
94 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(array(), $mockedStorage));
95 $mockedFile->expects($this->once())->method('getExtension')->will($this->returnValue($extension));
96
97 return $mockedFile;
98 }
99
100 //////////////////////////////////////////
101 // Tests concerning imagemake
102 //////////////////////////////////////////
103 /**
104 * @test
105 */
106 public function imagemakeFixesPermissionsOnNewFiles() {
107 if (TYPO3_OS == 'WIN') {
108 $this->markTestSkipped('imagemakeFixesPermissionsOnNewFiles() test not available on Windows.');
109 }
110 $fixtureGifFile = __DIR__ . '/Fixtures/clear.gif';
111 // Create image resource, determine target filename, fake target permission, run method and clean up
112 $fixtureGifRessource = imagecreatefromgif($fixtureGifFile);
113 $targetFilename = PATH_site . 'typo3temp/' . $this->getUniqueId('test_') . '.gif';
114 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
115 $subject = $this->subject;
116 $subject::imagemake($fixtureGifRessource, $targetFilename);
117 clearstatcache();
118 $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
119 \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($targetFilename);
120 $this->assertEquals($resultFilePermissions, '0777');
121 }
122
123 //////////////////////////////////////////
124 // Tests concerning getSpriteIconClasses
125 //////////////////////////////////////////
126 /**
127 * Tests whether an empty string returns 't3-icon'
128 *
129 * @test
130 */
131 public function getSpriteIconClassesWithEmptyStringReturnsT3Icon() {
132 $subject = $this->subject;
133 $this->assertEquals('t3-icon', $subject::getSpriteIconClasses(''));
134 }
135
136 /**
137 * Tests whether one part returns 't3-icon'
138 *
139 * @test
140 */
141 public function getSpriteIconClassesWithOnePartReturnsT3Icon() {
142 $subject = $this->subject;
143 $this->assertEquals('t3-icon', $subject::getSpriteIconClasses('actions'));
144 }
145
146 /**
147 * Tests the return of two parts
148 *
149 * @test
150 */
151 public function getSpriteIconClassesWithTwoPartsReturnsT3IconAndCombinedParts() {
152 $subject = $this->subject;
153 $result = explode(' ', $subject::getSpriteIconClasses('actions-juggle'));
154 sort($result);
155 $this->assertEquals(array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle'), $result);
156 }
157
158 /**
159 * Tests the return of tree parts
160 *
161 * @test
162 */
163 public function getSpriteIconClassesWithThreePartsReturnsT3IconAndCombinedParts() {
164 $subject = $this->subject;
165 $result = explode(' ', $subject::getSpriteIconClasses('actions-juggle-speed'));
166 sort($result);
167 $this->assertEquals(array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed'), $result);
168 }
169
170 /**
171 * Tests the return of four parts
172 *
173 * @test
174 */
175 public function getSpriteIconClassesWithFourPartsReturnsT3IconAndCombinedParts() {
176 $subject = $this->subject;
177 $result = explode(' ', $subject::getSpriteIconClasses('actions-juggle-speed-game'));
178 sort($result);
179 $this->assertEquals(array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed-game'), $result);
180 }
181
182 //////////////////////////////////////////
183 // Tests concerning getSpriteIcon
184 //////////////////////////////////////////
185 /**
186 * Tests whether an empty string returns a span with the missing sprite
187 *
188 * @test
189 */
190 public function getSpriteIconWithEmptyStringReturnsSpanWithIconMissingSprite() {
191 $GLOBALS['TBE_STYLES'] = array(
192 'spriteIconApi' => array(
193 'iconsAvailable' => array(
194 ),
195 ),
196 );
197 $subject = $this->subject;
198 $this->assertEquals('<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>', $subject::getSpriteIcon(''));
199 }
200
201 /**
202 * Tests whether an non existing icons returns a span with the missing sprite
203 *
204 * @test
205 */
206 public function getSpriteIconWithMissingIconReturnsSpanWithIconMissingSprite() {
207 $GLOBALS['TBE_STYLES'] = array(
208 'spriteIconApi' => array(
209 'iconsAvailable' => array(
210 ),
211 ),
212 );
213 $subject = $this->subject;
214 $this->assertEquals('<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>', $subject::getSpriteIcon('actions-juggle-speed'));
215 }
216
217 /**
218 * Tests whether an existing icon returns a span with the correct sprite
219 *
220 * @test
221 */
222 public function getSpriteIconWithExistingIconReturnsSpanWithIconSprite() {
223 $GLOBALS['TBE_STYLES'] = array(
224 'spriteIconApi' => array(
225 'iconsAvailable' => array(
226 'actions-document-new',
227 ),
228 ),
229 );
230 $subject = $this->subject;
231 $this->assertEquals('<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">&nbsp;</span>', $subject::getSpriteIcon('actions-document-new'));
232 }
233
234 /**
235 * Tests the returns of an existing icon + an other attribute like title="foo"
236 *
237 * @test
238 */
239 public function getSpriteIconWithExistingIconAndAttributeReturnsSpanWithIconSpriteAndAttribute() {
240 $GLOBALS['TBE_STYLES'] = array(
241 'spriteIconApi' => array(
242 'iconsAvailable' => array(
243 'actions-document-new',
244 ),
245 ),
246 );
247 $subject = $this->subject;
248 $this->assertEquals('<span title="foo" class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">&nbsp;</span>', $subject::getSpriteIcon('actions-document-new', array('title' => 'foo')));
249 }
250
251 /**
252 * Tests the returns of an existing icon + a class attribute
253 *
254 * @test
255 */
256 public function getSpriteIconWithExistingIconAndClassAttributeReturnsSpanWithIconSpriteAndClassAttribute() {
257 $GLOBALS['TBE_STYLES'] = array(
258 'spriteIconApi' => array(
259 'iconsAvailable' => array(
260 'actions-document-new',
261 ),
262 ),
263 );
264 $subject = $this->subject;
265 $this->assertEquals('<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new foo">&nbsp;</span>', $subject::getSpriteIcon('actions-document-new', array('class' => 'foo')));
266 }
267
268 /**
269 * Tests the returns of an existing icon + a class attribute
270 *
271 * @test
272 */
273 public function getSpriteIconWithExistingIconAndInnerHTMLReturnsSpanWithIconSpriteAndInnerHTML() {
274 $GLOBALS['TBE_STYLES'] = array(
275 'spriteIconApi' => array(
276 'iconsAvailable' => array(
277 'actions-document-new',
278 ),
279 ),
280 );
281 $subject = $this->subject;
282 $this->assertEquals('<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">foo</span>', $subject::getSpriteIcon('actions-document-new', array('html' => 'foo')));
283 }
284
285 /**
286 * Tests the returns of an existing icon + an overlay
287 *
288 * @test
289 */
290 public function getSpriteIconWithExistingIconAndOverlayReturnsSpanWithIconSpriteAndOverlay() {
291 $GLOBALS['TBE_STYLES'] = array(
292 'spriteIconApi' => array(
293 'iconsAvailable' => array(
294 'actions-document-new',
295 'status-overlay-hidden',
296 ),
297 ),
298 );
299 $subject = $this->subject;
300 $result = $subject::getSpriteIcon('actions-document-new', array(), array('status-overlay-hidden' => array()));
301 $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden t3-icon-overlay">&nbsp;</span>';
302 $this->assertEquals('<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>', $result);
303 }
304
305 /**
306 * Tests the returns of an existing icon + an overlay
307 *
308 * @test
309 */
310 public function getSpriteIconWithExistingIconAndOverlayAndAttributesReturnsSpanWithIconSpriteAndOverlayAndAttributes() {
311 $GLOBALS['TBE_STYLES'] = array(
312 'spriteIconApi' => array(
313 'iconsAvailable' => array(
314 'actions-document-new',
315 'status-overlay-hidden',
316 ),
317 ),
318 );
319 $subject = $this->subject;
320 $result = $subject::getSpriteIcon('actions-document-new', array('html' => 'foo1'), array('status-overlay-hidden' => array('class' => 'foo2')));
321 $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden foo2 t3-icon-overlay">foo1</span>';
322 $this->assertEquals('<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>', $result);
323 }
324
325 //////////////////////////////////////////
326 // Tests concerning getSpriteIconForRecord
327 //////////////////////////////////////////
328 /**
329 * Tests the returns of NULL table + empty array
330 *
331 * @test
332 */
333 public function getSpriteIconForRecordWithNullTableReturnsMissingIcon() {
334 $subject = $this->subject;
335 $result = $subject::getSpriteIconForRecord('', array());
336 $this->assertEquals('<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>', $result);
337 }
338
339 /**
340 * Tests the returns of tt_content + empty record
341 *
342 * @test
343 */
344 public function getSpriteIconForRecordWithEmptyRecordReturnsNormalSprite() {
345 $GLOBALS['TBE_STYLES'] = array(
346 'spriteIconApi' => array(
347 'iconsAvailable' => array('mimetypes-x-content-text'),
348 ),
349 );
350 $GLOBALS['TCA'] = array(
351 'tt_content' => array(
352 'ctrl' => array(
353 'typeicon_column' => 'CType',
354 'typeicon_classes' => array(
355 'default' => 'mimetypes-x-content-text',
356 ),
357 ),
358 ),
359 );
360 $subject = $this->subject;
361 $result = $subject::getSpriteIconForRecord('tt_content', array());
362 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">&nbsp;</span>', $result);
363 }
364
365 /**
366 * Tests the returns of tt_content + mock record
367 *
368 * @test
369 */
370 public function getSpriteIconForRecordWithMockRecordReturnsNormalSprite() {
371 $GLOBALS['TBE_STYLES'] = array(
372 'spriteIconApi' => array(
373 'iconsAvailable' => array('mimetypes-x-content-text'),
374 ),
375 );
376 $GLOBALS['TCA'] = array(
377 'tt_content' => array(
378 'ctrl' => array(
379 'typeicon_column' => 'CType',
380 'typeicon_classes' => array(
381 'text' => 'mimetypes-x-content-text',
382 ),
383 ),
384 ),
385 );
386 $subject = $this->subject;
387 $result = $subject::getSpriteIconForRecord('tt_content', $this->mockRecord);
388 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">&nbsp;</span>', $result);
389 }
390
391 /**
392 * Tests the returns of tt_content + mock record + options
393 *
394 * @test
395 */
396 public function getSpriteIconForRecordWithMockRecordAndOptionsReturnsNormalSprite() {
397 $GLOBALS['TBE_STYLES'] = array(
398 'spriteIconApi' => array(
399 'iconsAvailable' => array('mimetypes-x-content-text'),
400 ),
401 );
402 $GLOBALS['TCA'] = array(
403 'tt_content' => array(
404 'ctrl' => array(
405 'typeicon_column' => 'CType',
406 'typeicon_classes' => array(
407 'text' => 'mimetypes-x-content-text',
408 ),
409 ),
410 ),
411 );
412 $subject = $this->subject;
413 $result = $subject::getSpriteIconForRecord('tt_content', $this->mockRecord, array('class' => 'foo', 'title' => 'bar'));
414 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text foo" title="bar">&nbsp;</span>', $result);
415 }
416
417 /**
418 * Tests the returns of tt_content + mock record of type 'list' (aka plugin)
419 *
420 * @test
421 */
422 public function getSpriteIconForRecordWithMockRecordOfTypePluginReturnsPluginSprite() {
423 $GLOBALS['TBE_STYLES'] = array(
424 'spriteIconApi' => array(
425 'iconsAvailable' => array('mimetypes-x-content-plugin'),
426 ),
427 );
428 $GLOBALS['TCA'] = array(
429 'tt_content' => array(
430 'ctrl' => array(
431 'typeicon_column' => 'CType',
432 'typeicon_classes' => array(
433 'list' => 'mimetypes-x-content-plugin',
434 ),
435 ),
436 ),
437 );
438 $mockRecord = $this->mockRecord;
439 $mockRecord['CType'] = 'list';
440 $subject = $this->subject;
441 $result = $subject::getSpriteIconForRecord('tt_content', $mockRecord);
442 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-plugin">&nbsp;</span>', $result);
443 }
444
445 /**
446 * Tests the returns of tt_content + mock record with hidden flag
447 *
448 * @test
449 */
450 public function getSpriteIconForRecordWithMockRecordWithHiddenFlagReturnsNormalSpriteAndOverlay() {
451 $GLOBALS['TBE_STYLES'] = array(
452 'spriteIconApi' => array(
453 'iconsAvailable' => array(
454 'mimetypes-x-content-text',
455 'status-overlay-hidden',
456 ),
457 'spriteIconRecordOverlayNames' => array(
458 'hidden' => 'status-overlay-hidden',
459 ),
460 'spriteIconRecordOverlayPriorities' => array(
461 'hidden'
462 ),
463 ),
464 );
465 $GLOBALS['TCA'] = array(
466 'tt_content' => array(
467 'ctrl' => array(
468 'enablecolumns' => array(
469 'disabled' => 'hidden',
470 ),
471 'typeicon_column' => 'CType',
472 'typeicon_classes' => array(
473 'text' => 'mimetypes-x-content-text',
474 ),
475 ),
476 ),
477 );
478 $mockRecord = $this->mockRecord;
479 $mockRecord['hidden'] = '1';
480 $subject = $this->subject;
481 $result = $subject::getSpriteIconForRecord('tt_content', $mockRecord);
482 $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden t3-icon-overlay">&nbsp;</span>';
483 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">' . $overlay . '</span>', $result);
484 }
485
486 //////////////////////////////////////////
487 // Tests concerning getSpriteIconForFile
488 //////////////////////////////////////////
489 /**
490 * Tests the returns of no file
491 *
492 * @test
493 */
494 public function getSpriteIconForFileWithNoFileTypeReturnsOtherSprite() {
495 $subject = $this->subject;
496 $result = $subject::getSpriteIconForFile('');
497 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>', $result);
498 }
499
500 /**
501 * Tests the returns of unknown file
502 *
503 * @test
504 */
505 public function getSpriteIconForFileWithNoUnknowFileTypeReturnsOtherSprite() {
506 $subject = $this->subject;
507 $result = $subject::getSpriteIconForFile('foo');
508 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>', $result);
509 }
510
511 /**
512 * Tests the returns of file pdf
513 *
514 * @test
515 */
516 public function getSpriteIconForFileWithPdfReturnsPdfSprite() {
517 $subject = $this->subject;
518 $result = $subject::getSpriteIconForFile('pdf');
519 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-pdf t3-icon-pdf">&nbsp;</span>', $result);
520 }
521
522 /**
523 * Tests the returns of file png
524 *
525 * @test
526 */
527 public function getSpriteIconForFileWithPngReturnsPngSprite() {
528 $subject = $this->subject;
529 $result = $subject::getSpriteIconForFile('png');
530 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>', $result);
531 }
532
533 /**
534 * Tests the returns of file png + option
535 *
536 * @test
537 */
538 public function getSpriteIconForFileWithPngAndOptionsReturnsPngSpriteAndOptions() {
539 $subject = $this->subject;
540 $result = $subject::getSpriteIconForFile('png', array('title' => 'bar'));
541 $this->assertEquals('<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>', $result);
542 }
543
544 /**
545 * Tests whether a overrideIconOverlay hook is called.
546 *
547 * @test
548 */
549 public function isOverrideIconOverlayHookCalled() {
550 $classReference = $this->getUniqueId('user_overrideIconOverlayHook');
551 $hookMock = $this->getMock($classReference, array('overrideIconOverlay'), array());
552 $hookMock->expects($this->once())->method('overrideIconOverlay');
553 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'][$classReference] = $classReference;
554 $GLOBALS['T3_VAR']['getUserObj'][$classReference] = $hookMock;
555 $subject = $this->subject;
556 $subject::mapRecordOverlayToSpriteIconName('tt_content', array());
557 }
558
559 /**
560 * Tests whether a faulty overrideIconOverlay hook (the hook object cannot be found) is not called.
561 *
562 * @test
563 */
564 public function isFaultyOverrideIconOverlayHookNotCalled() {
565 $classReference = $this->getUniqueId('user_overrideIconOverlayHook');
566 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'][$classReference] = $classReference;
567 $GLOBALS['T3_VAR']['getUserObj'][$classReference] = new \stdClass();
568 $subject = $this->subject;
569 $subject::mapRecordOverlayToSpriteIconName('tt_content', array());
570 }
571
572 //////////////////////////////////////////////
573 // Tests concerning getSpriteIconForResource
574 //////////////////////////////////////////////
575 /**
576 * Tests the returns of no file
577 *
578 * @test
579 */
580 public function getSpriteIconForResourceWithFileWithoutExtensionTypeReturnsOtherSprite() {
581 $GLOBALS['TBE_STYLES'] = array(
582 'spriteIconApi' => array(
583 'iconsAvailable' => array(
584 'mimetypes-other-other',
585 ),
586 ),
587 );
588 $fileObject = $this->getTestSubjectFileObject('');
589 $subject = $this->subject;
590 $result = $subject::getSpriteIconForResource($fileObject);
591 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>', $result);
592 }
593
594 /**
595 * Tests the returns of unknown file
596 *
597 * @test
598 */
599 public function getSpriteIconForResourceWithUnknownFileTypeReturnsOtherSprite() {
600 $GLOBALS['TBE_STYLES'] = array(
601 'spriteIconApi' => array(
602 'iconsAvailable' => array(
603 'mimetypes-other-other',
604 ),
605 ),
606 );
607 $fileObject = $this->getTestSubjectFileObject('foo');
608 $subject = $this->subject;
609 $result = $subject::getSpriteIconForResource($fileObject);
610 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>', $result);
611 }
612
613 /**
614 * Tests the returns of file pdf
615 *
616 * @test
617 */
618 public function getSpriteIconForResourceWithPdfReturnsPdfSprite() {
619 $GLOBALS['TBE_STYLES'] = array(
620 'spriteIconApi' => array(
621 'iconsAvailable' => array(
622 'mimetypes-pdf',
623 ),
624 ),
625 );
626 $fileObject = $this->getTestSubjectFileObject('pdf');
627 $subject = $this->subject;
628 $result = $subject::getSpriteIconForResource($fileObject);
629 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-pdf t3-icon-pdf">&nbsp;</span>', $result);
630 }
631
632 /**
633 * Tests the returns of file png
634 *
635 * @test
636 */
637 public function getSpriteIconForResourceWithPngFileReturnsPngSprite() {
638 $GLOBALS['TBE_STYLES'] = array(
639 'spriteIconApi' => array(
640 'iconsAvailable' => array(
641 'mimetypes-media-image',
642 ),
643 ),
644 );
645 $fileObject = $this->getTestSubjectFileObject('png');
646 $subject = $this->subject;
647 $result = $subject::getSpriteIconForResource($fileObject);
648 $this->assertEquals('<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>', $result);
649 }
650
651 /**
652 * Tests the returns of file png + option
653 *
654 * @test
655 */
656 public function getSpriteIconForResourceWithPngFileAndOptionsReturnsPngSpriteAndOptions() {
657 $GLOBALS['TBE_STYLES'] = array(
658 'spriteIconApi' => array(
659 'iconsAvailable' => array(
660 'mimetypes-media-image',
661 ),
662 ),
663 );
664 $fileObject = $this->getTestSubjectFileObject('png');
665 $subject = $this->subject;
666 $result = $subject::getSpriteIconForResource($fileObject, array('title' => 'bar'));
667 $this->assertEquals('<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>', $result);
668 }
669
670 /**
671 * Tests the returns of normal folder
672 *
673 * @test
674 */
675 public function getSpriteIconForResourceWithFolderReturnsFolderSprite() {
676 $GLOBALS['TBE_STYLES'] = array(
677 'spriteIconApi' => array(
678 'iconsAvailable' => array(
679 'apps-filetree-folder-default',
680 ),
681 ),
682 );
683 $folderObject = $this->getTestSubjectFolderObject('/test');
684 $subject = $this->subject;
685 $result = $subject::getSpriteIconForResource($folderObject);
686 $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-folder-default">&nbsp;</span>', $result);
687 }
688
689 /**
690 * Tests the returns of open folder
691 *
692 * @test
693 */
694 public function getSpriteIconForResourceWithOpenFolderReturnsOpenFolderSprite() {
695 $GLOBALS['TBE_STYLES'] = array(
696 'spriteIconApi' => array(
697 'iconsAvailable' => array(
698 'apps-filetree-folder-opened',
699 ),
700 ),
701 );
702 $folderObject = $this->getTestSubjectFolderObject('/test');
703 $subject = $this->subject;
704 $result = $subject::getSpriteIconForResource($folderObject, array('folder-open' => TRUE));
705 $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-folder-opened">&nbsp;</span>', $result);
706 }
707
708 /**
709 * Tests the returns of root folder
710 *
711 * @test
712 */
713 public function getSpriteIconForResourceWithRootFolderReturnsRootFolderSprite() {
714 $GLOBALS['TBE_STYLES'] = array(
715 'spriteIconApi' => array(
716 'iconsAvailable' => array(
717 'apps-filetree-root',
718 ),
719 ),
720 );
721 $folderObject = $this->getTestSubjectFolderObject('/');
722 $subject = $this->subject;
723 $result = $subject::getSpriteIconForResource($folderObject);
724 $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-root">&nbsp;</span>', $result);
725 }
726
727 /**
728 * Tests the returns of mount root
729 *
730 * @test
731 */
732 public function getSpriteIconForResourceWithMountRootReturnsMountFolderSprite() {
733 $GLOBALS['TBE_STYLES'] = array(
734 'spriteIconApi' => array(
735 'iconsAvailable' => array(
736 'apps-filetree-mount',
737 ),
738 ),
739 );
740 $folderObject = $this->getTestSubjectFolderObject('/mount');
741 $subject = $this->subject;
742 $result = $subject::getSpriteIconForResource($folderObject, array('mount-root' => TRUE));
743 $this->assertEquals('<span class="t3-icon t3-icon-apps t3-icon-apps-filetree t3-icon-filetree-mount">&nbsp;</span>', $result);
744 }
745
746 /**
747 * Tests whether a overrideResourceIcon hook is called.
748 *
749 * @test
750 */
751 public function isOverrideResourceIconHookCalled() {
752 $GLOBALS['TBE_STYLES'] = array(
753 'spriteIconApi' => array(
754 'iconsAvailable' => array()
755 ),
756 );
757 $classReference = $this->getUniqueId('user_overrideResourceIconHook');
758 $folderObject = $this->getTestSubjectFolderObject('/test');
759 $hookMock = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\IconUtilityOverrideResourceIconHookInterface', array('overrideResourceIcon'), array(), $classReference);
760 $hookMock->expects($this->once())->method('overrideResourceIcon');
761 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'][$classReference] = $classReference;
762 $GLOBALS['T3_VAR']['getUserObj'][$classReference] = $hookMock;
763 $subject = $this->subject;
764 $subject::getSpriteIconForResource($folderObject);
765 }
766
767 /**
768 * Tests whether a faulty overrideResourceIcon hook (the hook object cannot be found) is not called.
769 *
770 * @test
771 * @expectedException \UnexpectedValueException
772 */
773 public function isFaultyResourceIconHookNotCalled() {
774 $classReference = $this->getUniqueId('user_overrideResourceIconHook');
775 $folderObject = $this->getTestSubjectFolderObject('/test');
776 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'][$classReference] = $classReference;
777 $GLOBALS['T3_VAR']['getUserObj'][$classReference] = new \stdClass();
778 $subject = $this->subject;
779 $subject::getSpriteIconForResource($folderObject);
780 }
781 }