TYPO3 CMS  TYPO3_8-7
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 
20 class ExtensionUtilityTest extends \TYPO3\TestingFramework\Core\Unit\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 
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 
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 
90  {
91  $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
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 
116  {
117  $this->expectException(\InvalidArgumentException::class);
118  $this->expectExceptionCode(1239891990);
120  'FirstController' => 'index'
121  ]);
122  }
123 
129  {
130  $this->expectException(\InvalidArgumentException::class);
131  $this->expectExceptionCode(1239891988);
133  'FirstController' => 'index'
134  ]);
135  }
136 
142  {
143  $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
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 
171  {
172  $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
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 
200  {
201  $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
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 
234  {
235  $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
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 
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';
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 
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';
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 
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  $this->assertEmpty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']);
341 
343 
344  $this->assertContains($typeConverterClassName, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']);
345  $this->assertEquals(1, count($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']));
346 
348  $this->assertEquals(1, count($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']));
349  }
350 }
static configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions=[], $pluginType=self::PLUGIN_TYPE_PLUGIN)
static registerTypeConverter($typeConverterClassName)
static registerPlugin($extensionName, $pluginName, $pluginTitle, $pluginIcon=null)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']