TYPO3 API  SVNRelease
t3lib_iconWorksTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010-2011 Fabien Udriot <fabien.udriot@ecodev.ch>
00006 *  (c) 2010-2011 Oliver Klee <typo3-coding@oliverklee.de>
00007 *  All rights reserved
00008 *
00009 *  This script is part of the TYPO3 project. The TYPO3 project is
00010 *  free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  The GNU General Public License can be found at
00016 *  http://www.gnu.org/copyleft/gpl.html.
00017 *
00018 *  This script is distributed in the hope that it will be useful,
00019 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 *  GNU General Public License for more details.
00022 *
00023 *  This copyright notice MUST APPEAR in all copies of the script!
00024 ***************************************************************/
00025 
00026 /**
00027  * Testcase for class t3lib_iconWorks.
00028  *
00029  * @author Fabien Udriot <fabien.udriot@ecodev.ch>
00030  * @author Oliver Klee <typo3-coding@oliverklee.de>
00031  *
00032  * @package TYPO3
00033  * @subpackage t3lib
00034  */
00035 class t3lib_iconWorksTest extends tx_phpunit_testcase {
00036 
00037     /**
00038      * Enable backup of global and system variables
00039      *
00040      * @var boolean
00041      */
00042     protected $backupGlobals = TRUE;
00043 
00044     /**
00045      * Exclude TYPO3_DB from backup/restore of $GLOBALS
00046      * because resource types cannot be handled during serializing
00047      *
00048      * @var array
00049      */
00050     protected $backupGlobalsBlacklist = array('TYPO3_DB');
00051 
00052     /**
00053      * @var array
00054      */
00055     protected $mockRecord;
00056 
00057     public function setUp() {
00058             // Simulate a tt_content record
00059         $this->mockRecord = array();
00060         $this->mockRecord['header'] = 'dummy content header';
00061         $this->mockRecord['uid'] = '1';
00062         $this->mockRecord['pid'] = '1';
00063         $this->mockRecord['image'] = '';
00064         $this->mockRecord['hidden'] = '0';
00065         $this->mockRecord['starttime'] = '0';
00066         $this->mockRecord['endtime'] = '0';
00067         $this->mockRecord['fe_group'] = '';
00068         $this->mockRecord['CType'] = 'text';
00069         $this->mockRecord['t3ver_id'] = '0';
00070         $this->mockRecord['t3ver_state'] = '0';
00071         $this->mockRecord['t3ver_wsid'] = '0';
00072         $this->mockRecord['sys_language_uid'] = '0';
00073         $this->mockRecord['l18n_parent'] = '0';
00074         $this->mockRecord['subheader'] = '';
00075         $this->mockRecord['bodytext'] = '';
00076     }
00077 
00078     public function tearDown() {
00079         unset($this->mockRecord);
00080     }
00081 
00082 
00083     //////////////////////////////////////////
00084     // Tests concerning imagemake
00085     //////////////////////////////////////////
00086 
00087     /**
00088      * @test
00089      */
00090     public function imagemakeFixesPermissionsOnNewFiles() {
00091         if (TYPO3_OS == 'WIN') {
00092             $this->markTestSkipped('imagemakeFixesPermissionsOnNewFiles() test not available on Windows.');
00093         }
00094 
00095         $testFinder = t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder');
00096         $fixtureGifFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.gif';
00097 
00098             // Create image ressource, determine target filename, fake target permission, run method and clean up
00099         $fixtureGifRessource = imagecreatefromgif($fixtureGifFile);
00100         $targetFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
00101         $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
00102         t3lib_iconWorks::imagemake($fixtureGifRessource, $targetFilename);
00103         clearstatcache();
00104         $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
00105         t3lib_div::unlink_tempfile($targetFilename);
00106 
00107         $this->assertEquals($resultFilePermissions, '0777');
00108     }
00109 
00110 
00111     //////////////////////////////////////////
00112     // Tests concerning getSpriteIconClasses
00113     //////////////////////////////////////////
00114 
00115     /**
00116      * Tests whether an empty string returns 't3-icon'
00117      * @test
00118      */
00119     public function getSpriteIconClassesWithEmptyStringReturnsT3Icon() {
00120         $this->assertEquals(
00121             't3-icon',
00122             t3lib_iconWorks::getSpriteIconClasses('')
00123         );
00124     }
00125 
00126     /**
00127      * Tests whether one part returns 't3-icon'
00128      * @test
00129      */
00130     public function getSpriteIconClassesWithOnePartReturnsT3Icon() {
00131         $this->assertEquals(
00132             't3-icon',
00133             t3lib_iconWorks::getSpriteIconClasses('actions')
00134         );
00135     }
00136 
00137     /**
00138      * Tests the return of two parts
00139      * @test
00140      */
00141     public function getSpriteIconClassesWithTwoPartsReturnsT3IconAndCombinedParts() {
00142         $result = explode(' ', t3lib_iconWorks::getSpriteIconClasses('actions-juggle'));
00143         sort($result);
00144 
00145         $this->assertEquals(
00146             array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle'),
00147             $result
00148         );
00149     }
00150 
00151     /**
00152      * Tests the return of tree parts
00153      * @test
00154      */
00155     public function getSpriteIconClassesWithThreePartsReturnsT3IconAndCombinedParts() {
00156         $result = explode(' ', t3lib_iconWorks::getSpriteIconClasses('actions-juggle-speed'));
00157         sort($result);
00158 
00159         $this->assertEquals(
00160             array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed'),
00161             $result
00162         );
00163     }
00164 
00165     /**
00166      * Tests the return of four parts
00167      * @test
00168      */
00169     public function getSpriteIconClassesWithFourPartsReturnsT3IconAndCombinedParts() {
00170         $result = explode(' ', t3lib_iconWorks::getSpriteIconClasses('actions-juggle-speed-game'));
00171         sort($result);
00172 
00173         $this->assertEquals(
00174             array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed-game'),
00175             $result
00176         );
00177     }
00178 
00179     //////////////////////////////////////////
00180     // Tests concerning getSpriteIcon
00181     //////////////////////////////////////////
00182 
00183     /**
00184      * Tests whether an empty string returns a span with the missing sprite
00185      * @test
00186      */
00187     public function getSpriteIconWithEmptyStringReturnsSpanWithIconMissingSprite() {
00188         $this->assertEquals(
00189             '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>',
00190             t3lib_iconWorks::getSpriteIcon('')
00191         );
00192     }
00193 
00194     /**
00195      * Tests whether an non existing icons returns a span with the missing sprite
00196      * @test
00197      */
00198     public function getSpriteIconWithMissingIconReturnsSpanWithIconMissingSprite() {
00199         $this->assertEquals(
00200             '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>',
00201             t3lib_iconWorks::getSpriteIcon('actions-juggle-speed')
00202         );
00203     }
00204 
00205     /**
00206      * Tests whether an existing icon returns a span with the correct sprite
00207      * @test
00208      */
00209     public function getSpriteIconWithExistingIconReturnsSpanWithIconSprite() {
00210         $this->assertEquals(
00211             '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">&nbsp;</span>',
00212             t3lib_iconWorks::getSpriteIcon('actions-document-new')
00213         );
00214     }
00215 
00216     /**
00217      * Tests the returns of an existing icon + an other attribute like title="foo"
00218      * @test
00219      */
00220     public function getSpriteIconWithExistingIconAndAttributeReturnsSpanWithIconSpriteAndAttribute() {
00221         $this->assertEquals(
00222             '<span title="foo" class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">&nbsp;</span>',
00223             t3lib_iconWorks::getSpriteIcon('actions-document-new', array('title' => 'foo'))
00224         );
00225     }
00226 
00227     /**
00228      * Tests the returns of an existing icon + a class attribute
00229      * @test
00230      */
00231     public function getSpriteIconWithExistingIconAndClassAttributeReturnsSpanWithIconSpriteAndClassAttribute() {
00232         $this->assertEquals(
00233             '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new foo">&nbsp;</span>',
00234             t3lib_iconWorks::getSpriteIcon('actions-document-new', array('class' => 'foo'))
00235         );
00236     }
00237 
00238     /**
00239      * Tests the returns of an existing icon + a class attribute
00240      * @test
00241      */
00242     public function getSpriteIconWithExistingIconAndInnerHTMLReturnsSpanWithIconSpriteAndInnerHTML() {
00243         $this->assertEquals(
00244             '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">foo</span>',
00245             t3lib_iconWorks::getSpriteIcon('actions-document-new', array('html' => 'foo'))
00246         );
00247     }
00248 
00249     /**
00250      * Tests the returns of an existing icon + an overlay
00251      * @test
00252      */
00253     public function getSpriteIconWithExistingIconAndOverlayReturnsSpanWithIconSpriteAndOverlay() {
00254         $result = t3lib_iconWorks::getSpriteIcon('actions-document-new', array(), array('status-overlay-hidden' => array()));
00255         $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden t3-icon-overlay">&nbsp;</span>';
00256         $this->assertEquals(
00257             '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>',
00258             $result
00259         );
00260     }
00261 
00262     /**
00263      * Tests the returns of an existing icon + an overlay
00264      * @test
00265      */
00266     public function getSpriteIconWithExistingIconAndOverlayAndAttributesReturnsSpanWithIconSpriteAndOverlayAndAttributes() {
00267         $result = t3lib_iconWorks::getSpriteIcon('actions-document-new', array('html' => 'foo1'), array('status-overlay-hidden' => array('class' => 'foo2')));
00268         $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden foo2 t3-icon-overlay">foo1</span>';
00269         $this->assertEquals(
00270             '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-new">' . $overlay . '</span>',
00271             $result
00272         );
00273     }
00274 
00275 
00276     //////////////////////////////////////////
00277     // Tests concerning getSpriteIconForRecord
00278     //////////////////////////////////////////
00279 
00280     /**
00281      * Tests the returns of null table + empty array
00282      * @test
00283      */
00284     public function getSpriteIconForRecordWithNullTableReturnsMissingIcon() {
00285         $result = t3lib_iconWorks::getSpriteIconForRecord('', array());
00286 
00287         $this->assertEquals(
00288             '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-icon-missing">&nbsp;</span>',
00289             $result
00290         );
00291     }
00292 
00293     /**
00294      * Tests the returns of tt_content + empty record
00295      * @test
00296      */
00297     public function getSpriteIconForRecordWithEmptyRecordReturnsNormalSprite() {
00298         $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', array());
00299 
00300         $this->assertEquals(
00301             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">&nbsp;</span>',
00302             $result
00303         );
00304     }
00305 
00306     /**
00307      * Tests the returns of tt_content + mock record
00308      * @test
00309      */
00310     public function getSpriteIconForRecordWithMockRecordReturnsNormalSprite() {
00311         $mockRecord = $this->mockRecord;
00312         $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord);
00313 
00314         $this->assertEquals(
00315             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">&nbsp;</span>',
00316             $result
00317         );
00318     }
00319 
00320     /**
00321      * Tests the returns of tt_content + mock record + options
00322      * @test
00323      */
00324     public function getSpriteIconForRecordWithMockRecordAndOptionsReturnsNormalSprite() {
00325         $mockRecord = $this->mockRecord;
00326         $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord, array('class' => 'foo', 'title' => 'bar'));
00327 
00328         $this->assertEquals(
00329             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text foo" title="bar">&nbsp;</span>',
00330             $result
00331         );
00332     }
00333 
00334     /**
00335      * Tests the returns of tt_content + mock record of type 'list' (aka plugin)
00336      * @test
00337      */
00338     public function getSpriteIconForRecordWithMockRecordOfTypePluginReturnsPluginSprite() {
00339         $mockRecord = $this->mockRecord;
00340         $mockRecord['CType'] = 'list';
00341         $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord);
00342 
00343         $this->assertEquals(
00344             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-plugin">&nbsp;</span>',
00345             $result
00346         );
00347     }
00348 
00349     /**
00350      * Tests the returns of tt_content + mock record with hidden flag
00351      * @test
00352      */
00353     public function getSpriteIconForRecordWithMockRecordWithHiddenFlagReturnsNormalSpriteAndOverlay() {
00354         $mockRecord = $this->mockRecord;
00355         $mockRecord['hidden'] = '1';
00356         $result = t3lib_iconWorks::getSpriteIconForRecord('tt_content', $mockRecord);
00357         $overlay = '<span class="t3-icon t3-icon-status t3-icon-status-overlay t3-icon-overlay-hidden t3-icon-overlay">&nbsp;</span>';
00358 
00359         $this->assertEquals(
00360             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-x t3-icon-x-content-text">' . $overlay . '</span>',
00361             $result
00362         );
00363     }
00364 
00365 
00366     //////////////////////////////////////////
00367     // Tests concerning getSpriteIconForFile
00368     //////////////////////////////////////////
00369 
00370     /**
00371      * Tests the returns of no file
00372      * @test
00373      */
00374     public function getSpriteIconForFileWithNoFileTypeReturnsOtherSprite() {
00375         $result = t3lib_iconWorks::getSpriteIconForFile('');
00376 
00377         $this->assertEquals(
00378             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>',
00379             $result
00380         );
00381     }
00382 
00383     /**
00384      * Tests the returns of unknown file
00385      * @test
00386      */
00387     public function getSpriteIconForFileWithNoUnknowFileTypeReturnsOtherSprite() {
00388         $result = t3lib_iconWorks::getSpriteIconForFile('foo');
00389 
00390         $this->assertEquals(
00391             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-other t3-icon-other-other">&nbsp;</span>',
00392             $result
00393         );
00394     }
00395 
00396     /**
00397      * Tests the returns of file pdf
00398      * @test
00399      */
00400     public function getSpriteIconForFileWithPdfReturnsPdfSprite() {
00401         $result = t3lib_iconWorks::getSpriteIconForFile('pdf');
00402 
00403         $this->assertEquals(
00404             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-pdf t3-icon-pdf">&nbsp;</span>',
00405             $result
00406         );
00407     }
00408 
00409     /**
00410      * Tests the returns of file png
00411      * @test
00412      */
00413     public function getSpriteIconForFileWithPngReturnsPngSprite() {
00414         $result = t3lib_iconWorks::getSpriteIconForFile('png');
00415 
00416         $this->assertEquals(
00417             '<span class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>',
00418             $result
00419         );
00420     }
00421 
00422     /**
00423      * Tests the returns of file png + option
00424      * @test
00425      */
00426     public function getSpriteIconForFileWithPngAndOptionsReturnsPngSpriteAndOptions() {
00427         $result = t3lib_iconWorks::getSpriteIconForFile('png', array('title' => 'bar'));
00428 
00429         $this->assertEquals(
00430             '<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image">&nbsp;</span>',
00431             $result
00432         );
00433     }
00434 }
00435 ?>