Fixed bug #17490: After introducing the locking in #17289 no CSRF token will ever...
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_iconWorksTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Fabien Udriot <fabien.udriot@ecodev.ch>
6 * (c) 2010-2011 Oliver Klee <typo3-coding@oliverklee.de>
7 * All rights reserved
8 *
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.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
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.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25
26 /**
27 * Testcase for class t3lib_iconWorks.
28 *
29 * @author Fabien Udriot <fabien.udriot@ecodev.ch>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 *
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35 class t3lib_iconWorksTest extends tx_phpunit_testcase {
36
37 /**
38 * Enable backup of global and system variables
39 *
40 * @var boolean
41 */
42 protected $backupGlobals = TRUE;
43
44 /**
45 * Exclude TYPO3_DB from backup/restore of $GLOBALS
46 * because resource types cannot be handled during serializing
47 *
48 * @var array
49 */
50 protected $backupGlobalsBlacklist = array('TYPO3_DB');
51
52 /**
53 * @var array
54 */
55 protected $mockRecord;
56
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'] = '';
76 }
77
78 public function tearDown() {
79 unset($this->mockRecord);
80 }
81
82
83 //////////////////////////////////////////
84 // Tests concerning imagemake
85 //////////////////////////////////////////
86
87 /**
88 * @test
89 */
90 public function imagemakeFixesPermissionsOnNewFiles() {
91 if (TYPO3_OS == 'WIN') {
92 $this->markTestSkipped('imagemakeFixesPermissionsOnNewFiles() test not available on Windows.');
93 }
94
95 $testFinder = t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder');
96 $fixtureGifFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.gif';
97
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);
103 clearstatcache();
104 $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
105 t3lib_div::unlink_tempfile($targetFilename);
106
107 $this->assertEquals($resultFilePermissions, '0777');
108 }
109
110
111 //////////////////////////////////////////
112 // Tests concerning getSpriteIconClasses
113 //////////////////////////////////////////
114
115 /**
116 * Tests whether an empty string returns 't3-icon'
117 * @test
118 */
119 public function getSpriteIconClassesWithEmptyStringReturnsT3Icon() {
120 $this->assertEquals(
121 't3-icon',
122 t3lib_iconWorks::getSpriteIconClasses('')
123 );
124 }
125
126 /**
127 * Tests whether one part returns 't3-icon'
128 * @test
129 */
130 public function getSpriteIconClassesWithOnePartReturnsT3Icon() {
131 $this->assertEquals(
132 't3-icon',
133 t3lib_iconWorks::getSpriteIconClasses('actions')
134 );
135 }
136
137 /**
138 * Tests the return of two parts
139 * @test
140 */
141 public function getSpriteIconClassesWithTwoPartsReturnsT3IconAndCombinedParts() {
142 $result = explode(' ', t3lib_iconWorks::getSpriteIconClasses('actions-juggle'));
143 sort($result);
144
145 $this->assertEquals(
146 array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle'),
147 $result
148 );
149 }
150
151 /**
152 * Tests the return of tree parts
153 * @test
154 */
155 public function getSpriteIconClassesWithThreePartsReturnsT3IconAndCombinedParts() {
156 $result = explode(' ', t3lib_iconWorks::getSpriteIconClasses('actions-juggle-speed'));
157 sort($result);
158
159 $this->assertEquals(
160 array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed'),
161 $result
162 );
163 }
164
165 /**
166 * Tests the return of four parts
167 * @test
168 */
169 public function getSpriteIconClassesWithFourPartsReturnsT3IconAndCombinedParts() {
170 $result = explode(' ', t3lib_iconWorks::getSpriteIconClasses('actions-juggle-speed-game'));
171 sort($result);
172
173 $this->assertEquals(
174 array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed-game'),
175 $result
176 );
177 }
178
179 //////////////////////////////////////////
180 // Tests concerning getSpriteIcon
181 //////////////////////////////////////////
182
183 /**
184 * Tests whether an empty string returns a span with the missing sprite
185 * @test
186 */
187 public function getSpriteIconWithEmptyStringReturnsSpanWithIconMissingSprite() {
188 $this->assertEquals(
189 '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>',
190 t3lib_iconWorks::getSpriteIcon('')
191 );
192 }
193
194 /**
195 * Tests whether an non existing icons returns a span with the missing sprite
196 * @test
197 */
198 public function getSpriteIconWithMissingIconReturnsSpanWithIconMissingSprite() {
199 $this->assertEquals(
200 '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>',
201 t3lib_iconWorks::getSpriteIcon('actions-juggle-speed')
202 );
203 }
204
205 /**
206 * Tests whether an existing icon returns a span with the correct sprite
207 * @test
208 */
209 public function getSpriteIconWithExistingIconReturnsSpanWithIconSprite() {
210 $this->assertEquals(
211 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">&nbsp;</span>',
212 t3lib_iconWorks::getSpriteIcon('actions-document-new')
213 );
214 }
215
216 /**
217 * Tests the returns of an existing icon + an other attribute like title="foo"
218 * @test
219 */
220 public function getSpriteIconWithExistingIconAndAttributeReturnsSpanWithIconSpriteAndAttribute() {
221 $this->assertEquals(
222 '<span title="foo" class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">&nbsp;</span>',
223 t3lib_iconWorks::getSpriteIcon('actions-document-new', array('title' => 'foo'))
224 );
225 }
226
227 /**
228 * Tests the returns of an existing icon + a class attribute
229 * @test
230 */
231 public function getSpriteIconWithExistingIconAndClassAttributeReturnsSpanWithIconSpriteAndClassAttribute() {
232 $this->assertEquals(
233 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new foo">&nbsp;</span>',
234 t3lib_iconWorks::getSpriteIcon('actions-document-new', array('class' => 'foo'))
235 );
236 }
237
238 /**
239 * Tests the returns of an existing icon + a class attribute
240 * @test
241 */
242 public function getSpriteIconWithExistingIconAndInnerHTMLReturnsSpanWithIconSpriteAndInnerHTML() {
243 $this->assertEquals(
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'))
246 );
247 }
248
249 /**
250 * Tests the returns of an existing icon + an overlay
251 * @test
252 */
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">&nbsp;</span>';
256 $this->assertEquals(
257 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>',
258 $result
259 );
260 }
261
262 /**
263 * Tests the returns of an existing icon + an overlay
264 * @test
265 */
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>';
269 $this->assertEquals(
270 '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>',
271 $result
272 );
273 }
274
275
276 //////////////////////////////////////////
277 // Tests concerning getSpriteIconForRecord
278 //////////////////////////////////////////
279
280 /**
281 * Tests the returns of null table + empty array
282 * @test
283 */
284 public function getSpriteIconForRecordWithNullTableReturnsMissingIcon() {
285 $result = t3lib_iconWorks::getSpriteIconForRecord('', array());
286
287 $this->assertEquals(
288 '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>',
289 $result
290 );
291 }
292
293 /**
294 * Tests the returns of tt_content + empty record
295 * @test
296 */
297 public function getSpriteIconForRecordWithEmptyRecordReturnsNormalSprite() {
298 $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', array());
299
300 $this->assertEquals(
301 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">&nbsp;</span>',
302 $result
303 );
304 }
305
306 /**
307 * Tests the returns of tt_content + mock record
308 * @test
309 */
310 public function getSpriteIconForRecordWithMockRecordReturnsNormalSprite() {
311 $mockRecord = $this->mockRecord;
312 $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord);
313
314 $this->assertEquals(
315 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">&nbsp;</span>',
316 $result
317 );
318 }
319
320 /**
321 * Tests the returns of tt_content + mock record + options
322 * @test
323 */
324 public function getSpriteIconForRecordWithMockRecordAndOptionsReturnsNormalSprite() {
325 $mockRecord = $this->mockRecord;
326 $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord, array('class' => 'foo', 'title' => 'bar'));
327
328 $this->assertEquals(
329 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text foo" title="bar">&nbsp;</span>',
330 $result
331 );
332 }
333
334 /**
335 * Tests the returns of tt_content + mock record of type 'list' (aka plugin)
336 * @test
337 */
338 public function getSpriteIconForRecordWithMockRecordOfTypePluginReturnsPluginSprite() {
339 $mockRecord = $this->mockRecord;
340 $mockRecord['CType'] = 'list';
341 $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord);
342
343 $this->assertEquals(
344 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-plugin">&nbsp;</span>',
345 $result
346 );
347 }
348
349 /**
350 * Tests the returns of tt_content + mock record with hidden flag
351 * @test
352 */
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">&nbsp;</span>';
358
359 $this->assertEquals(
360 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">' . $overlay . '</span>',
361 $result
362 );
363 }
364
365
366 //////////////////////////////////////////
367 // Tests concerning getSpriteIconForFile
368 //////////////////////////////////////////
369
370 /**
371 * Tests the returns of no file
372 * @test
373 */
374 public function getSpriteIconForFileWithNoFileTypeReturnsOtherSprite() {
375 $result = t3lib_iconWorks::getSpriteIconForFile('');
376
377 $this->assertEquals(
378 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>',
379 $result
380 );
381 }
382
383 /**
384 * Tests the returns of unknown file
385 * @test
386 */
387 public function getSpriteIconForFileWithNoUnknowFileTypeReturnsOtherSprite() {
388 $result = t3lib_iconWorks::getSpriteIconForFile('foo');
389
390 $this->assertEquals(
391 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>',
392 $result
393 );
394 }
395
396 /**
397 * Tests the returns of file pdf
398 * @test
399 */
400 public function getSpriteIconForFileWithPdfReturnsPdfSprite() {
401 $result = t3lib_iconWorks::getSpriteIconForFile('pdf');
402
403 $this->assertEquals(
404 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-pdf t3-icon-pdf">&nbsp;</span>',
405 $result
406 );
407 }
408
409 /**
410 * Tests the returns of file png
411 * @test
412 */
413 public function getSpriteIconForFileWithPngReturnsPngSprite() {
414 $result = t3lib_iconWorks::getSpriteIconForFile('png');
415
416 $this->assertEquals(
417 '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>',
418 $result
419 );
420 }
421
422 /**
423 * Tests the returns of file png + option
424 * @test
425 */
426 public function getSpriteIconForFileWithPngAndOptionsReturnsPngSpriteAndOptions() {
427 $result = t3lib_iconWorks::getSpriteIconForFile('png', array('title' => 'bar'));
428
429 $this->assertEquals(
430 '<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>',
431 $result
432 );
433 }
434 }
435 ?>