‪TYPO3CMS  9.5
ExtensionUtilityTest.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪ExtensionUtilityTest extends UnitTestCase
25 {
26  protected function ‪setUp()
27  {
28  ‪$GLOBALS['TSFE'] = new \stdClass();
29  ‪$GLOBALS['TSFE']->tmpl = new \stdClass();
30  ‪$GLOBALS['TSFE']->tmpl->setup = [];
31  ‪$GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = [
32  '9' => 'CASE',
33  '9.' => [
34  'key.' => [
35  'field' => 'layout'
36  ],
37  0 => '< plugin.tt_news'
38  ],
39  'extensionname_someplugin' => 'USER',
40  'extensionname_someplugin.' => [
41  'userFunc' => Bootstrap::class . '->run',
42  'extensionName' => 'ExtensionName',
43  'pluginName' => 'SomePlugin'
44  ],
45  'someotherextensionname_secondplugin' => 'USER',
46  'someotherextensionname_secondplugin.' => [
47  'userFunc' => Bootstrap::class . '->run',
48  'extensionName' => 'SomeOtherExtensionName',
49  'pluginName' => 'SecondPlugin'
50  ],
51  'extensionname_thirdplugin' => 'USER',
52  'extensionname_thirdplugin.' => [
53  'userFunc' => Bootstrap::class . '->run',
54  'extensionName' => 'ExtensionName',
55  'pluginName' => 'ThirdPlugin'
56  ]
57  ];
58  }
59 
65  {
66  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
67  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', ['Blog' => 'index']);
68  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
69  $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
70  $this->assertContains('
71  userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
72  extensionName = MyExtension
73  pluginName = Pi1', $staticTypoScript);
74  $this->assertNotContains('USER_INT', $staticTypoScript);
75  }
76 
82  {
83  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
84  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', ['Blog' => 'index']);
85  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
86  $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
87  }
88 
94  {
95  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
96  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
97  'FirstController' => 'index'
98  ]);
99  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
100  $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
101  $this->assertContains('
102  extensionName = MyExtension
103  pluginName = Pi1', $staticTypoScript);
104  $expectedResult = [
105  'controllers' => [
106  'FirstController' => [
107  'actions' => ['index']
108  ]
109  ],
110  'pluginType' => 'list_type'
111  ];
112  $this->assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
113  }
114 
120  {
121  $this->expectException(\InvalidArgumentException::class);
122  $this->expectExceptionCode(1239891990);
123  ‪ExtensionUtility::configurePlugin('', 'SomePlugin', [
124  'FirstController' => 'index'
125  ]);
126  }
127 
133  {
134  $this->expectException(\InvalidArgumentException::class);
135  $this->expectExceptionCode(1239891988);
136  ‪ExtensionUtility::configurePlugin('MyExtension', '', [
137  'FirstController' => 'index'
138  ]);
139  }
140 
146  {
147  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
148  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
149  'FirstController' => 'index,show,new, create,delete,edit,update'
150  ], [
151  'FirstController' => 'index,show'
152  ]);
153  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
154  $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
155  $this->assertContains('
156  extensionName = MyExtension
157  pluginName = Pi1', $staticTypoScript);
158  $expectedResult = [
159  'controllers' => [
160  'FirstController' => [
161  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
162  'nonCacheableActions' => ['index', 'show']
163  ]
164  ],
165  'pluginType' => 'list_type'
166  ];
167  $this->assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
168  }
169 
175  {
176  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
177  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
178  'FirstController' => 'index,show,new, create,delete,edit,update'
179  ], [
180  'FirstController' => 'new,show'
181  ]);
182  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
183  $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
184  $this->assertContains('
185  extensionName = MyExtension
186  pluginName = Pi1', $staticTypoScript);
187  $expectedResult = [
188  'controllers' => [
189  'FirstController' => [
190  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
191  'nonCacheableActions' => ['new', 'show']
192  ]
193  ],
194  'pluginType' => 'list_type'
195  ];
196  $this->assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
197  }
198 
204  {
205  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
206  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
207  'FirstController' => 'index,show,new,create,delete,edit,update',
208  'SecondController' => 'index,show,delete',
209  'ThirdController' => 'create'
210  ], [
211  'FirstController' => 'new,create,edit,update',
212  'ThirdController' => 'create'
213  ]);
214  $expectedResult = [
215  'controllers' => [
216  'FirstController' => [
217  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
218  'nonCacheableActions' => ['new', 'create', 'edit', 'update']
219  ],
220  'SecondController' => [
221  'actions' => ['index', 'show', 'delete']
222  ],
223  'ThirdController' => [
224  'actions' => ['create'],
225  'nonCacheableActions' => ['create']
226  ]
227  ],
228  'pluginType' => 'list_type'
229  ];
230  $this->assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
231  }
232 
238  {
239  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
240  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
241  'FirstController' => 'index,show,new,create,delete,edit,update',
242  'SecondController' => 'index,show,delete',
243  'ThirdController' => 'create'
244  ], [
245  'FirstController' => 'index,new,create,edit,update',
246  'SecondController' => 'delete',
247  'ThirdController' => 'create'
248  ]);
249  $expectedResult = [
250  'controllers' => [
251  'FirstController' => [
252  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
253  'nonCacheableActions' => ['index', 'new', 'create', 'edit', 'update']
254  ],
255  'SecondController' => [
256  'actions' => ['index', 'show', 'delete'],
257  'nonCacheableActions' => ['delete']
258  ],
259  'ThirdController' => [
260  'actions' => ['create'],
261  'nonCacheableActions' => ['create']
262  ]
263  ],
264  'pluginType' => 'list_type'
265  ];
266  $this->assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
267  }
268 
276  {
277  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
279  'indexed_search',
280  'Pi2',
281  'Testing'
282  );
283  $this->assertEquals(
284  'EXT:indexed_search/Resources/Public/Icons/Extension.png',
285  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
286  );
287  }
288 
296  {
297  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
299  'IndexedSearch',
300  'Pi2',
301  'Testing'
302  );
303  $this->assertEquals(
304  'EXT:indexed_search/Resources/Public/Icons/Extension.png',
305  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
306  );
307  }
308 
316  {
317  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
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 
337  {
338  $typeConverterClassName = \TYPO3\CMS\Extbase\Property\TypeConverter\ArrayConverter::class;
339 
340  // the Extbase EXTCONF is not set at all at this point
341  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'] = [];
342 
344 
345  $this->assertContains($typeConverterClassName, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']);
346  $this->assertEquals(1, count(‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']));
347 
349  $this->assertEquals(1, count(‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']));
350  }
351 }
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginWorksForASingleControllerAction
‪configurePluginWorksForASingleControllerAction()
Definition: ExtensionUtilityTest.php:93
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault
‪configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault()
Definition: ExtensionUtilityTest.php:237
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility
Definition: ExtensionUtility.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUnderscoredExtensionNameAndIconPathNotGiven
‪registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUnderscoredExtensionNameAndIconPathNotGiven()
Definition: ExtensionUtilityTest.php:275
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest
Definition: ExtensionUtilityTest.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginCreatesCorrectDefaultTypoScriptSetup
‪configurePluginCreatesCorrectDefaultTypoScriptSetup()
Definition: ExtensionUtilityTest.php:81
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\registerPluginTriggersAddPluginWhichSetsPluginIconPathIfIconPathIsGiven
‪registerPluginTriggersAddPluginWhichSetsPluginIconPathIfIconPathIsGiven()
Definition: ExtensionUtilityTest.php:315
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUpperCameCasedExtensionNameAndIconPathNotGiven
‪registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUpperCameCasedExtensionNameAndIconPathNotGiven()
Definition: ExtensionUtilityTest.php:295
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility\registerTypeConverter
‪static registerTypeConverter($typeConverterClassName)
Definition: ExtensionUtility.php:211
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginWorksForMinimalisticSetup
‪configurePluginWorksForMinimalisticSetup()
Definition: ExtensionUtilityTest.php:64
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginThrowsExceptionIfPluginNameIsEmpty
‪configurePluginThrowsExceptionIfPluginNameIsEmpty()
Definition: ExtensionUtilityTest.php:132
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility\configurePlugin
‪static configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions=[], $pluginType=self::PLUGIN_TYPE_PLUGIN)
Definition: ExtensionUtility.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginRespectsNonDefaultActionAsANonCacheableAction
‪configurePluginRespectsNonDefaultActionAsANonCacheableAction()
Definition: ExtensionUtilityTest.php:174
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginRespectsDefaultActionAsANonCacheableAction
‪configurePluginRespectsDefaultActionAsANonCacheableAction()
Definition: ExtensionUtilityTest.php:145
‪TYPO3\CMS\Extbase\Tests\Unit\Utility
Definition: DebuggerUtilityTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\setUp
‪setUp()
Definition: ExtensionUtilityTest.php:26
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility\registerPlugin
‪static registerPlugin($extensionName, $pluginName, $pluginTitle, $pluginIcon=null)
Definition: ExtensionUtility.php:114
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Core\Bootstrap
Definition: Bootstrap.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginThrowsExceptionIfExtensionNameIsEmpty
‪configurePluginThrowsExceptionIfExtensionNameIsEmpty()
Definition: ExtensionUtilityTest.php:119
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault
‪configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault()
Definition: ExtensionUtilityTest.php:203
‪TYPO3\CMS\Extbase\Tests\Unit\Utility\ExtensionUtilityTest\sameTypeConvertersRegisteredAreAddedOnlyOnce
‪sameTypeConvertersRegisteredAreAddedOnlyOnce()
Definition: ExtensionUtilityTest.php:336