Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Documentation / t3lib_extMgm_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
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 /**
27 * Testcase for class t3lib_extmgm
28 *
29 * @package TYPO3
30 * @subpackage t3lib
31 */
32 class t3lib_extMgm_testcase extends tx_phpunit_testcase {
33
34 public function setUp() {
35 global $TYPO3_CONF_VARS;
36 $this->TYPO3_CONF_VARS_backup = $TYPO3_CONF_VARS;
37 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
38 }
39
40 public function tearDown() {
41 global $TYPO3_CONF_VARS;
42 $TYPO3_CONF_VARS = $this->TYPO3_CONF_VARS_before;
43 }
44
45 /**
46 * @test
47 */
48 public function addingTsWorksForMinimalisticSetup() {
49 global $TYPO3_CONF_VARS;
50 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
51 t3lib_extMgm::addExtbasePlugin(
52 'pluginkey',
53 'my_extension'
54 );
55 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
56
57 $this->assertContains('includeLibs.tx_extbase_dispatcher = EXT:extbase/class.tx_extbase_dispatcher.php', $staticTypoScript, 'Did not include "tx_extbase_dispatcher".');
58 $this->assertContains('tt_content.list.20.my_extension_pluginkey = USER', $staticTypoScript);
59 $this->assertContains('
60 pluginKey = pluginkey
61 extensionName = MyExtension', $staticTypoScript);
62 $this->assertNotContains('controller =', $staticTypoScript);
63 $this->assertNotContains('action =', $staticTypoScript);
64 $this->assertNotContains('USER_INT', $staticTypoScript);
65 }
66
67 /**
68 * @test
69 */
70 public function addingTsWorksForASingleControllerAction() {
71 global $TYPO3_CONF_VARS;
72 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
73 t3lib_extMgm::addExtbasePlugin(
74 'pluginkey',
75 'my_extension',
76 array(
77 'FirstController' => 'index'
78 )
79 );
80 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
81
82 $this->assertContains('includeLibs.tx_extbase_dispatcher = EXT:extbase/class.tx_extbase_dispatcher.php', $staticTypoScript, 'Did not include "tx_extbase_dispatcher".');
83 $this->assertContains('tt_content.list.20.my_extension_pluginkey = USER', $staticTypoScript);
84 $this->assertContains('
85 pluginKey = pluginkey
86 extensionName = MyExtension
87 controller = FirstController
88 action = index', $staticTypoScript);
89 $this->assertNotContains('USER_INT', $staticTypoScript);
90 }
91
92 /**
93 * @test
94 */
95 public function addingPluginWithEmptyPluginKeyResultsInAnError() {
96 $this->setExpectedException('InvalidArgumentException');
97 t3lib_extMgm::addExtbasePlugin(
98 '',
99 'my_extension',
100 array(
101 'FirstController' => 'index'
102 )
103 );
104 }
105
106 /**
107 * @test
108 */
109 public function addingPluginWithEmptyExtensionKeyResultsInAnError() {
110 $this->setExpectedException('InvalidArgumentException');
111 t3lib_extMgm::addExtbasePlugin(
112 'pluginKey',
113 '',
114 array(
115 'FirstController' => 'index'
116 )
117 );
118 }
119
120 /**
121 * @test
122 */
123 public function addingPluginWithInvalidExtensionKeyResultsInAnError() {
124 $this->setExpectedException('InvalidArgumentException');
125 t3lib_extMgm::addExtbasePlugin(
126 'pluginKey',
127 'MyExtension',
128 array(
129 'FirstController' => 'index'
130 )
131 );
132 }
133
134 /**
135 * @test
136 */
137 public function theDefaultControllerActionCanBeSetManually() {
138 global $TYPO3_CONF_VARS;
139 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
140 t3lib_extMgm::addExtbasePlugin(
141 'pluginkey',
142 'my_extension',
143 array(
144 'FirstController' => 'index,show,new,create,delete,edit,update',
145 'SecondController' => 'index,show,delete',
146 'ThirdController' => 'create'
147 ),
148 array(),
149 array('SecondController' => 'show')
150 );
151 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
152
153 $this->assertContains('
154 pluginKey = pluginkey
155 extensionName = MyExtension
156 controller = SecondController
157 action = show', $staticTypoScript);
158 }
159
160 /**
161 * @test
162 */
163 public function addingPluginRespectsDefaultActionAsANonCachableAction() {
164 global $TYPO3_CONF_VARS;
165 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
166 t3lib_extMgm::addExtbasePlugin(
167 'pluginkey',
168 'my_extension',
169 array(
170 'FirstController' => 'index,show,new,create,delete,edit,update'
171 ),
172 array(
173 'FirstController' => 'index,show'
174 )
175 );
176 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
177
178 $this->assertContains('
179 tt_content.list.20.my_extension_pluginkey = USER_INT
180 tt_content.list.20.my_extension_pluginkey {', $staticTypoScript);
181 $this->assertContains('
182 [globalString: GP = tx_myextension_pluginkey|controller = FirstController] && [globalString: GP = tx_myextension_pluginkey|action = /new|create|delete|edit|update/]
183 tt_content.list.20.my_extension_pluginkey = USER', $staticTypoScript);
184 }
185
186 /**
187 * @test
188 */
189 public function addingPluginRespectsNonDefaultActionAsANonCachableAction() {
190 global $TYPO3_CONF_VARS;
191 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
192 t3lib_extMgm::addExtbasePlugin(
193 'pluginkey',
194 'my_extension',
195 array(
196 'FirstController' => 'index,show,new,create,delete,edit,update'
197 ),
198 array(
199 'FirstController' => 'show,new'
200 )
201 );
202 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
203
204 $this->assertContains('
205 tt_content.list.20.my_extension_pluginkey = USER
206 tt_content.list.20.my_extension_pluginkey {', $staticTypoScript);
207 $this->assertContains('
208 [globalString: GP = tx_myextension_pluginkey|controller = FirstController] && [globalString: GP = tx_myextension_pluginkey|action = /show|new/]
209 tt_content.list.20.my_extension_pluginkey = USER_INT', $staticTypoScript);
210 }
211
212 /**
213 * @test
214 */
215 public function addingPluginWorksForMultipleControllerActionsWithCachableActionAsDefault() {
216 global $TYPO3_CONF_VARS;
217 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
218 t3lib_extMgm::addExtbasePlugin(
219 'pluginkey',
220 'my_extension',
221 array(
222 'FirstController' => 'index,show,new,create,delete,edit,update',
223 'SecondController' => 'index,show,delete',
224 'ThirdController' => 'create'
225 ),
226 array(
227 'FirstController' => 'new,create,edit,update',
228 'SecondController' => 'delete',
229 'ThirdController' => 'create'
230 ),
231 array('SecondController' => 'show')
232 );
233 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
234
235 $this->assertContains('
236 tt_content.list.20.my_extension_pluginkey = USER
237 tt_content.list.20.my_extension_pluginkey {', $staticTypoScript);
238
239 $this->assertContains('
240 [globalString: GP = tx_myextension_pluginkey|controller = FirstController] && [globalString: GP = tx_myextension_pluginkey|action = /new|create|edit|update/]
241 tt_content.list.20.my_extension_pluginkey = USER_INT', $staticTypoScript);
242
243 $this->assertContains('
244 [globalString: GP = tx_myextension_pluginkey|controller = SecondController] && [globalString: GP = tx_myextension_pluginkey|action = /delete/]
245 tt_content.list.20.my_extension_pluginkey = USER_INT', $staticTypoScript);
246
247 $this->assertContains('
248 [globalString: GP = tx_myextension_pluginkey|controller = ThirdController] && [globalString: GP = tx_myextension_pluginkey|action = /create/]
249 tt_content.list.20.my_extension_pluginkey = USER_INT', $staticTypoScript);
250 }
251
252
253 /**
254 * @test
255 */
256 public function addingPluginWorksForMultipleControllerActionsWithNonCachableActionAsDefault() {
257 global $TYPO3_CONF_VARS;
258 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'] = '';
259 t3lib_extMgm::addExtbasePlugin(
260 'pluginkey',
261 'my_extension',
262 array(
263 'FirstController' => 'index,show,new,create,delete,edit,update',
264 'SecondController' => 'index,show,delete',
265 'ThirdController' => 'create'
266 ),
267 array(
268 'FirstController' => 'new,create,edit,update',
269 'SecondController' => 'delete',
270 'ThirdController' => 'create'
271 ),
272 array('SecondController' => 'delete')
273 );
274 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['cssstyledcontent/static/current/'];
275
276 $this->assertContains('
277 tt_content.list.20.my_extension_pluginkey = USER_INT
278 tt_content.list.20.my_extension_pluginkey {', $staticTypoScript);
279
280 $this->assertContains('
281 [globalString: GP = tx_myextension_pluginkey|controller = FirstController] && [globalString: GP = tx_myextension_pluginkey|action = /index|show|delete/]
282 tt_content.list.20.my_extension_pluginkey = USER', $staticTypoScript);
283
284 $this->assertContains('
285 [globalString: GP = tx_myextension_pluginkey|controller = SecondController] && [globalString: GP = tx_myextension_pluginkey|action = /index|show/]
286 tt_content.list.20.my_extension_pluginkey = USER', $staticTypoScript);
287
288 $this->assertNotContains('[globalString: GP = tx_myextension_pluginkey|controller = ThirdController]', $staticTypoScript);
289 }
290
291
292 }
293
294 ?>