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