2 /***************************************************************
5 * (c) 2010-2011 Fabien Udriot <fabien.udriot@ecodev.ch>
6 * (c) 2010-2011 Oliver Klee <typo3-coding@oliverklee.de>
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
27 * Testcase for class t3lib_iconWorks.
29 * @author Fabien Udriot <fabien.udriot@ecodev.ch>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 class t3lib_iconWorksTest
extends tx_phpunit_testcase
{
38 * Enable backup of global and system variables
42 protected $backupGlobals = TRUE;
45 * Exclude TYPO3_DB from backup/restore of $GLOBALS
46 * because resource types cannot be handled during serializing
50 protected $backupGlobalsBlacklist = array('TYPO3_DB');
55 protected $mockRecord;
57 public function setUp() {
58 // Simulate a tt_content record
59 $this->mockRecord
= array();
60 $this->mockRecord
['header'] = 'dummy content header';
61 $this->mockRecord
['uid'] = '1';
62 $this->mockRecord
['pid'] = '1';
63 $this->mockRecord
['image'] = '';
64 $this->mockRecord
['hidden'] = '0';
65 $this->mockRecord
['starttime'] = '0';
66 $this->mockRecord
['endtime'] = '0';
67 $this->mockRecord
['fe_group'] = '';
68 $this->mockRecord
['CType'] = 'text';
69 $this->mockRecord
['t3ver_id'] = '0';
70 $this->mockRecord
['t3ver_state'] = '0';
71 $this->mockRecord
['t3ver_wsid'] = '0';
72 $this->mockRecord
['sys_language_uid'] = '0';
73 $this->mockRecord
['l18n_parent'] = '0';
74 $this->mockRecord
['subheader'] = '';
75 $this->mockRecord
['bodytext'] = '';
78 public function tearDown() {
79 unset($this->mockRecord
);
83 //////////////////////////////////////////
84 // Tests concerning imagemake
85 //////////////////////////////////////////
90 public function imagemakeFixesPermissionsOnNewFiles() {
91 if (TYPO3_OS
== 'WIN') {
92 $this->markTestSkipped('imagemakeFixesPermissionsOnNewFiles() test not available on Windows.');
95 $testFinder = t3lib_div
::makeInstance('Tx_Phpunit_Service_TestFinder');
96 $fixtureGifFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.gif';
98 // Create image ressource, determine target filename, fake target permission, run method and clean up
99 $fixtureGifRessource = imagecreatefromgif($fixtureGifFile);
100 $targetFilename = PATH_site
. 'typo3temp/' . uniqid('test_') . '.gif';
101 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
102 t3lib_iconWorks
::imagemake($fixtureGifRessource, $targetFilename);
104 $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
105 t3lib_div
::unlink_tempfile($targetFilename);
107 $this->assertEquals($resultFilePermissions, '0777');
111 //////////////////////////////////////////
112 // Tests concerning getSpriteIconClasses
113 //////////////////////////////////////////
116 * Tests whether an empty string returns 't3-icon'
119 public function getSpriteIconClassesWithEmptyStringReturnsT3Icon() {
122 t3lib_iconWorks
::getSpriteIconClasses('')
127 * Tests whether one part returns 't3-icon'
130 public function getSpriteIconClassesWithOnePartReturnsT3Icon() {
133 t3lib_iconWorks
::getSpriteIconClasses('actions')
138 * Tests the return of two parts
141 public function getSpriteIconClassesWithTwoPartsReturnsT3IconAndCombinedParts() {
142 $result = explode(' ', t3lib_iconWorks
::getSpriteIconClasses('actions-juggle'));
146 array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle'),
152 * Tests the return of tree parts
155 public function getSpriteIconClassesWithThreePartsReturnsT3IconAndCombinedParts() {
156 $result = explode(' ', t3lib_iconWorks
::getSpriteIconClasses('actions-juggle-speed'));
160 array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed'),
166 * Tests the return of four parts
169 public function getSpriteIconClassesWithFourPartsReturnsT3IconAndCombinedParts() {
170 $result = explode(' ', t3lib_iconWorks
::getSpriteIconClasses('actions-juggle-speed-game'));
174 array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed-game'),
179 //////////////////////////////////////////
180 // Tests concerning getSpriteIcon
181 //////////////////////////////////////////
184 * Tests whether an empty string returns a span with the missing sprite
187 public function getSpriteIconWithEmptyStringReturnsSpanWithIconMissingSprite() {
189 '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing"> </span>',
190 t3lib_iconWorks
::getSpriteIcon('')
195 * Tests whether an non existing icons returns a span with the missing sprite
198 public function getSpriteIconWithMissingIconReturnsSpanWithIconMissingSprite() {
200 '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing"> </span>',
201 t3lib_iconWorks
::getSpriteIcon('actions-juggle-speed')
206 * Tests whether an existing icon returns a span with the correct sprite
209 public function getSpriteIconWithExistingIconReturnsSpanWithIconSprite() {
211 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new"> </span>',
212 t3lib_iconWorks
::getSpriteIcon('actions-document-new')
217 * Tests the returns of an existing icon + an other attribute like title="foo"
220 public function getSpriteIconWithExistingIconAndAttributeReturnsSpanWithIconSpriteAndAttribute() {
222 '<span title="foo" class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new"> </span>',
223 t3lib_iconWorks
::getSpriteIcon('actions-document-new', array('title' => 'foo'))
228 * Tests the returns of an existing icon + a class attribute
231 public function getSpriteIconWithExistingIconAndClassAttributeReturnsSpanWithIconSpriteAndClassAttribute() {
233 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new foo"> </span>',
234 t3lib_iconWorks
::getSpriteIcon('actions-document-new', array('class' => 'foo'))
239 * Tests the returns of an existing icon + a class attribute
242 public function getSpriteIconWithExistingIconAndInnerHTMLReturnsSpanWithIconSpriteAndInnerHTML() {
244 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">foo</span>',
245 t3lib_iconWorks
::getSpriteIcon('actions-document-new', array('html' => 'foo'))
250 * Tests the returns of an existing icon + an overlay
253 public function getSpriteIconWithExistingIconAndOverlayReturnsSpanWithIconSpriteAndOverlay() {
254 $result = t3lib_iconWorks
::getSpriteIcon('actions-document-new', array(), array('status-overlay-hidden' => array()));
255 $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden t3-icon-overlay"> </span>';
257 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>',
263 * Tests the returns of an existing icon + an overlay
266 public function getSpriteIconWithExistingIconAndOverlayAndAttributesReturnsSpanWithIconSpriteAndOverlayAndAttributes() {
267 $result = t3lib_iconWorks
::getSpriteIcon('actions-document-new', array('html' => 'foo1'), array('status-overlay-hidden' => array('class' => 'foo2')));
268 $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden foo2 t3-icon-overlay">foo1</span>';
270 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>',
276 //////////////////////////////////////////
277 // Tests concerning getSpriteIconForRecord
278 //////////////////////////////////////////
281 * Tests the returns of NULL table + empty array
284 public function getSpriteIconForRecordWithNullTableReturnsMissingIcon() {
285 $result = t3lib_iconWorks
::getSpriteIconForRecord('', array());
288 '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing"> </span>',
294 * Tests the returns of tt_content + empty record
297 public function getSpriteIconForRecordWithEmptyRecordReturnsNormalSprite() {
298 $result = t3lib_iconWorks
::getSpriteIconForRecord('tt_content', array());
301 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text"> </span>',
307 * Tests the returns of tt_content + mock record
310 public function getSpriteIconForRecordWithMockRecordReturnsNormalSprite() {
311 $mockRecord = $this->mockRecord
;
312 $result = t3lib_iconWorks
::getSpriteIconForRecord('tt_content', $mockRecord);
315 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text"> </span>',
321 * Tests the returns of tt_content + mock record + options
324 public function getSpriteIconForRecordWithMockRecordAndOptionsReturnsNormalSprite() {
325 $mockRecord = $this->mockRecord
;
326 $result = t3lib_iconWorks
::getSpriteIconForRecord('tt_content', $mockRecord, array('class' => 'foo', 'title' => 'bar'));
329 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text foo" title="bar"> </span>',
335 * Tests the returns of tt_content + mock record of type 'list' (aka plugin)
338 public function getSpriteIconForRecordWithMockRecordOfTypePluginReturnsPluginSprite() {
339 $mockRecord = $this->mockRecord
;
340 $mockRecord['CType'] = 'list';
341 $result = t3lib_iconWorks
::getSpriteIconForRecord('tt_content', $mockRecord);
344 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-plugin"> </span>',
350 * Tests the returns of tt_content + mock record with hidden flag
353 public function getSpriteIconForRecordWithMockRecordWithHiddenFlagReturnsNormalSpriteAndOverlay() {
354 $mockRecord = $this->mockRecord
;
355 $mockRecord['hidden'] = '1';
356 $result = t3lib_iconWorks
::getSpriteIconForRecord('tt_content', $mockRecord);
357 $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden t3-icon-overlay"> </span>';
360 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">' . $overlay . '</span>',
366 //////////////////////////////////////////
367 // Tests concerning getSpriteIconForFile
368 //////////////////////////////////////////
371 * Tests the returns of no file
374 public function getSpriteIconForFileWithNoFileTypeReturnsOtherSprite() {
375 $result = t3lib_iconWorks
::getSpriteIconForFile('');
378 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other"> </span>',
384 * Tests the returns of unknown file
387 public function getSpriteIconForFileWithNoUnknowFileTypeReturnsOtherSprite() {
388 $result = t3lib_iconWorks
::getSpriteIconForFile('foo');
391 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other"> </span>',
397 * Tests the returns of file pdf
400 public function getSpriteIconForFileWithPdfReturnsPdfSprite() {
401 $result = t3lib_iconWorks
::getSpriteIconForFile('pdf');
404 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-pdf t3-icon-pdf"> </span>',
410 * Tests the returns of file png
413 public function getSpriteIconForFileWithPngReturnsPngSprite() {
414 $result = t3lib_iconWorks
::getSpriteIconForFile('png');
417 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image"> </span>',
423 * Tests the returns of file png + option
426 public function getSpriteIconForFileWithPngAndOptionsReturnsPngSpriteAndOptions() {
427 $result = t3lib_iconWorks
::getSpriteIconForFile('png', array('title' => 'bar'));
430 '<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image"> </span>',
436 * Tests whether a overrideIconOverlay hook is called.
439 public function isOverrideIconOverlayHookCalled() {
440 $classReference = uniqid('user_overrideIconOverlayHook');
442 $hookMock = $this->getMock($classReference, array('overrideIconOverlay'), array());
443 $hookMock->expects($this->once())->method('overrideIconOverlay');
444 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'][$classReference] = $classReference;
445 $GLOBALS['T3_VAR']['getUserObj'][$classReference] = $hookMock;
447 t3lib_iconWorks
::mapRecordOverlayToSpriteIconName('tt_content', array());
451 * Tests whether a faulty overrideIconOverlay hook (the hook object cannot be found) is not called.
454 public function isFaultyOverrideIconOverlayHookNotCalled() {
455 $classReference = uniqid('user_overrideIconOverlayHook');
457 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'][$classReference] = $classReference;
458 $GLOBALS['T3_VAR']['getUserObj'][$classReference] = new stdClass();
460 t3lib_iconWorks
::mapRecordOverlayToSpriteIconName('tt_content', array());