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