[!!!][TASK] Extract testing framework for TYPO3
[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 * 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 /**
18 * Testcase for class \TYPO3\CMS\Extbase\Utility\ExtensionUtility
19 */
20 class ExtensionUtilityTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
21 {
22 protected function setUp()
23 {
24 $GLOBALS['TSFE'] = new \stdClass();
25 $GLOBALS['TSFE']->tmpl = new \stdClass();
26 $GLOBALS['TSFE']->tmpl->setup = [];
27 $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = [
28 '9' => 'CASE',
29 '9.' => [
30 'key.' => [
31 'field' => 'layout'
32 ],
33 0 => '< plugin.tt_news'
34 ],
35 'extensionname_someplugin' => 'USER',
36 'extensionname_someplugin.' => [
37 'userFunc' => \TYPO3\CMS\Extbase\Core\Bootstrap::class . '->run',
38 'extensionName' => 'ExtensionName',
39 'pluginName' => 'SomePlugin'
40 ],
41 'someotherextensionname_secondplugin' => 'USER',
42 'someotherextensionname_secondplugin.' => [
43 'userFunc' => \TYPO3\CMS\Extbase\Core\Bootstrap::class . '->run',
44 'extensionName' => 'SomeOtherExtensionName',
45 'pluginName' => 'SecondPlugin'
46 ],
47 'extensionname_thirdplugin' => 'USER',
48 'extensionname_thirdplugin.' => [
49 'userFunc' => \TYPO3\CMS\Extbase\Core\Bootstrap::class . '->run',
50 'extensionName' => 'ExtensionName',
51 'pluginName' => 'ThirdPlugin'
52 ]
53 ];
54 }
55
56 /**
57 * @test
58 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
59 */
60 public function configurePluginWorksForMinimalisticSetup()
61 {
62 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
63 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', ['Blog' => 'index']);
64 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
65 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
66 $this->assertContains('
67 userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
68 extensionName = MyExtension
69 pluginName = Pi1', $staticTypoScript);
70 $this->assertNotContains('USER_INT', $staticTypoScript);
71 }
72
73 /**
74 * @test
75 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
76 */
77 public function configurePluginCreatesCorrectDefaultTypoScriptSetup()
78 {
79 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
80 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', ['Blog' => 'index']);
81 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
82 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
83 }
84
85 /**
86 * @test
87 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
88 */
89 public function configurePluginWorksForASingleControllerAction()
90 {
91 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
92 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
93 'FirstController' => 'index'
94 ]);
95 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
96 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
97 $this->assertContains('
98 extensionName = MyExtension
99 pluginName = Pi1', $staticTypoScript);
100 $expectedResult = [
101 'controllers' => [
102 'FirstController' => [
103 'actions' => ['index']
104 ]
105 ],
106 'pluginType' => 'list_type'
107 ];
108 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
109 }
110
111 /**
112 * @test
113 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
114 */
115 public function configurePluginThrowsExceptionIfExtensionNameIsEmpty()
116 {
117 $this->expectException(\InvalidArgumentException::class);
118 $this->expectExceptionCode(1239891990);
119 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('', 'SomePlugin', [
120 'FirstController' => 'index'
121 ]);
122 }
123
124 /**
125 * @test
126 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
127 */
128 public function configurePluginThrowsExceptionIfPluginNameIsEmpty()
129 {
130 $this->expectException(\InvalidArgumentException::class);
131 $this->expectExceptionCode(1239891988);
132 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', '', [
133 'FirstController' => 'index'
134 ]);
135 }
136
137 /**
138 * @test
139 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
140 */
141 public function configurePluginRespectsDefaultActionAsANonCacheableAction()
142 {
143 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
144 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
145 'FirstController' => 'index,show,new, create,delete,edit,update'
146 ], [
147 'FirstController' => 'index,show'
148 ]);
149 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
150 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
151 $this->assertContains('
152 extensionName = MyExtension
153 pluginName = Pi1', $staticTypoScript);
154 $expectedResult = [
155 'controllers' => [
156 'FirstController' => [
157 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
158 'nonCacheableActions' => ['index', 'show']
159 ]
160 ],
161 'pluginType' => 'list_type'
162 ];
163 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
164 }
165
166 /**
167 * @test
168 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
169 */
170 public function configurePluginRespectsNonDefaultActionAsANonCacheableAction()
171 {
172 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
173 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
174 'FirstController' => 'index,show,new, create,delete,edit,update'
175 ], [
176 'FirstController' => 'new,show'
177 ]);
178 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
179 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
180 $this->assertContains('
181 extensionName = MyExtension
182 pluginName = Pi1', $staticTypoScript);
183 $expectedResult = [
184 'controllers' => [
185 'FirstController' => [
186 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
187 'nonCacheableActions' => ['new', 'show']
188 ]
189 ],
190 'pluginType' => 'list_type'
191 ];
192 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
193 }
194
195 /**
196 * @test
197 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
198 */
199 public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault()
200 {
201 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
202 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
203 'FirstController' => 'index,show,new,create,delete,edit,update',
204 'SecondController' => 'index,show,delete',
205 'ThirdController' => 'create'
206 ], [
207 'FirstController' => 'new,create,edit,update',
208 'ThirdController' => 'create'
209 ]);
210 $expectedResult = [
211 'controllers' => [
212 'FirstController' => [
213 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
214 'nonCacheableActions' => ['new', 'create', 'edit', 'update']
215 ],
216 'SecondController' => [
217 'actions' => ['index', 'show', 'delete']
218 ],
219 'ThirdController' => [
220 'actions' => ['create'],
221 'nonCacheableActions' => ['create']
222 ]
223 ],
224 'pluginType' => 'list_type'
225 ];
226 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
227 }
228
229 /**
230 * @test
231 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
232 */
233 public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault()
234 {
235 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
236 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
237 'FirstController' => 'index,show,new,create,delete,edit,update',
238 'SecondController' => 'index,show,delete',
239 'ThirdController' => 'create'
240 ], [
241 'FirstController' => 'index,new,create,edit,update',
242 'SecondController' => 'delete',
243 'ThirdController' => 'create'
244 ]);
245 $expectedResult = [
246 'controllers' => [
247 'FirstController' => [
248 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
249 'nonCacheableActions' => ['index', 'new', 'create', 'edit', 'update']
250 ],
251 'SecondController' => [
252 'actions' => ['index', 'show', 'delete'],
253 'nonCacheableActions' => ['delete']
254 ],
255 'ThirdController' => [
256 'actions' => ['create'],
257 'nonCacheableActions' => ['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 * Tests method combination of registerPlugin() and its dependency addPlugin() to
267 * verify plugin icon path resolving works.
268 *
269 * @test
270 */
271 public function registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUnderscoredExtensionNameAndIconPathNotGiven()
272 {
273 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
274 $GLOBALS['TYPO3_LOADED_EXT'] = [];
275 $GLOBALS['TYPO3_LOADED_EXT']['indexed_search']['ext_icon'] = 'foo.gif';
276 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
277 'indexed_search',
278 'Pi2',
279 'Testing'
280 );
281 $this->assertEquals(
282 'EXT:indexed_search/foo.gif',
283 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
284 );
285 }
286
287 /**
288 * Tests method combination of registerPlugin() and its dependency addPlugin() to
289 * verify plugin icon path resolving works.
290 *
291 * @test
292 */
293 public function registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUpperCameCasedExtensionNameAndIconPathNotGiven()
294 {
295 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
296 $GLOBALS['TYPO3_LOADED_EXT'] = [];
297 $GLOBALS['TYPO3_LOADED_EXT']['indexed_search']['ext_icon'] = 'foo.gif';
298 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
299 'IndexedSearch',
300 'Pi2',
301 'Testing'
302 );
303 $this->assertEquals(
304 'EXT:indexed_search/foo.gif',
305 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
306 );
307 }
308
309 /**
310 * Tests method combination of registerPlugin() and its dependency addPlugin() to
311 * verify plugin icon path resolving works.
312 *
313 * @test
314 */
315 public function registerPluginTriggersAddPluginWhichSetsPluginIconPathIfIconPathIsGiven()
316 {
317 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
318 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
319 'IndexedSearch',
320 'Pi2',
321 'Testing',
322 'EXT:indexed_search/foo.gif'
323 );
324 $this->assertEquals(
325 'EXT:indexed_search/foo.gif',
326 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
327 );
328 }
329 }