[BUGFIX] No double htmlspecialchars for filemount select
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Utility / ExtensionUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Oliver Hader <oliver@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for class \TYPO3\CMS\Extbase\Utility\ExtensionUtility
28 */
29 class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
30
31 /**
32 * A backup of the global database
33 *
34 * @var \TYPO3\CMS\Core\Database\DatabaseConnection
35 */
36 protected $databaseBackup = NULL;
37
38 public function setUp() {
39 $this->databaseBackup = $GLOBALS['TYPO3_DB'];
40 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('fullQuoteStr', 'exec_SELECTgetRows'));
41
42 $GLOBALS['TSFE'] = new \stdClass();
43 $GLOBALS['TSFE']->tmpl = new \stdClass();
44 $GLOBALS['TSFE']->tmpl->setup = array();
45 $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = array(
46 '9' => 'CASE',
47 '9.' => array(
48 'key.' => array(
49 'field' => 'layout'
50 ),
51 0 => '< plugin.tt_news'
52 ),
53 'extensionname_someplugin' => 'USER',
54 'extensionname_someplugin.' => array(
55 'userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run',
56 'extensionName' => 'ExtensionName',
57 'pluginName' => 'SomePlugin'
58 ),
59 'someotherextensionname_secondplugin' => 'USER',
60 'someotherextensionname_secondplugin.' => array(
61 'userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run',
62 'extensionName' => 'SomeOtherExtensionName',
63 'pluginName' => 'SecondPlugin'
64 ),
65 'extensionname_thirdplugin' => 'USER',
66 'extensionname_thirdplugin.' => array(
67 'userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run',
68 'extensionName' => 'ExtensionName',
69 'pluginName' => 'ThirdPlugin'
70 )
71 );
72 }
73
74 public function tearDown() {
75 $GLOBALS['TYPO3_DB'] = $this->databaseBackup;
76 }
77
78 /**
79 * @test
80 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
81 */
82 public function configurePluginWorksForMinimalisticSetup() {
83 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
84 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array('Blog' => 'index'));
85 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
86 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
87 $this->assertContains('
88 userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
89 extensionName = MyExtension
90 pluginName = Pi1', $staticTypoScript);
91 $this->assertNotContains('USER_INT', $staticTypoScript);
92 }
93
94 /**
95 * @test
96 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
97 */
98 public function configurePluginCreatesCorrectDefaultTypoScriptSetup() {
99 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
100 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array('Blog' => 'index'));
101 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
102 $defaultTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'];
103 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
104 $this->assertContains('
105 plugin.tx_myextension {
106 settings {
107 }
108 persistence {
109 storagePid =
110 classes {
111 }
112 }
113 view {
114 templateRootPath =
115 layoutRootPath =
116 partialRootPath =
117 # with defaultPid you can specify the default page uid of this plugin. If you set this to the string "auto" the target page will be determined automatically. Defaults to an empty string that expects the target page to be the current page.
118 defaultPid =
119 }
120 }', $defaultTypoScript);
121 }
122
123 /**
124 * @test
125 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
126 */
127 public function configurePluginWorksForASingleControllerAction() {
128 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
129 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
130 'FirstController' => 'index'
131 ));
132 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
133 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
134 $this->assertContains('
135 extensionName = MyExtension
136 pluginName = Pi1', $staticTypoScript);
137 $expectedResult = array(
138 'controllers' => array(
139 'FirstController' => array(
140 'actions' => array('index')
141 )
142 ),
143 'pluginType' => 'list_type'
144 );
145 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
146 }
147
148 /**
149 * @test
150 * @expectedException \InvalidArgumentException
151 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
152 */
153 public function configurePluginThrowsExceptionIfExtensionNameIsEmpty() {
154 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('', 'SomePlugin', array(
155 'FirstController' => 'index'
156 ));
157 }
158
159 /**
160 * @test
161 * @expectedException \InvalidArgumentException
162 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
163 */
164 public function configurePluginThrowsExceptionIfPluginNameIsEmpty() {
165 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', '', array(
166 'FirstController' => 'index'
167 ));
168 }
169
170 /**
171 * @test
172 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
173 */
174 public function configurePluginRespectsDefaultActionAsANonCacheableAction() {
175 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
176 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
177 'FirstController' => 'index,show,new, create,delete,edit,update'
178 ), array(
179 'FirstController' => 'index,show'
180 ));
181 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
182 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
183 $this->assertContains('
184 extensionName = MyExtension
185 pluginName = Pi1', $staticTypoScript);
186 $expectedResult = array(
187 'controllers' => array(
188 'FirstController' => array(
189 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
190 'nonCacheableActions' => array('index', 'show')
191 )
192 ),
193 'pluginType' => 'list_type'
194 );
195 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
196 }
197
198 /**
199 * @test
200 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
201 */
202 public function configurePluginRespectsNonDefaultActionAsANonCacheableAction() {
203 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
204 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
205 'FirstController' => 'index,show,new, create,delete,edit,update'
206 ), array(
207 'FirstController' => 'new,show'
208 ));
209 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
210 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
211 $this->assertContains('
212 extensionName = MyExtension
213 pluginName = Pi1', $staticTypoScript);
214 $expectedResult = array(
215 'controllers' => array(
216 'FirstController' => array(
217 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
218 'nonCacheableActions' => array('new', 'show')
219 )
220 ),
221 'pluginType' => 'list_type'
222 );
223 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
224 }
225
226 /**
227 * @test
228 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
229 */
230 public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault() {
231 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
232 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
233 'FirstController' => 'index,show,new,create,delete,edit,update',
234 'SecondController' => 'index,show,delete',
235 'ThirdController' => 'create'
236 ), array(
237 'FirstController' => 'new,create,edit,update',
238 'ThirdController' => 'create'
239 ));
240 $expectedResult = array(
241 'controllers' => array(
242 'FirstController' => array(
243 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
244 'nonCacheableActions' => array('new', 'create', 'edit', 'update')
245 ),
246 'SecondController' => array(
247 'actions' => array('index', 'show', 'delete')
248 ),
249 'ThirdController' => array(
250 'actions' => array('create'),
251 'nonCacheableActions' => array('create')
252 )
253 ),
254 'pluginType' => 'list_type'
255 );
256 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
257 }
258
259 /**
260 * @test
261 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
262 */
263 public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault() {
264 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
265 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
266 'FirstController' => 'index,show,new,create,delete,edit,update',
267 'SecondController' => 'index,show,delete',
268 'ThirdController' => 'create'
269 ), array(
270 'FirstController' => 'index,new,create,edit,update',
271 'SecondController' => 'delete',
272 'ThirdController' => 'create'
273 ));
274 $expectedResult = array(
275 'controllers' => array(
276 'FirstController' => array(
277 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
278 'nonCacheableActions' => array('index', 'new', 'create', 'edit', 'update')
279 ),
280 'SecondController' => array(
281 'actions' => array('index', 'show', 'delete'),
282 'nonCacheableActions' => array('delete')
283 ),
284 'ThirdController' => array(
285 'actions' => array('create'),
286 'nonCacheableActions' => array('create')
287 )
288 ),
289 'pluginType' => 'list_type'
290 );
291 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
292 }
293 }