Extbase:
[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 * @test
75 * @see Tx_Extbase_Utility_Plugin::registerPlugin
76 */
77 public function addingTsWorksForASingleControllerAction() {
78 global $TYPO3_CONF_VARS;
79 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
80 Tx_Extbase_Utility_Plugin::registerPlugin(
81 'MyExtension',
82 'Pi1',
83 'My Plugin Title',
84 array(
85 'FirstController' => 'index'
86 )
87 );
88 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
89
90 $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
91 $this->assertContains('
92 pluginName = Pi1
93 extensionName = MyExtension
94 controller = FirstController
95 action = index', $staticTypoScript);
96 $this->assertNotContains('USER_INT', $staticTypoScript);
97 }
98
99 /**
100 * @test
101 * @see Tx_Extbase_Utility_Plugin::registerPlugin
102 */
103 public function addingPluginWithEmptyPluginNameResultsInAnError() {
104 $this->setExpectedException('InvalidArgumentException');
105 Tx_Extbase_Utility_Plugin::registerPlugin(
106 'MyExtension',
107 '',
108 'My Plugin Title',
109 array(
110 'FirstController' => 'index'
111 )
112 );
113 }
114
115 /**
116 * @test
117 * @see Tx_Extbase_Utility_Plugin::registerPlugin
118 */
119 public function addingPluginWithEmptyExtensionNameResultsInAnError() {
120 $this->setExpectedException('InvalidArgumentException');
121 Tx_Extbase_Utility_Plugin::registerPlugin(
122 '',
123 'Pi1',
124 'My Plugin Title',
125 array(
126 'FirstController' => 'index'
127 )
128 );
129 }
130
131 /**
132 * @test
133 * @see Tx_Extbase_Utility_Plugin::registerPlugin
134 */
135 public function addingPluginWithInvalidExtensionNameResultsInAnError() {
136 $this->setExpectedException('InvalidArgumentException');
137 Tx_Extbase_Utility_Plugin::registerPlugin(
138 'my_extension',
139 'Pi1',
140 'My Plugin Title',
141 array(
142 'FirstController' => 'index'
143 )
144 );
145 }
146
147 /**
148 * @test
149 * @see Tx_Extbase_Utility_Plugin::registerPlugin
150 */
151 public function addingPluginRespectsDefaultActionAsANonCachableAction() {
152 global $TYPO3_CONF_VARS;
153 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
154 Tx_Extbase_Utility_Plugin::registerPlugin(
155 'MyExtension',
156 'Pi1',
157 'My Plugin Title',
158 array(
159 'FirstController' => 'index,show,new,create,delete,edit,update'
160 ),
161 array(
162 'FirstController' => 'index,show'
163 )
164 );
165 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
166
167 $this->assertContains('
168 tt_content.list.20.myextension_pi1 = USER_INT
169 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
170 $this->assertContains('
171 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /new|create|delete|edit|update/]
172 tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
173 }
174
175 /**
176 * @test
177 * @see Tx_Extbase_Utility_Plugin::registerPlugin
178 */
179 public function addingPluginRespectsNonDefaultActionAsANonCachableAction() {
180 global $TYPO3_CONF_VARS;
181 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
182 Tx_Extbase_Utility_Plugin::registerPlugin(
183 'MyExtension',
184 'Pi1',
185 'My Plugin Title',
186 array(
187 'FirstController' => 'index,show,new,create,delete,edit,update'
188 ),
189 array(
190 'FirstController' => 'show,new'
191 )
192 );
193 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
194
195 $this->assertContains('
196 tt_content.list.20.myextension_pi1 = USER
197 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
198 $this->assertContains('
199 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /show|new/]
200 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
201 }
202
203 /**
204 * @test
205 * @see Tx_Extbase_Utility_Plugin::registerPlugin
206 */
207 public function addingPluginWorksForMultipleControllerActionsWithCachableActionAsDefault() {
208 global $TYPO3_CONF_VARS;
209 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
210 Tx_Extbase_Utility_Plugin::registerPlugin(
211 'MyExtension',
212 'Pi1',
213 'My Plugin Title',
214 array(
215 'FirstController' => 'index,show,new,create,delete,edit,update',
216 'SecondController' => 'index,show,delete',
217 'ThirdController' => 'create'
218 ),
219 array(
220 'FirstController' => 'new,create,edit,update',
221 'SecondController' => 'delete',
222 'ThirdController' => 'create'
223 ),
224 array('SecondController' => 'show')
225 );
226 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
227
228 $this->assertContains('
229 tt_content.list.20.myextension_pi1 = USER
230 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
231
232 $this->assertContains('
233 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /new|create|edit|update/]
234 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
235
236 $this->assertContains('
237 [globalString: GP = tx_myextension_pi1|controller = SecondController] && [globalString: GP = tx_myextension_pi1|action = /delete/]
238 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
239
240 $this->assertContains('
241 [globalString: GP = tx_myextension_pi1|controller = ThirdController] && [globalString: GP = tx_myextension_pi1|action = /create/]
242 tt_content.list.20.myextension_pi1 = USER_INT', $staticTypoScript);
243 }
244
245
246 /**
247 * @test
248 * @see Tx_Extbase_Utility_Plugin::registerPlugin
249 */
250 public function addingPluginWorksForMultipleControllerActionsWithNonCachableActionAsDefault() {
251 global $TYPO3_CONF_VARS;
252 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
253 Tx_Extbase_Utility_Plugin::registerPlugin(
254 'MyExtension',
255 'Pi1',
256 'My Plugin Title',
257 array(
258 'FirstController' => 'index,show,new,create,delete,edit,update',
259 'SecondController' => 'index,show,delete',
260 'ThirdController' => 'create'
261 ),
262 array(
263 'FirstController' => 'index,new,create,edit,update',
264 'SecondController' => 'delete',
265 'ThirdController' => 'create'
266 )
267 );
268 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
269
270 $this->assertContains('
271 tt_content.list.20.myextension_pi1 = USER_INT
272 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
273
274 $this->assertContains('
275 [globalString: GP = tx_myextension_pi1|controller = FirstController] && [globalString: GP = tx_myextension_pi1|action = /show|delete/]
276 tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
277
278 $this->assertContains('
279 [globalString: GP = tx_myextension_pi1|controller = SecondController] && [globalString: GP = tx_myextension_pi1|action = /index|show/]
280 tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
281
282 $this->assertNotContains('[globalString: GP = tx_myextension_pi1|controller = ThirdController]', $staticTypoScript);
283 }
284
285 /**
286 * @test
287 * @see Tx_Extbase_Utility_Plugin::registerPlugin
288 */
289 public function addingPluginWorksForMultipleControllerActionsWithNonCachableActionAsDefaultAndOnlyNonCachableActions() {
290 global $TYPO3_CONF_VARS;
291 $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
292 Tx_Extbase_Utility_Plugin::registerPlugin(
293 'MyExtension',
294 'Pi1',
295 'My Plugin Title',
296 array(
297 'FirstController' => 'index,show,new,create,delete,edit,update',
298 'SecondController' => 'index,show,delete',
299 'ThirdController' => 'create'
300 ),
301 array(
302 'FirstController' => 'index,show,new,create,delete,edit,update',
303 'SecondController' => 'index,show,delete',
304 'ThirdController' => 'create'
305 )
306 );
307 $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
308
309 $this->assertContains('
310 tt_content.list.20.myextension_pi1 = USER_INT
311 tt_content.list.20.myextension_pi1 {', $staticTypoScript);
312
313 $this->assertNotContains('GP', $staticTypoScript);
314 }
315
316 // TODO switchableControllerActionsIsSupressedIfOnlyOneControllerActionIsGiven()
317 // TODO switchableControllerDingsIsGeneratedWithMultipleControllersEachHavingOnlyOneAction
318
319 }
320
321 ?>