‪TYPO3CMS  10.4
ExtensionUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪ExtensionUtilityTest extends UnitTestCase
26 {
27  protected function ‪setUp(): void
28  {
29  parent::setUp();
30  ‪$GLOBALS['TSFE'] = new \stdClass();
31  ‪$GLOBALS['TSFE']->tmpl = new \stdClass();
32  ‪$GLOBALS['TSFE']->tmpl->setup = [];
33  ‪$GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = [
34  '9' => 'CASE',
35  '9.' => [
36  'key.' => [
37  'field' => 'layout'
38  ],
39  0 => '< plugin.tt_news'
40  ],
41  'extensionname_someplugin' => 'USER',
42  'extensionname_someplugin.' => [
43  'userFunc' => Bootstrap::class . '->run',
44  'extensionName' => 'ExtensionName',
45  'pluginName' => 'SomePlugin'
46  ],
47  'someotherextensionname_secondplugin' => 'USER',
48  'someotherextensionname_secondplugin.' => [
49  'userFunc' => Bootstrap::class . '->run',
50  'extensionName' => 'SomeOtherExtensionName',
51  'pluginName' => 'SecondPlugin'
52  ],
53  'extensionname_thirdplugin' => 'USER',
54  'extensionname_thirdplugin.' => [
55  'userFunc' => Bootstrap::class . '->run',
56  'extensionName' => 'ExtensionName',
57  'pluginName' => 'ThirdPlugin'
58  ]
59  ];
60  }
61 
67  {
68  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
69  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', ['Blog' => 'index']);
70  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
71  self::assertStringContainsString('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
72  self::assertStringContainsString('
73  userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
74  extensionName = MyExtension
75  pluginName = Pi1', $staticTypoScript);
76  self::assertStringNotContainsString('USER_INT', $staticTypoScript);
77  }
78 
84  {
85  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
86  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', ['Blog' => 'index']);
87  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
88  self::assertStringContainsString('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
89  }
90 
96  {
97  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
98  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
99  'FirstController' => 'index'
100  ]);
101  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
102  self::assertStringContainsString('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
103  self::assertStringContainsString('
104  extensionName = MyExtension
105  pluginName = Pi1', $staticTypoScript);
106  $expectedResult = [
107  'controllers' => [
108  'MyExtension\Controller\FirstControllerController' => [
109  'className' => 'MyExtension\Controller\FirstControllerController',
110  'alias' => 'FirstController',
111  'actions' => ['index']
112  ]
113  ],
114  'pluginType' => 'list_type'
115  ];
116  self::assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
117  }
118 
124  {
125  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
126  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
127  'First' => 'index,show,new, create,delete,edit,update'
128  ], [
129  'First' => 'index,show'
130  ]);
131  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
132  self::assertStringContainsString('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
133  self::assertStringContainsString('
134  extensionName = MyExtension
135  pluginName = Pi1', $staticTypoScript);
136  $expectedResult = [
137  'controllers' => [
138  'MyExtension\Controller\FirstController' => [
139  'className' => 'MyExtension\Controller\FirstController',
140  'alias' => 'First',
141  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
142  'nonCacheableActions' => ['index', 'show']
143  ]
144  ],
145  'pluginType' => 'list_type'
146  ];
147  self::assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
148  }
149 
155  {
156  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
157  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
158  'First' => 'index,show,new, create,delete,edit,update'
159  ], [
160  'First' => 'new,show'
161  ]);
162  $staticTypoScript = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
163  self::assertStringContainsString('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
164  self::assertStringContainsString('
165  extensionName = MyExtension
166  pluginName = Pi1', $staticTypoScript);
167  $expectedResult = [
168  'controllers' => [
169  'MyExtension\Controller\FirstController' => [
170  'className' => 'MyExtension\Controller\FirstController',
171  'alias' => 'First',
172  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
173  'nonCacheableActions' => ['new', 'show']
174  ]
175  ],
176  'pluginType' => 'list_type'
177  ];
178  self::assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
179  }
180 
186  {
187  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
188  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
189  'First' => 'index,show,new,create,delete,edit,update',
190  'Second' => 'index,show,delete',
191  'Third' => 'create'
192  ], [
193  'First' => 'new,create,edit,update',
194  'Third' => 'create'
195  ]);
196  $expectedResult = [
197  'controllers' => [
198  'MyExtension\Controller\FirstController' => [
199  'className' => 'MyExtension\Controller\FirstController',
200  'alias' => 'First',
201  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
202  'nonCacheableActions' => ['new', 'create', 'edit', 'update']
203  ],
204  'MyExtension\Controller\SecondController' => [
205  'className' => 'MyExtension\Controller\SecondController',
206  'alias' => 'Second',
207  'actions' => ['index', 'show', 'delete']
208  ],
209  'MyExtension\Controller\ThirdController' => [
210  'className' => 'MyExtension\Controller\ThirdController',
211  'alias' => 'Third',
212  'actions' => ['create'],
213  'nonCacheableActions' => ['create']
214  ]
215  ],
216  'pluginType' => 'list_type'
217  ];
218  self::assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
219  }
220 
226  {
227  ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
228  ‪ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
229  'First' => 'index,show,new,create,delete,edit,update',
230  'Second' => 'index,show,delete',
231  'Third' => 'create'
232  ], [
233  'First' => 'index,new,create,edit,update',
234  'Second' => 'delete',
235  'Third' => 'create'
236  ]);
237  $expectedResult = [
238  'controllers' => [
239  'MyExtension\Controller\FirstController' => [
240  'className' => 'MyExtension\Controller\FirstController',
241  'alias' => 'First',
242  'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
243  'nonCacheableActions' => ['index', 'new', 'create', 'edit', 'update']
244  ],
245  'MyExtension\Controller\SecondController' => [
246  'className' => 'MyExtension\Controller\SecondController',
247  'alias' => 'Second',
248  'actions' => ['index', 'show', 'delete'],
249  'nonCacheableActions' => ['delete']
250  ],
251  'MyExtension\Controller\ThirdController' => [
252  'className' => 'MyExtension\Controller\ThirdController',
253  'alias' => 'Third',
254  'actions' => ['create'],
255  'nonCacheableActions' => ['create']
256  ]
257  ],
258  'pluginType' => 'list_type'
259  ];
260  self::assertEquals($expectedResult, ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
261  }
262 
267  {
268  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
270  'TYPO3.CMS.IndexedSearch',
271  'Pi2',
272  'Testing'
273  );
274  self::assertSame(
275  'indexedsearch_pi2',
276  ‪$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][1]
277  );
278  }
279 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginWorksForASingleControllerAction
‪configurePluginWorksForASingleControllerAction()
Definition: ExtensionUtilityTest.php:95
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility\registerPlugin
‪static registerPlugin($extensionName, $pluginName, $pluginTitle, $pluginIcon=null, $group='default')
Definition: ExtensionUtility.php:161
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault
‪configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault()
Definition: ExtensionUtilityTest.php:225
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility
Definition: ExtensionUtility.php:30
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginRespectsDefaultActionAsANonCacheableAction
‪configurePluginRespectsDefaultActionAsANonCacheableAction()
Definition: ExtensionUtilityTest.php:123
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault
‪configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault()
Definition: ExtensionUtilityTest.php:185
‪TYPO3\CMS\Extbase\Utility\ExtensionUtility\configurePlugin
‪static configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions=[], $pluginType=self::PLUGIN_TYPE_PLUGIN)
Definition: ExtensionUtility.php:51
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility
Definition: ExtensionUtilityTest.php:16
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\setUp
‪setUp()
Definition: ExtensionUtilityTest.php:27
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginWorksForMinimalisticSetup
‪configurePluginWorksForMinimalisticSetup()
Definition: ExtensionUtilityTest.php:66
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginCreatesCorrectDefaultTypoScriptSetup
‪configurePluginCreatesCorrectDefaultTypoScriptSetup()
Definition: ExtensionUtilityTest.php:83
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\registerPluginRegistersPluginWithDeprecatedVendorInExtensionName
‪registerPluginRegistersPluginWithDeprecatedVendorInExtensionName()
Definition: ExtensionUtilityTest.php:266
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Core\Bootstrap
Definition: Bootstrap.php:43
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest\configurePluginRespectsNonDefaultActionAsANonCacheableAction
‪configurePluginRespectsNonDefaultActionAsANonCacheableAction()
Definition: ExtensionUtilityTest.php:154
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Utility\ExtensionUtilityTest
Definition: ExtensionUtilityTest.php:26