TYPO3 CMS  TYPO3_6-2
IconUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
24 
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 
50  protected $subject;
51 
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 
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 
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 
101  // Tests concerning imagemake
103 
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';
116  $subject::imagemake($fixtureGifRessource, $targetFilename);
117  clearstatcache();
118  $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
120  $this->assertEquals($resultFilePermissions, '0777');
121  }
122 
124  // Tests concerning getSpriteIconClasses
126 
133  $this->assertEquals('t3-icon', $subject::getSpriteIconClasses(''));
134  }
135 
143  $this->assertEquals('t3-icon', $subject::getSpriteIconClasses('actions'));
144  }
145 
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 
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 
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 
183  // Tests concerning getSpriteIcon
185 
191  $GLOBALS['TBE_STYLES'] = array(
192  'spriteIconApi' => array(
193  'iconsAvailable' => array(
194  ),
195  ),
196  );
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 
207  $GLOBALS['TBE_STYLES'] = array(
208  'spriteIconApi' => array(
209  'iconsAvailable' => array(
210  ),
211  ),
212  );
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 
223  $GLOBALS['TBE_STYLES'] = array(
224  'spriteIconApi' => array(
225  'iconsAvailable' => array(
226  'actions-document-new',
227  ),
228  ),
229  );
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 
240  $GLOBALS['TBE_STYLES'] = array(
241  'spriteIconApi' => array(
242  'iconsAvailable' => array(
243  'actions-document-new',
244  ),
245  ),
246  );
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 
257  $GLOBALS['TBE_STYLES'] = array(
258  'spriteIconApi' => array(
259  'iconsAvailable' => array(
260  'actions-document-new',
261  ),
262  ),
263  );
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 
274  $GLOBALS['TBE_STYLES'] = array(
275  'spriteIconApi' => array(
276  'iconsAvailable' => array(
277  'actions-document-new',
278  ),
279  ),
280  );
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 
291  $GLOBALS['TBE_STYLES'] = array(
292  'spriteIconApi' => array(
293  'iconsAvailable' => array(
294  'actions-document-new',
295  'status-overlay-hidden',
296  ),
297  ),
298  );
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 
311  $GLOBALS['TBE_STYLES'] = array(
312  'spriteIconApi' => array(
313  'iconsAvailable' => array(
314  'actions-document-new',
315  'status-overlay-hidden',
316  ),
317  ),
318  );
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 
326  // Tests concerning getSpriteIconForRecord
328 
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 
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  );
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 
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  );
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 
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  );
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 
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  );
439  $mockRecord['CType'] = 'list';
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 
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  );
479  $mockRecord['hidden'] = '1';
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 
487  // Tests concerning getSpriteIconForFile
489 
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 
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 
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 
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 
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 
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;
556  $subject::mapRecordOverlayToSpriteIconName('tt_content', array());
557  }
558 
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();
569  $subject::mapRecordOverlayToSpriteIconName('tt_content', array());
570  }
571 
573  // Tests concerning getSpriteIconForResource
575 
581  $GLOBALS['TBE_STYLES'] = array(
582  'spriteIconApi' => array(
583  'iconsAvailable' => array(
584  'mimetypes-other-other',
585  ),
586  ),
587  );
588  $fileObject = $this->getTestSubjectFileObject('');
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 
600  $GLOBALS['TBE_STYLES'] = array(
601  'spriteIconApi' => array(
602  'iconsAvailable' => array(
603  'mimetypes-other-other',
604  ),
605  ),
606  );
607  $fileObject = $this->getTestSubjectFileObject('foo');
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 
619  $GLOBALS['TBE_STYLES'] = array(
620  'spriteIconApi' => array(
621  'iconsAvailable' => array(
622  'mimetypes-pdf',
623  ),
624  ),
625  );
626  $fileObject = $this->getTestSubjectFileObject('pdf');
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 
638  $GLOBALS['TBE_STYLES'] = array(
639  'spriteIconApi' => array(
640  'iconsAvailable' => array(
641  'mimetypes-media-image',
642  ),
643  ),
644  );
645  $fileObject = $this->getTestSubjectFileObject('png');
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 
657  $GLOBALS['TBE_STYLES'] = array(
658  'spriteIconApi' => array(
659  'iconsAvailable' => array(
660  'mimetypes-media-image',
661  ),
662  ),
663  );
664  $fileObject = $this->getTestSubjectFileObject('png');
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 
676  $GLOBALS['TBE_STYLES'] = array(
677  'spriteIconApi' => array(
678  'iconsAvailable' => array(
679  'apps-filetree-folder-default',
680  ),
681  ),
682  );
683  $folderObject = $this->getTestSubjectFolderObject('/test');
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 
695  $GLOBALS['TBE_STYLES'] = array(
696  'spriteIconApi' => array(
697  'iconsAvailable' => array(
698  'apps-filetree-folder-opened',
699  ),
700  ),
701  );
702  $folderObject = $this->getTestSubjectFolderObject('/test');
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 
714  $GLOBALS['TBE_STYLES'] = array(
715  'spriteIconApi' => array(
716  'iconsAvailable' => array(
717  'apps-filetree-root',
718  ),
719  ),
720  );
721  $folderObject = $this->getTestSubjectFolderObject('/');
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 
733  $GLOBALS['TBE_STYLES'] = array(
734  'spriteIconApi' => array(
735  'iconsAvailable' => array(
736  'apps-filetree-mount',
737  ),
738  ),
739  );
740  $folderObject = $this->getTestSubjectFolderObject('/mount');
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 
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;
764  $subject::getSpriteIconForResource($folderObject);
765  }
766 
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();
779  $subject::getSpriteIconForResource($folderObject);
780  }
781 }
static unlink_tempfile($uploadedTempFileName)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]