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