[TASK] Move access right parameters from BE to SYS configuration
[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 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\IconUtilityFixture;
18
19 /**
20 * Test case
21 */
22 class IconUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
23 {
24 /**
25 * @var array Simulate a tt_content record
26 */
27 protected $mockRecord = array(
28 'header' => 'dummy content header',
29 'uid' => '1',
30 'pid' => '1',
31 'image' => '',
32 'hidden' => '0',
33 'starttime' => '0',
34 'endtime' => '0',
35 'fe_group' => '',
36 'CType' => 'text',
37 't3ver_id' => '0',
38 't3ver_state' => '0',
39 't3ver_wsid' => '0',
40 'sys_language_uid' => '0',
41 'l18n_parent' => '0',
42 'subheader' => '',
43 'bodytext' => '',
44 );
45
46 /**
47 * Create folder object to use as test subject
48 *
49 * @param string $identifier
50 * @return \TYPO3\CMS\Core\Resource\Folder
51 */
52 protected function getTestSubjectFolderObject($identifier)
53 {
54 $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false);
55 $mockedStorage->expects($this->any())->method('getRootLevelFolder')->will($this->returnValue(
56 new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, '/', '/')
57 ));
58 $mockedStorage->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(true));
59 $mockedStorage->expects($this->any())->method('isBrowsable')->will($this->returnValue(true));
60 return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $identifier, $identifier);
61 }
62
63 /**
64 * Create file object to use as test subject
65 *
66 * @param $extension
67 * @return \TYPO3\CMS\Core\Resource\File
68 */
69 protected function getTestSubjectFileObject($extension)
70 {
71 $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false);
72 $mockedFile = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(array(), $mockedStorage));
73 $mockedFile->expects($this->once())->method('getExtension')->will($this->returnValue($extension));
74 return $mockedFile;
75 }
76
77 //////////////////////////////////////////
78 // Tests concerning imagemake
79 //////////////////////////////////////////
80 /**
81 * @test
82 */
83 public function imagemakeFixesPermissionsOnNewFiles()
84 {
85 if (TYPO3_OS == 'WIN') {
86 $this->markTestSkipped('imagemakeFixesPermissionsOnNewFiles() test not available on Windows.');
87 }
88 $fixtureGifFile = __DIR__ . '/Fixtures/clear.gif';
89 // Create image resource, determine target filename, fake target permission, run method and clean up
90 $fixtureGifRessource = imagecreatefromgif($fixtureGifFile);
91 $targetFilename = PATH_site . 'typo3temp/' . $this->getUniqueId('test_') . '.gif';
92 $this->testFilesToDelete[] = $targetFilename;
93 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'] = '0777';
94 IconUtilityFixture::imagemake($fixtureGifRessource, $targetFilename);
95 clearstatcache();
96 $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
97 $this->assertEquals($resultFilePermissions, '0777');
98 }
99
100 //////////////////////////////////////////
101 // Tests concerning getSpriteIconClasses
102 //////////////////////////////////////////
103 /**
104 * Tests whether an empty string returns 't3-icon'
105 *
106 * @test
107 */
108 public function getSpriteIconClassesWithEmptyStringReturnsT3Icon()
109 {
110 $this->assertEquals('t3-icon', IconUtilityFixture::getSpriteIconClasses(''));
111 }
112
113 /**
114 * Tests whether one part returns 't3-icon'
115 *
116 * @test
117 */
118 public function getSpriteIconClassesWithOnePartReturnsT3Icon()
119 {
120 $this->assertEquals('t3-icon', IconUtilityFixture::getSpriteIconClasses('actions'));
121 }
122
123 /**
124 * Tests the return of two parts
125 *
126 * @test
127 */
128 public function getSpriteIconClassesWithTwoPartsReturnsT3IconAndCombinedParts()
129 {
130 $result = explode(' ', IconUtilityFixture::getSpriteIconClasses('actions-juggle'));
131 sort($result);
132 $this->assertEquals(array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle'), $result);
133 }
134
135 /**
136 * Tests the return of tree parts
137 *
138 * @test
139 */
140 public function getSpriteIconClassesWithThreePartsReturnsT3IconAndCombinedParts()
141 {
142 $result = explode(' ', IconUtilityFixture::getSpriteIconClasses('actions-juggle-speed'));
143 sort($result);
144 $this->assertEquals(array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed'), $result);
145 }
146
147 /**
148 * Tests the return of four parts
149 *
150 * @test
151 */
152 public function getSpriteIconClassesWithFourPartsReturnsT3IconAndCombinedParts()
153 {
154 $result = explode(' ', IconUtilityFixture::getSpriteIconClasses('actions-juggle-speed-game'));
155 sort($result);
156 $this->assertEquals(array('t3-icon', 't3-icon-actions', 't3-icon-actions-juggle', 't3-icon-juggle-speed-game'), $result);
157 }
158 }