[BUGFIX] Followup Fluid Template Fallback paths
[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 templateRootPaths {
115 #example: fooKey = EXT:bar/foo
116 }
117 layoutRootPaths {
118 #example: fooKey = EXT:bar/foo
119 }
120 partialRootPaths {
121 #example: fooKey = EXT:bar/foo
122 }
123 # 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.
124 defaultPid =
125 }
126 }', $defaultTypoScript);
127 }
128
129 /**
130 * @test
131 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
132 */
133 public function configurePluginWorksForASingleControllerAction() {
134 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
135 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
136 'FirstController' => 'index'
137 ));
138 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
139 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
140 $this->assertContains('
141 extensionName = MyExtension
142 pluginName = Pi1', $staticTypoScript);
143 $expectedResult = array(
144 'controllers' => array(
145 'FirstController' => array(
146 'actions' => array('index')
147 )
148 ),
149 'pluginType' => 'list_type'
150 );
151 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
152 }
153
154 /**
155 * @test
156 * @expectedException \InvalidArgumentException
157 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
158 */
159 public function configurePluginThrowsExceptionIfExtensionNameIsEmpty() {
160 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('', 'SomePlugin', array(
161 'FirstController' => 'index'
162 ));
163 }
164
165 /**
166 * @test
167 * @expectedException \InvalidArgumentException
168 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
169 */
170 public function configurePluginThrowsExceptionIfPluginNameIsEmpty() {
171 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', '', array(
172 'FirstController' => 'index'
173 ));
174 }
175
176 /**
177 * @test
178 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
179 */
180 public function configurePluginRespectsDefaultActionAsANonCacheableAction() {
181 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
182 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
183 'FirstController' => 'index,show,new, create,delete,edit,update'
184 ), array(
185 'FirstController' => 'index,show'
186 ));
187 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
188 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
189 $this->assertContains('
190 extensionName = MyExtension
191 pluginName = Pi1', $staticTypoScript);
192 $expectedResult = array(
193 'controllers' => array(
194 'FirstController' => array(
195 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
196 'nonCacheableActions' => array('index', 'show')
197 )
198 ),
199 'pluginType' => 'list_type'
200 );
201 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
202 }
203
204 /**
205 * @test
206 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
207 */
208 public function configurePluginRespectsNonDefaultActionAsANonCacheableAction() {
209 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
210 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
211 'FirstController' => 'index,show,new, create,delete,edit,update'
212 ), array(
213 'FirstController' => 'new,show'
214 ));
215 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
216 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
217 $this->assertContains('
218 extensionName = MyExtension
219 pluginName = Pi1', $staticTypoScript);
220 $expectedResult = array(
221 'controllers' => array(
222 'FirstController' => array(
223 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
224 'nonCacheableActions' => array('new', 'show')
225 )
226 ),
227 'pluginType' => 'list_type'
228 );
229 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
230 }
231
232 /**
233 * @test
234 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
235 */
236 public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault() {
237 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
238 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
239 'FirstController' => 'index,show,new,create,delete,edit,update',
240 'SecondController' => 'index,show,delete',
241 'ThirdController' => 'create'
242 ), array(
243 'FirstController' => 'new,create,edit,update',
244 'ThirdController' => 'create'
245 ));
246 $expectedResult = array(
247 'controllers' => array(
248 'FirstController' => array(
249 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
250 'nonCacheableActions' => array('new', 'create', 'edit', 'update')
251 ),
252 'SecondController' => array(
253 'actions' => array('index', 'show', 'delete')
254 ),
255 'ThirdController' => array(
256 'actions' => array('create'),
257 'nonCacheableActions' => array('create')
258 )
259 ),
260 'pluginType' => 'list_type'
261 );
262 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
263 }
264
265 /**
266 * @test
267 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
268 */
269 public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault() {
270 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
271 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
272 'FirstController' => 'index,show,new,create,delete,edit,update',
273 'SecondController' => 'index,show,delete',
274 'ThirdController' => 'create'
275 ), array(
276 'FirstController' => 'index,new,create,edit,update',
277 'SecondController' => 'delete',
278 'ThirdController' => 'create'
279 ));
280 $expectedResult = array(
281 'controllers' => array(
282 'FirstController' => array(
283 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
284 'nonCacheableActions' => array('index', 'new', 'create', 'edit', 'update')
285 ),
286 'SecondController' => array(
287 'actions' => array('index', 'show', 'delete'),
288 'nonCacheableActions' => array('delete')
289 ),
290 'ThirdController' => array(
291 'actions' => array('create'),
292 'nonCacheableActions' => array('create')
293 )
294 ),
295 'pluginType' => 'list_type'
296 );
297 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
298 }
299 }