TYPO3 CMS  TYPO3_6-2
ExtensionServiceTest.php
Go to the documentation of this file.
1 <?php
3 
21 
26 
30  protected $extensionService;
31 
32  public function setUp() {
33  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('fullQuoteStr', 'exec_SELECTgetRows'));
34  $GLOBALS['TSFE'] = new \stdClass();
35  $this->extensionService = $this->getAccessibleMock('TYPO3\CMS\Extbase\Service\ExtensionService', array('dummy'));
36  $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
37  $this->extensionService->_set('configurationManager', $this->mockConfigurationManager);
38  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'] = array(
39  'ExtensionName' => array(
40  'plugins' => array(
41  'SomePlugin' => array(
42  'controllers' => array(
43  'ControllerName' => array(
44  'actions' => array('index', 'otherAction')
45  )
46  )
47  ),
48  'ThirdPlugin' => array(
49  'controllers' => array(
50  'ControllerName' => array(
51  'actions' => array('otherAction', 'thirdAction')
52  )
53  )
54  )
55  )
56  ),
57  'SomeOtherExtensionName' => array(
58  'plugins' => array(
59  'SecondPlugin' => array(
60  'controllers' => array(
61  'ControllerName' => array(
62  'actions' => array('index', 'otherAction')
63  ),
64  'SecondControllerName' => array(
65  'actions' => array('someAction', 'someOtherAction'),
66  'nonCacheableActions' => array('someOtherAction')
67  )
68  )
69  )
70  )
71  )
72  );
73  }
74 
80  public function getPluginNamespaceDataProvider() {
81  return array(
82  array('SomeExtension', 'SomePlugin', 'tx_someextension_someplugin'),
83  array('NonExistingExtension', 'SomePlugin', 'tx_nonexistingextension_someplugin'),
84  array('Invalid', '', 'tx_invalid_')
85  );
86  }
87 
95  public function getPluginNamespaceTests($extensionName, $pluginName, $expectedResult) {
96  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array()));
97  $actualResult = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
98  $this->assertEquals($expectedResult, $actualResult, 'Failing for extension: "' . $extensionName . '", plugin: "' . $pluginName . '"');
99  }
100 
104  public function pluginNamespaceCanBeOverridden() {
105  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'SomeExtension', 'SomePlugin')->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
106  $expectedResult = 'overridden_plugin_namespace';
107  $actualResult = $this->extensionService->getPluginNamespace('SomeExtension', 'SomePlugin');
108  $this->assertEquals($expectedResult, $actualResult);
109  }
110 
117  return array(
118  array('ExtensionName', 'ControllerName', 'someNonExistingAction', NULL),
119  array('ExtensionName', 'ControllerName', 'index', 'SomePlugin'),
120  array('ExtensionName', 'ControllerName', 'thirdAction', 'ThirdPlugin'),
121  array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'thirdAction', NULL),
122  array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'ThIrDaCtIoN', NULL),
123  array('SomeOtherExtensionName', 'ControllerName', 'otherAction', 'SecondPlugin')
124  );
125  }
126 
135  public function getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult) {
136  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
137  $actualResult = $this->extensionService->getPluginNameByAction($extensionName, $controllerName, $actionName);
138  $this->assertEquals($expectedResult, $actualResult, 'Failing for $extensionName: "' . $extensionName . '", $controllerName: "' . $controllerName . '", $actionName: "' . $actionName . '" - ');
139  }
140 
146  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
147  $this->extensionService->getPluginNameByAction('ExtensionName', 'ControllerName', 'otherAction');
148  }
149 
154  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('extensionName' => 'CurrentExtension', 'pluginName' => 'CurrentPlugin', 'controllerConfiguration' => array('ControllerName' => array('actions' => array('otherAction'))))));
155  $actualResult = $this->extensionService->getPluginNameByAction('CurrentExtension', 'ControllerName', 'otherAction');
156  $expectedResult = 'CurrentPlugin';
157  $this->assertEquals($expectedResult, $actualResult);
158  }
159 
164  $mockConfiguration = array();
165  $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
166  $actualResult = $this->extensionService->isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
167  $this->assertTrue($actualResult);
168  }
169 
174  $mockConfiguration = array(
175  'controllerConfiguration' => array(
176  'SomeController' => array(
177  'nonCacheableActions' => array('someAction')
178  )
179  )
180  );
181  $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
182  $actualResult = $this->extensionService->isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
183  $this->assertFalse($actualResult);
184  }
185 
190  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(NULL));
191  $this->assertNull($this->extensionService->getTargetPidByPlugin('ExtensionName', 'PluginName'));
192  }
193 
198  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 0))));
199  $this->assertNull($this->extensionService->getTargetPidByPlugin('ExtensionName', 'PluginName'));
200  }
201 
206  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 123))));
207  $expectedResult = 123;
208  $actualResult = $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
209  $this->assertEquals($expectedResult, $actualResult);
210  }
211 
216  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
217  $pluginSignature = 'extensionname_someplugin';
218  $GLOBALS['TSFE']->sys_page = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('enableFields'));
219  $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->with('tt_content')->will($this->returnValue(' AND enable_fields'));
220  $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->with($pluginSignature, 'tt_content')->will($this->returnValue('"pluginSignature"'));
221  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('pid', 'tt_content', 'list_type="pluginSignature" AND CType="list" AND enable_fields AND sys_language_uid=', '', '')->will($this->returnValue(array(array('pid' => '321'))));
222  $expectedResult = 321;
223  $actualResult = $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
224  $this->assertEquals($expectedResult, $actualResult);
225  }
226 
231  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
232  $GLOBALS['TSFE']->sys_page = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('enableFields'));
233  $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
234  $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
235  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array()));
236  $this->assertNull($this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin'));
237  }
238 
244  $this->mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
245  $GLOBALS['TSFE']->sys_page = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('enableFields'));
246  $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
247  $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
248  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array(array('pid' => 123), array('pid' => 124))));
249  $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
250  }
251 
256  $this->assertNull($this->extensionService->getDefaultControllerNameByPlugin('NonExistingExtensionName', 'SomePlugin'));
257  }
258 
263  $this->assertNull($this->extensionService->getDefaultControllerNameByPlugin('ExtensionName', 'NonExistingPlugin'));
264  }
265 
270  $expectedResult = 'ControllerName';
271  $actualResult = $this->extensionService->getDefaultControllerNameByPlugin('ExtensionName', 'SomePlugin');
272  $this->assertEquals($expectedResult, $actualResult);
273  }
274 
279  $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController('NonExistingExtensionName', 'SomePlugin', 'ControllerName'));
280  }
281 
286  $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController('ExtensionName', 'NonExistingPlugin', 'ControllerName'));
287  }
288 
293  $this->assertNull($this->extensionService->getDefaultActionNameByPluginAndController('ExtensionName', 'SomePlugin', 'NonExistingControllerName'));
294  }
295 
300  $expectedResult = 'someAction';
301  $actualResult = $this->extensionService->getDefaultActionNameByPluginAndController('SomeOtherExtensionName', 'SecondPlugin', 'SecondControllerName');
302  $this->assertEquals($expectedResult, $actualResult);
303  }
304 }
getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult)
getPluginNamespaceTests($extensionName, $pluginName, $expectedResult)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]