3666e773336546bcb53181ad4942dea9062be647
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Utility / Plugin_testcase.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 /**
27 * Testcase for class Tx_Extbase_Utility_Plugin
28 *
29 * @package Extbase
30 * @subpackage extbase
31 */
32 class Tx_Extbase_Utility_Plugin_testcase extends tx_phpunit_testcase {
33
34 /**
35 * Contains backup of $TYPO3_CONF_VARS
36 * @var array
37 */
38 protected $typo3ConfVars = array();
39
40 public function setUp() {
41 global $TYPO3_CONF_VARS;
42 $this->typo3ConfVars = $TYPO3_CONF_VARS;
43 }
44
45 public function tearDown() {
46 global $TYPO3_CONF_VARS;
47 $TYPO3_CONF_VARS = $this->typo3ConfVars;
48 }
49
50 /**
51 * @test
52 * @see Tx_Extbase_Utility_Plugin::registerPlugin
53 */
54 public function addingTsWorksForMinimalisticSetup() {
55 global $TYPO3_CONF_VARS;
56 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
57 Tx_Extbase_Utility_Plugin::registerPlugin(
58 'MyExtension',
59 'Pi1',
60 'My Plugin Title',
61 array('Blog' => 'index')
62 );
63 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
64
65 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
66 $this->assertContains('
67 pluginName = Pi1
68 extensionName = MyExtension', $staticTypoScript);
69
70 $this->assertNotContains('USER_INT', $staticTypoScript);
71 }
72
73
74 /**
75 * @test
76 * @see Tx_Extbase_Utility_Plugin::registerPlugin
77 */
78 public function addingTsAddsEnablesCacheClearingByDefault() {
79 global $TYPO3_CONF_VARS;
80 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
81 Tx_Extbase_Utility_Plugin::registerPlugin(
82 'MyExtension',
83 'Pi1',
84 'My Plugin Title',
85 array('Blog' => 'index')
86 );
87 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
88
89 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
90 $this->assertContains('
91 enableAutomaticCacheClearing = 1', $staticTypoScript);
92 }
93
94 /**
95 * @test
96 * @see Tx_Extbase_Utility_Plugin::registerPlugin
97 */
98 public function addingTsWorksForASingleControllerAction() {
99 global $TYPO3_CONF_VARS;
100 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
101 Tx_Extbase_Utility_Plugin::registerPlugin(
102 'MyExtension',
103 'Pi1',
104 'My Plugin Title',
105 array(
106 'FirstController' => 'index'
107 )
108 );
109 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
110
111 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
112 $this->assertContains('
113 pluginName = Pi1
114 extensionName = MyExtension', $staticTypoScript);
115 $this->assertContains('
116 controller = FirstController
117 action = index', $staticTypoScript);
118 $this->assertNotContains('USER_INT', $staticTypoScript);
119 }
120
121 /**
122 * @test
123 * @see Tx_Extbase_Utility_Plugin::registerPlugin
124 */
125 public function addingPluginWithEmptyPluginNameResultsInAnError() {
126 $this->setExpectedException('InvalidArgumentException');
127 Tx_Extbase_Utility_Plugin::registerPlugin(
128 'MyExtension',
129 '',
130 'My Plugin Title',
131 array(
132 'FirstController' => 'index'
133 )
134 );
135 }
136
137 /**
138 * @test
139 * @see Tx_Extbase_Utility_Plugin::registerPlugin
140 */
141 public function addingPluginWithEmptyExtensionNameResultsInAnError() {
142 $this->setExpectedException('InvalidArgumentException');
143 Tx_Extbase_Utility_Plugin::registerPlugin(
144 '',
145 'Pi1',
146 'My Plugin Title',
147 array(
148 'FirstController' => 'index'
149 )
150 );
151 }
152
153 /**
154 * @test
155 * @see Tx_Extbase_Utility_Plugin::registerPlugin
156 */
157 public function addingPluginRespectsDefaultActionAsANonCachableAction() {
158 global $TYPO3_CONF_VARS;
159 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
160 Tx_Extbase_Utility_Plugin::registerPlugin(
161 'MyExtension',
162 'Pi1',
163 'My Plugin Title',
164 array(
165 'FirstController' => 'index,show,new,create,delete,edit,update'
166 ),
167 array(
168 'FirstController' => 'index,show'
169 )
170 );
171 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
172
173 $this->assertContains('
174 tt_content.list.20.myextension_pi1 = USER_INT
175 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
176 $this->assertContains('
177 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /new|create|delete|edit|update/]
178 tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
179 }
180
181 /**
182 * @test
183 * @see Tx_Extbase_Utility_Plugin::registerPlugin
184 */
185 public function addingPluginRespectsNonDefaultActionAsANonCachableAction() {
186 global $TYPO3_CONF_VARS;
187 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
188 Tx_Extbase_Utility_Plugin::registerPlugin(
189 'MyExtension',
190 'Pi1',
191 'My Plugin Title',
192 array(
193 'FirstController' => 'index,show,new,create,delete,edit,update'
194 ),
195 array(
196 'FirstController' => 'show,new'
197 )
198 );
199 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
200
201 $this->assertContains('
202 tt_content.list.20.myextension_pi1 = USER
203 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
204 $this->assertContains('
205 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /show|new/]
206 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
207 }
208
209 /**
210 * @test
211 * @see Tx_Extbase_Utility_Plugin::registerPlugin
212 */
213 public function addingPluginWorksForMultipleControllerActionsWithCachableActionAsDefault() {
214 global $TYPO3_CONF_VARS;
215 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
216 Tx_Extbase_Utility_Plugin::registerPlugin(
217 'MyExtension',
218 'Pi1',
219 'My Plugin Title',
220 array(
221 'FirstController' => 'index,show,new,create,delete,edit,update',
222 'SecondController' => 'index,show,delete',
223 'ThirdController' => 'create'
224 ),
225 array(
226 'FirstController' => 'new,create,edit,update',
227 'SecondController' => 'delete',
228 'ThirdController' => 'create'
229 ),
230 array('SecondController' => 'show')
231 );
232 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
233
234 $this->assertContains('
235 tt_content.list.20.myextension_pi1 = USER
236 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
237
238 $this->assertContains('
239 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /new|create|edit|update/]
240 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
241
242 $this->assertContains('
243 [globalString: GP = tx_myextension_pi1|controller = SecondController] && [globalString: GP = tx_myextension_pi1|action = /delete/]
244 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
245
246 $this->assertContains('
247 [globalString: GP = tx_myextension_pi1|controller = ThirdController] && [globalString: GP = tx_myextension_pi1|action = /create/]
248 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
249 }
250
251
252 /**
253 * @test
254 * @see Tx_Extbase_Utility_Plugin::registerPlugin
255 */
256 public function addingPluginWorksForMultipleControllerActionsWithNonCachableActionAsDefault() {
257 global $TYPO3_CONF_VARS;
258 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
259 Tx_Extbase_Utility_Plugin::registerPlugin(
260 'MyExtension',
261 'Pi1',
262 'My Plugin Title',
263 array(
264 'FirstController' => 'index,show,new,create,delete,edit,update',
265 'SecondController' => 'index,show,delete',
266 'ThirdController' => 'create'
267 ),
268 array(
269 'FirstController' => 'index,new,create,edit,update',
270 'SecondController' => 'delete',
271 'ThirdController' => 'create'
272 )
273 );
274 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
275
276 $this->assertContains('
277 tt_content.list.20.myextension_pi1 = USER_INT
278 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
279
280 $this->assertContains('
281 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /show|delete/]
282 tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
283
284 $this->assertContains('
285 [globalString: GP = tx_myextension_pi1|controller = SecondController] && [globalString: GP = tx_myextension_pi1|action = /index|show/]
286 tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
287
288 $this->assertNotContains('[globalString: GP = tx_myextension_pi1|controller = ThirdController]', $staticTypoScript);
289 }
290
291 /**
292 * @test
293 * @see Tx_Extbase_Utility_Plugin::registerPlugin
294 */
295 public function addingPluginWorksForMultipleControllerActionsWithNonCachableActionAsDefaultAndOnlyNonCachableActions() {
296 global $TYPO3_CONF_VARS;
297 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
298 Tx_Extbase_Utility_Plugin::registerPlugin(
299 'MyExtension',
300 'Pi1',
301 'My Plugin Title',
302 array(
303 'FirstController' => 'index,show,new,create,delete,edit,update',
304 'SecondController' => 'index,show,delete',
305 'ThirdController' => 'create'
306 ),
307 array(
308 'FirstController' => 'index,show,new,create,delete,edit,update',
309 'SecondController' => 'index,show,delete',
310 'ThirdController' => 'create'
311 )
312 );
313 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
314
315 $this->assertContains('
316 tt_content.list.20.myextension_pi1 = USER_INT
317 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
318
319 $this->assertNotContains('GP', $staticTypoScript);
320 }
321
322 // TODO switchableControllerActionsIsSupressedIfOnlyOneControllerActionIsGiven()
323 // TODO switchableControllerDingsIsGeneratedWithMultipleControllersEachHavingOnlyOneAction
324
325 }
326
327 ?>