[+TASK] Extbase (Tests): Fixed Extbase unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Utility / ExtensionTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Oliver Hader <oliver@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for class Tx_Extbase_Utility_Extension
27 *
28 * @package Extbase
29 * @subpackage extbase
30 */
31 class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
32
33 /**
34 * Contains backup of $TYPO3_CONF_VARS
35 * @var array
36 */
37 protected $typo3ConfVars = array();
38
39 /**
40 * @var t3lib_DB
41 */
42 protected $typo3DbBackup;
43
44 /**
45 * @var t3lib_fe contains a backup of the current $GLOBALS['TSFE']
46 */
47 protected $tsfeBackup;
48
49 public function setUp() {
50 $this->typo3ConfVars = $GLOBALS['TYPO3_CONF_VARS'];
51 $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
52 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('fullQuoteStr', 'exec_SELECTgetRows'));
53 $this->tsfeBackup = $GLOBALS['TSFE'];
54 if (!isset($GLOBALS['TSFE']->tmpl)) {
55 $GLOBALS['TSFE']->tmpl = new stdClass();
56 }
57 if (!isset($GLOBALS['TSFE']->tmpl->setup)) {
58 $GLOBALS['TSFE']->tmpl->setup = array();
59 }
60 $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = array(
61 '9' => 'CASE',
62 '9.' => array(
63 'key.' => array(
64 'field' => 'layout'),
65 0 => '< plugin.tt_news'
66 ),
67 'extensionname_someplugin' => 'USER',
68 'extensionname_someplugin.' => array(
69 'userFunc' => 'tx_extbase_core_bootstrap->run',
70 'extensionName' => 'ExtensionName',
71 'pluginName' => 'SomePlugin',
72 ),
73 'someotherextensionname_secondplugin' => 'USER',
74 'someotherextensionname_secondplugin.' => array(
75 'userFunc' => 'tx_extbase_core_bootstrap->run',
76 'extensionName' => 'SomeOtherExtensionName',
77 'pluginName' => 'SecondPlugin',
78 ),
79 'extensionname_thirdplugin' => 'USER',
80 'extensionname_thirdplugin.' => array(
81 'userFunc' => 'tx_extbase_core_bootstrap->run',
82 'extensionName' => 'ExtensionName',
83 'pluginName' => 'ThirdPlugin',
84 ),
85 );
86 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'] = array(
87 'ExtensionName' => array(
88 'plugins' => array(
89 'SomePlugin' => array(
90 'controllers' => array(
91 'ControllerName' => array(
92 'actions' => array('index', 'otherAction')
93 ),
94 ),
95 ),
96 'ThirdPlugin' => array(
97 'controllers' => array(
98 'ControllerName' => array(
99 'actions' => array('otherAction', 'thirdAction')
100 ),
101 ),
102 ),
103 ),
104 ),
105 'SomeOtherExtensionName' => array(
106 'plugins' => array(
107 'SecondPlugin' => array(
108 'controllers' => array(
109 'ControllerName' => array(
110 'actions' => array('index', 'otherAction')
111 ),
112 'SecondControllerName' => array(
113 'actions' => array('someAction', 'someOtherAction'),
114 'nonCacheableActions' => array('someOtherAction')
115 )
116 ),
117 ),
118 ),
119 ),
120 );
121 }
122
123 public function tearDown() {
124 $GLOBALS['TYPO3_CONF_VARS'] = $this->typo3ConfVars;
125 $GLOBALS['TSFE'] = $this->tsfeBackup;
126 }
127
128 /**
129 * @test
130 * @see Tx_Extbase_Utility_Extension::registerPlugin
131 */
132 public function configurePluginWorksForMinimalisticSetup() {
133 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
134 Tx_Extbase_Utility_Extension::configurePlugin(
135 'MyExtension',
136 'Pi1',
137 array('Blog' => 'index')
138 );
139 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
140
141 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
142 $this->assertContains('
143 userFunc = tx_extbase_core_bootstrap->run
144 extensionName = MyExtension
145 pluginName = Pi1', $staticTypoScript);
146
147 $this->assertNotContains('USER_INT', $staticTypoScript);
148 }
149
150
151 /**
152 * @test
153 * @see Tx_Extbase_Utility_Extension::registerPlugin
154 */
155 public function configurePluginCreatesCorrectDefaultTypoScriptSetup() {
156 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
157 Tx_Extbase_Utility_Extension::configurePlugin(
158 'MyExtension',
159 'Pi1',
160 array('Blog' => 'index')
161 );
162 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
163 $defaultTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'];
164 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
165 $this->assertContains('
166 plugin.tx_myextension {
167 settings {
168 }
169 persistence {
170 storagePid =
171 classes {
172 }
173 }
174 view {
175 templateRootPath =
176 layoutRootPath =
177 partialRootPath =
178 # with defaultPid you can specify the default page uid of this plugin. If you set this to the string "auto" the target page will be determined automatically. Defaults to an empty string that expects the target page to be the current page.
179 defaultPid =
180 }
181 }', $defaultTypoScript);
182 }
183
184 /**
185 * @test
186 * @see Tx_Extbase_Utility_Extension::registerPlugin
187 */
188 public function configurePluginWorksForASingleControllerAction() {
189 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
190 Tx_Extbase_Utility_Extension::configurePlugin(
191 'MyExtension',
192 'Pi1',
193 array(
194 'FirstController' => 'index'
195 )
196 );
197 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
198
199 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
200 $this->assertContains('
201 extensionName = MyExtension
202 pluginName = Pi1', $staticTypoScript);
203
204 $expectedResult = array(
205 'controllers' => array(
206 'FirstController' => array(
207 'actions' => array('index')
208 )
209 ),
210 'pluginType' => 'list_type'
211 );
212 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
213 }
214
215 /**
216 * @test
217 * @expectedException InvalidArgumentException
218 * @see Tx_Extbase_Utility_Extension::registerPlugin
219 */
220 public function configurePluginThrowsExceptionIfExtensionNameIsEmpty() {
221 Tx_Extbase_Utility_Extension::configurePlugin(
222 '',
223 'SomePlugin',
224 array(
225 'FirstController' => 'index'
226 )
227 );
228 }
229
230 /**
231 * @test
232 * @expectedException InvalidArgumentException
233 * @see Tx_Extbase_Utility_Extension::registerPlugin
234 */
235 public function configurePluginThrowsExceptionIfPluginNameIsEmpty() {
236 Tx_Extbase_Utility_Extension::configurePlugin(
237 'MyExtension',
238 '',
239 array(
240 'FirstController' => 'index'
241 )
242 );
243 }
244
245
246 /**
247 * @test
248 * @see Tx_Extbase_Utility_Extension::registerPlugin
249 */
250 public function configurePluginRespectsDefaultActionAsANonCacheableAction() {
251 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
252 Tx_Extbase_Utility_Extension::configurePlugin(
253 'MyExtension',
254 'Pi1',
255 array(
256 'FirstController' => 'index,show,new, create,delete,edit,update'
257 ),
258 array(
259 'FirstController' => 'index,show'
260 )
261 );
262 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
263 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
264 $this->assertContains('
265 extensionName = MyExtension
266 pluginName = Pi1', $staticTypoScript);
267
268 $expectedResult = array(
269 'controllers' => array(
270 'FirstController' => array(
271 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
272 'nonCacheableActions' => array('index', 'show')
273 )
274 ),
275 'pluginType' => 'list_type'
276 );
277 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
278 }
279
280 /**
281 * @test
282 * @see Tx_Extbase_Utility_Extension::registerPlugin
283 */
284 public function configurePluginRespectsNonDefaultActionAsANonCacheableAction() {
285 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
286 Tx_Extbase_Utility_Extension::configurePlugin(
287 'MyExtension',
288 'Pi1',
289 array(
290 'FirstController' => 'index,show,new, create,delete,edit,update'
291 ),
292 array(
293 'FirstController' => 'new,show'
294 )
295 );
296 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
297 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
298 $this->assertContains('
299 extensionName = MyExtension
300 pluginName = Pi1', $staticTypoScript);
301
302 $expectedResult = array(
303 'controllers' => array(
304 'FirstController' => array(
305 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
306 'nonCacheableActions' => array('new', 'show')
307 )
308 ),
309 'pluginType' => 'list_type'
310 );
311 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
312 }
313
314 /**
315 * @test
316 * @see Tx_Extbase_Utility_Extension::registerPlugin
317 */
318 public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault() {
319 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
320 Tx_Extbase_Utility_Extension::configurePlugin(
321 'MyExtension',
322 'Pi1',
323 array(
324 'FirstController' => 'index,show,new,create,delete,edit,update',
325 'SecondController' => 'index,show,delete',
326 'ThirdController' => 'create'
327 ),
328 array(
329 'FirstController' => 'new,create,edit,update',
330 'ThirdController' => 'create'
331 )
332 );
333
334 $expectedResult = array(
335 'controllers' => array(
336 'FirstController' => array(
337 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
338 'nonCacheableActions' => array('new', 'create', 'edit', 'update')
339 ),
340 'SecondController' => array(
341 'actions' => array('index', 'show', 'delete')
342 ),
343 'ThirdController' => array(
344 'actions' => array('create'),
345 'nonCacheableActions' => array('create')
346 )
347 ),
348 'pluginType' => 'list_type'
349 );
350 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
351 }
352
353
354 /**
355 * @test
356 * @see Tx_Extbase_Utility_Extension::registerPlugin
357 */
358 public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault() {
359 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
360 Tx_Extbase_Utility_Extension::configurePlugin(
361 'MyExtension',
362 'Pi1',
363 array(
364 'FirstController' => 'index,show,new,create,delete,edit,update',
365 'SecondController' => 'index,show,delete',
366 'ThirdController' => 'create'
367 ),
368 array(
369 'FirstController' => 'index,new,create,edit,update',
370 'SecondController' => 'delete',
371 'ThirdController' => 'create'
372 )
373 );
374
375 $expectedResult = array(
376 'controllers' => array(
377 'FirstController' => array(
378 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
379 'nonCacheableActions' => array('index', 'new', 'create', 'edit', 'update')
380 ),
381 'SecondController' => array(
382 'actions' => array('index', 'show', 'delete'),
383 'nonCacheableActions' => array('delete')
384 ),
385 'ThirdController' => array(
386 'actions' => array('create'),
387 'nonCacheableActions' => array('create')
388 )
389 ),
390 'pluginType' => 'list_type'
391 );
392 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
393 }
394
395 /**
396 * DataProvider for getPluginNamespaceByPluginSignatureTests()
397 *
398 * @return array
399 */
400 public function getPluginNamespaceDataProvider() {
401 return array(
402 array('SomeExtension', 'SomePlugin', 'tx_someextension_someplugin'),
403 array('NonExistingExtension', 'SomePlugin', 'tx_nonexistingextension_someplugin'),
404 array('Invalid', '', 'tx_invalid_'),
405 );
406 }
407
408 /**
409 * @test
410 * @dataProvider getPluginNamespaceDataProvider
411 */
412 public function getPluginNamespaceTests($extensionName, $pluginName, $expectedResult) {
413 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
414 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array()));
415 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
416 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
417 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
418
419 $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespace($extensionName, $pluginName);
420 $this->assertEquals($expectedResult, $actualResult, 'Failing for extension: "' . $extensionName . '", plugin: "' . $pluginName . '"');
421 }
422
423 /**
424 * @test
425 */
426 public function pluginNamespaceCanBeOverridden() {
427 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
428 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'SomeExtension', 'SomePlugin')->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
429 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
430 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
431 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
432
433 $expectedResult = 'overridden_plugin_namespace';
434 $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespace('SomeExtension', 'SomePlugin');
435 $this->assertEquals($expectedResult, $actualResult);
436 }
437
438 /**
439 * DataProvider for getPluginNameByActionTests()
440 *
441 * @return array
442 */
443 public function getPluginNameByActionDataProvider() {
444 return array(
445 array('ExtensionName', 'ControllerName', 'someNonExistingAction', NULL),
446 array('ExtensionName', 'ControllerName', 'index', 'SomePlugin'),
447 array('ExtensionName', 'ControllerName', 'thirdAction', 'ThirdPlugin'),
448 array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'thirdAction', NULL),
449 array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'ThIrDaCtIoN', NULL),
450 array('SomeOtherExtensionName', 'ControllerName', 'otherAction', 'SecondPlugin'),
451 );
452 }
453
454 /**
455 * @test
456 * @dataProvider getPluginNameByActionDataProvider
457 */
458 public function getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult) {
459 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
460 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
461 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
462 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
463 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
464
465 $actualResult = Tx_Extbase_Utility_Extension::getPluginNameByAction($extensionName, $controllerName, $actionName);
466 $this->assertEquals($expectedResult, $actualResult, 'Failing for $extensionName: "' . $extensionName . '", $controllerName: "' . $controllerName . '", $actionName: "' . $actionName . '" - ');
467 }
468
469 /**
470 * @test
471 * @expectedException Tx_Extbase_Exception
472 */
473 public function getPluginNameByActionThrowsExceptionIfMoreThanOnePluginMatches() {
474 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
475 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
476 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
477 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
478 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
479
480 Tx_Extbase_Utility_Extension::getPluginNameByAction('ExtensionName', 'ControllerName', 'otherAction');
481 }
482
483 /**
484 * @test
485 */
486 public function getPluginNameByActionReturnsCurrentIfItCanHandleTheActionEvenIfMoreThanOnePluginMatches() {
487 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
488 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('extensionName' => 'CurrentExtension', 'pluginName' => 'CurrentPlugin', 'controllerConfiguration' => array('ControllerName' => array('actions' => array('otherAction'))))));
489 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
490 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
491 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
492
493 $actualResult = Tx_Extbase_Utility_Extension::getPluginNameByAction('CurrentExtension', 'ControllerName', 'otherAction');
494 $expectedResult = 'CurrentPlugin';
495 $this->assertEquals($expectedResult, $actualResult);
496 }
497
498 /**
499 * @test
500 */
501 public function getTargetPidByPluginSignatureReturnsNullIfConfigurationManagerIsNotInitialized() {
502 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
503 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(NULL));
504 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
505 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
506 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
507
508 $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'PluginName'));
509 }
510
511 /**
512 * @test
513 */
514 public function getTargetPidByPluginSignatureReturnsNullIfDefaultPidIsZero() {
515 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
516 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 0))));
517 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
518 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
519 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
520
521 $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'PluginName'));
522 }
523
524 /**
525 * @test
526 */
527 public function getTargetPidByPluginSignatureReturnsTheConfiguredDefaultPid() {
528 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
529 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 123))));
530 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
531 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
532 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
533
534 $expectedResult = 123;
535 $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
536 $this->assertEquals($expectedResult, $actualResult);
537 }
538
539 /**
540 * @test
541 */
542 public function getTargetPidByPluginSignatureDeterminesTheTargetPidIfDefaultPidIsAuto() {
543 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
544 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
545 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
546 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
547 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
548
549 $pluginSignature = 'extensionname_someplugin';
550 $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
551 $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->with('tt_content')->will($this->returnValue(' AND enable_fields'));
552 $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->with($pluginSignature, 'tt_content')->will($this->returnValue('"pluginSignature"'));
553 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with(
554 'pid',
555 'tt_content',
556 'list_type="pluginSignature" AND CType="list" AND enable_fields',
557 '',
558 ''
559 )->will($this->returnValue(array(array('pid' => '321'))));
560 $expectedResult = 321;
561 $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
562 $this->assertEquals($expectedResult, $actualResult);
563 }
564
565 /**
566 * @test
567 */
568 public function getTargetPidByPluginSignatureReturnsNullIfTargetPidCouldNotBeDetermined() {
569 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
570 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
571 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
572 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
573 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
574
575 $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
576 $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
577 $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
578 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array()));
579 $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin'));
580 }
581
582 /**
583 * @test
584 * @expectedException Tx_Extbase_Exception
585 */
586 public function getTargetPidByPluginSignatureThrowsExceptionIfMoreThanOneTargetPidsWereFound() {
587 $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
588 $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
589 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
590 $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
591 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
592
593 $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
594 $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
595 $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
596 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array(array('pid' => 123), array('pid' => 124))));
597 Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
598 }
599
600 }
601
602 ?>