[TASK] Use FQCN's when registering plugins/modules
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / UnitDeprecated / Utility / ExtensionUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\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 use TYPO3\CMS\Extbase\Core\Bootstrap;
18 use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Testcase for class \TYPO3\CMS\Extbase\Utility\ExtensionUtility
23 */
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
60 /**
61 * @test
62 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
63 */
64 public function configurePluginWorksForMinimalisticSetup()
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
77 /**
78 * @test
79 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
80 */
81 public function configurePluginCreatesCorrectDefaultTypoScriptSetup()
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
89 /**
90 * @test
91 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
92 */
93 public function configurePluginWorksForASingleControllerAction()
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 'MyExtension\Controller\FirstControllerController' => [
107 'className' => 'MyExtension\Controller\FirstControllerController',
108 'alias' => 'FirstController',
109 'actions' => ['index']
110 ]
111 ],
112 'pluginType' => 'list_type'
113 ];
114 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
115 }
116
117 /**
118 * @test
119 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
120 */
121 public function configurePluginRespectsDefaultActionAsANonCacheableAction()
122 {
123 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
124 ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
125 'First' => 'index,show,new, create,delete,edit,update'
126 ], [
127 'First' => 'index,show'
128 ]);
129 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
130 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
131 $this->assertContains('
132 extensionName = MyExtension
133 pluginName = Pi1', $staticTypoScript);
134 $expectedResult = [
135 'controllers' => [
136 'MyExtension\Controller\FirstController' => [
137 'className' => 'MyExtension\Controller\FirstController',
138 'alias' => 'First',
139 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
140 'nonCacheableActions' => ['index', 'show']
141 ]
142 ],
143 'pluginType' => 'list_type'
144 ];
145 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
146 }
147
148 /**
149 * @test
150 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
151 */
152 public function configurePluginRespectsNonDefaultActionAsANonCacheableAction()
153 {
154 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
155 ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
156 'First' => 'index,show,new, create,delete,edit,update'
157 ], [
158 'First' => 'new,show'
159 ]);
160 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
161 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
162 $this->assertContains('
163 extensionName = MyExtension
164 pluginName = Pi1', $staticTypoScript);
165 $expectedResult = [
166 'controllers' => [
167 'MyExtension\Controller\FirstController' => [
168 'className' => 'MyExtension\Controller\FirstController',
169 'alias' => 'First',
170 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
171 'nonCacheableActions' => ['new', 'show']
172 ]
173 ],
174 'pluginType' => 'list_type'
175 ];
176 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
177 }
178
179 /**
180 * @test
181 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
182 */
183 public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault()
184 {
185 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
186 ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
187 'First' => 'index,show,new,create,delete,edit,update',
188 'Second' => 'index,show,delete',
189 'Third' => 'create'
190 ], [
191 'First' => 'new,create,edit,update',
192 'Third' => 'create'
193 ]);
194 $expectedResult = [
195 'controllers' => [
196 'MyExtension\Controller\FirstController' => [
197 'className' => 'MyExtension\Controller\FirstController',
198 'alias' => 'First',
199 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
200 'nonCacheableActions' => ['new', 'create', 'edit', 'update']
201 ],
202 'MyExtension\Controller\SecondController' => [
203 'className' => 'MyExtension\Controller\SecondController',
204 'alias' => 'Second',
205 'actions' => ['index', 'show', 'delete']
206 ],
207 'MyExtension\Controller\ThirdController' => [
208 'className' => 'MyExtension\Controller\ThirdController',
209 'alias' => 'Third',
210 'actions' => ['create'],
211 'nonCacheableActions' => ['create']
212 ]
213 ],
214 'pluginType' => 'list_type'
215 ];
216 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
217 }
218
219 /**
220 * @test
221 * @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin
222 */
223 public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault()
224 {
225 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = [];
226 ExtensionUtility::configurePlugin('MyExtension', 'Pi1', [
227 'First' => 'index,show,new,create,delete,edit,update',
228 'Second' => 'index,show,delete',
229 'Third' => 'create'
230 ], [
231 'First' => 'index,new,create,edit,update',
232 'Second' => 'delete',
233 'Third' => 'create'
234 ]);
235 $expectedResult = [
236 'controllers' => [
237 'MyExtension\Controller\FirstController' => [
238 'className' => 'MyExtension\Controller\FirstController',
239 'alias' => 'First',
240 'actions' => ['index', 'show', 'new', 'create', 'delete', 'edit', 'update'],
241 'nonCacheableActions' => ['index', 'new', 'create', 'edit', 'update']
242 ],
243 'MyExtension\Controller\SecondController' => [
244 'className' => 'MyExtension\Controller\SecondController',
245 'alias' => 'Second',
246 'actions' => ['index', 'show', 'delete'],
247 'nonCacheableActions' => ['delete']
248 ],
249 'MyExtension\Controller\ThirdController' => [
250 'className' => 'MyExtension\Controller\ThirdController',
251 'alias' => 'Third',
252 'actions' => ['create'],
253 'nonCacheableActions' => ['create']
254 ]
255 ],
256 'pluginType' => 'list_type'
257 ];
258 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
259 }
260 }