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