2 /***************************************************************
5 * (c) 2009 Oliver Hader <oliver@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
26 * Testcase for class Tx_Extbase_Utility_Extension
31 class Tx_Extbase_Tests_Unit_Utility_ExtensionTest
extends tx_phpunit_testcase
{
34 * Contains backup of $TYPO3_CONF_VARS
37 protected $typo3ConfVars = array();
40 * @var t3lib_fe contains a backup of the current $GLOBALS['TSFE']
42 protected $tsfeBackup;
44 public function setUp() {
45 $this->typo3ConfVars
= $GLOBALS['TYPO3_CONF_VARS'];
46 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('fullQuoteStr', 'exec_SELECTgetRows'));
47 $this->tsfeBackup
= $GLOBALS['TSFE'];
48 if (!isset($GLOBALS['TSFE']->tmpl
)) {
49 $GLOBALS['TSFE']->tmpl
= new stdClass();
51 if (!isset($GLOBALS['TSFE']->tmpl
->setup
)) {
52 $GLOBALS['TSFE']->tmpl
->setup
= array();
54 $GLOBALS['TSFE']->tmpl
->setup
['tt_content.']['list.']['20.'] = array(
59 0 => '< plugin.tt_news'
61 'extensionname_someplugin' => 'USER',
62 'extensionname_someplugin.' => array(
63 'userFunc' => 'Tx_Extbase_Core_Bootstrap->run',
64 'extensionName' => 'ExtensionName',
65 'pluginName' => 'SomePlugin',
67 'someotherextensionname_secondplugin' => 'USER',
68 'someotherextensionname_secondplugin.' => array(
69 'userFunc' => 'Tx_Extbase_Core_Bootstrap->run',
70 'extensionName' => 'SomeOtherExtensionName',
71 'pluginName' => 'SecondPlugin',
73 'extensionname_thirdplugin' => 'USER',
74 'extensionname_thirdplugin.' => array(
75 'userFunc' => 'Tx_Extbase_Core_Bootstrap->run',
76 'extensionName' => 'ExtensionName',
77 'pluginName' => 'ThirdPlugin',
82 public function tearDown() {
83 $GLOBALS['TYPO3_CONF_VARS'] = $this->typo3ConfVars
;
84 $GLOBALS['TSFE'] = $this->tsfeBackup
;
89 * @see Tx_Extbase_Utility_Extension::registerPlugin
91 public function configurePluginWorksForMinimalisticSetup() {
92 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
93 Tx_Extbase_Utility_Extension
::configurePlugin(
96 array('Blog' => 'index')
98 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
100 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
101 $this->assertContains('
102 userFunc = Tx_Extbase_Core_Bootstrap->run
103 extensionName = MyExtension
104 pluginName = Pi1', $staticTypoScript);
106 $this->assertNotContains('USER_INT', $staticTypoScript);
112 * @see Tx_Extbase_Utility_Extension::registerPlugin
114 public function configurePluginCreatesCorrectDefaultTypoScriptSetup() {
115 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
116 Tx_Extbase_Utility_Extension
::configurePlugin(
119 array('Blog' => 'index')
121 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
122 $defaultTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'];
123 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
124 $this->assertContains('
125 plugin.tx_myextension {
137 # 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.
140 }', $defaultTypoScript);
145 * @see Tx_Extbase_Utility_Extension::registerPlugin
147 public function configurePluginWorksForASingleControllerAction() {
148 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
149 Tx_Extbase_Utility_Extension
::configurePlugin(
153 'FirstController' => 'index'
156 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
158 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
159 $this->assertContains('
160 extensionName = MyExtension
161 pluginName = Pi1', $staticTypoScript);
163 $expectedResult = array(
164 'controllers' => array(
165 'FirstController' => array(
166 'actions' => array('index')
169 'pluginType' => 'list_type'
171 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
176 * @expectedException InvalidArgumentException
177 * @see Tx_Extbase_Utility_Extension::registerPlugin
179 public function configurePluginThrowsExceptionIfExtensionNameIsEmpty() {
180 Tx_Extbase_Utility_Extension
::configurePlugin(
184 'FirstController' => 'index'
191 * @expectedException InvalidArgumentException
192 * @see Tx_Extbase_Utility_Extension::registerPlugin
194 public function configurePluginThrowsExceptionIfPluginNameIsEmpty() {
195 Tx_Extbase_Utility_Extension
::configurePlugin(
199 'FirstController' => 'index'
207 * @see Tx_Extbase_Utility_Extension::registerPlugin
209 public function configurePluginRespectsDefaultActionAsANonCacheableAction() {
210 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
211 Tx_Extbase_Utility_Extension
::configurePlugin(
215 'FirstController' => 'index,show,new, create,delete,edit,update'
218 'FirstController' => 'index,show'
221 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
222 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
223 $this->assertContains('
224 extensionName = MyExtension
225 pluginName = Pi1', $staticTypoScript);
227 $expectedResult = array(
228 'controllers' => array(
229 'FirstController' => array(
230 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
231 'nonCacheableActions' => array('index', 'show')
234 'pluginType' => 'list_type'
236 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
241 * @see Tx_Extbase_Utility_Extension::registerPlugin
243 public function configurePluginRespectsNonDefaultActionAsANonCacheableAction() {
244 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
245 Tx_Extbase_Utility_Extension
::configurePlugin(
249 'FirstController' => 'index,show,new, create,delete,edit,update'
252 'FirstController' => 'new,show'
255 $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
256 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
257 $this->assertContains('
258 extensionName = MyExtension
259 pluginName = Pi1', $staticTypoScript);
261 $expectedResult = array(
262 'controllers' => array(
263 'FirstController' => array(
264 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
265 'nonCacheableActions' => array('new', 'show')
268 'pluginType' => 'list_type'
270 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
275 * @see Tx_Extbase_Utility_Extension::registerPlugin
277 public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault() {
278 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
279 Tx_Extbase_Utility_Extension
::configurePlugin(
283 'FirstController' => 'index,show,new,create,delete,edit,update',
284 'SecondController' => 'index,show,delete',
285 'ThirdController' => 'create'
288 'FirstController' => 'new,create,edit,update',
289 'ThirdController' => 'create'
293 $expectedResult = array(
294 'controllers' => array(
295 'FirstController' => array(
296 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
297 'nonCacheableActions' => array('new', 'create', 'edit', 'update')
299 'SecondController' => array(
300 'actions' => array('index', 'show', 'delete')
302 'ThirdController' => array(
303 'actions' => array('create'),
304 'nonCacheableActions' => array('create')
307 'pluginType' => 'list_type'
309 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
315 * @see Tx_Extbase_Utility_Extension::registerPlugin
317 public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault() {
318 $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
319 Tx_Extbase_Utility_Extension
::configurePlugin(
323 'FirstController' => 'index,show,new,create,delete,edit,update',
324 'SecondController' => 'index,show,delete',
325 'ThirdController' => 'create'
328 'FirstController' => 'index,new,create,edit,update',
329 'SecondController' => 'delete',
330 'ThirdController' => 'create'
334 $expectedResult = array(
335 'controllers' => array(
336 'FirstController' => array(
337 'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
338 'nonCacheableActions' => array('index', 'new', 'create', 'edit', 'update')
340 'SecondController' => array(
341 'actions' => array('index', 'show', 'delete'),
342 'nonCacheableActions' => array('delete')
344 'ThirdController' => array(
345 'actions' => array('create'),
346 'nonCacheableActions' => array('create')
349 'pluginType' => 'list_type'
351 $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);