[!!!][~TASK] Extbase (Utility): Moved configureDispatcher() and registerPlugin()...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / MVC / Web / RequestBuilder_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 class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_MVC_Web_RequestBuilder_testcase extends Tx_Extbase_Base_testcase {
29
30 /**
31 * @var array
32 */
33 protected $getBackup = array();
34
35 /**
36 * @var array
37 */
38 protected $postBackup = array();
39
40 public function __construct() {
41 require_once(t3lib_extMgm::extPath('extbase', 'Classes/MVC/Web/RequestBuilder.php'));
42 }
43
44 public function setUp() {
45 $this->configuration = array(
46 'userFunc' => 'Tx_Extbase_Dispatcher->dispatch',
47 'pluginName' => 'pi1',
48 'extensionName' => 'MyExtension',
49 'controller' => 'TheFirstController',
50 'action' => 'show',
51 'switchableControllerActions.' => array(
52 '1.' => array(
53 'controller' => 'TheFirstController',
54 'actions' => ',show,index, ,new,create,delete,edit,update,setup,test'
55 ),
56 '2.' => array(
57 'controller' => 'TheSecondController',
58 'actions' => 'show, index'
59 ),
60 '3.' => array(
61 'controller' => 'TheThirdController',
62 'actions' => 'delete,create'
63 )
64 )
65 );
66 $this->builder = new Tx_Extbase_MVC_Web_RequestBuilder;
67 $this->getBackup = $_GET;
68 $this->postBackup = $_POST;
69 }
70
71 public function tearDown() {
72 $_GET = $this->getBackup;
73 $_POST = $this->postBackup;
74 }
75
76 /**
77 * @test
78 */
79 public function buildReturnsAWebRequestObject() {
80 $this->builder->initialize($this->configuration);
81 $request = $this->builder->build();
82 $this->assertEquals('Tx_Extbase_MVC_Web_Request', get_class($request));
83 $this->assertEquals('pi1', $request->getPluginName());
84 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
85 $this->assertEquals('TheFirstController', $request->getControllerName());
86 $this->assertEquals('show', $request->getControllerActionName());
87 }
88
89 /**
90 * @test
91 */
92 public function buildWithoutConfigurationReturnsAWebRequestObjectWithDefaultSettings() {
93 $request = $this->builder->build();
94 $this->assertEquals('plugin', $request->getPluginName());
95 $this->assertEquals('Extbase', $request->getControllerExtensionName());
96 $this->assertEquals('Standard', $request->getControllerName());
97 $this->assertEquals('index', $request->getControllerActionName());
98 }
99
100 /**
101 * @test
102 */
103 public function buildWithMissingControllerConfigurationsReturnsAWebRequestObjectWithDefaultControllerSettings() {
104 $configuration = $this->configuration;
105 unset($configuration['controller']);
106 unset($configuration['action']);
107 unset($configuration['switchableControllerActions.']);
108 $this->builder->initialize($configuration);
109 $request = $this->builder->build();
110 $this->assertEquals('pi1', $request->getPluginName());
111 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
112 $this->assertEquals('Standard', $request->getControllerName());
113 $this->assertEquals('index', $request->getControllerActionName());
114 }
115
116 /**
117 * @test
118 */
119 public function buildWithMissingActionsReturnsAWebRequestObjectWithDefaultControllerSettings() {
120 $configuration = $this->configuration;
121 unset($configuration['controller']);
122 unset($configuration['action']);
123 $this->builder->initialize($configuration);
124 $request = $this->builder->build();
125 $this->assertEquals('pi1', $request->getPluginName());
126 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
127 $this->assertEquals('TheFirstController', $request->getControllerName());
128 $this->assertEquals('show', $request->getControllerActionName());
129 }
130
131 /**
132 * @test
133 */
134 public function buildSetsTheRequestURIInTheRequestObject() {
135 $this->builder->initialize($this->configuration);
136 $request = $this->builder->build();
137 $this->assertEquals(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), $request->getRequestURI());
138 }
139
140 /**
141 * @test
142 */
143 public function buildSetsParametersFromGetAndPostVariables() {
144 $builder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_RequestBuilder'), array('dummy'));
145 $builder->_set('extensionName', 'someExtensionName');
146 $builder->_set('pluginName', 'somePluginName');
147
148 $_GET = array(
149 'tx_someotherextensionname_somepluginname' => array(
150 'foo' => 'bar'
151 ),
152 'tx_someextensionname_somepluginname' => array(
153 'parameter1' => 'valueGetsOverwritten',
154 'parameter2' => array(
155 'parameter3' => 'value3'
156 )
157 )
158 );
159 $_POST = array(
160 'tx_someextensionname_someotherpluginname' => array(
161 'foo' => 'bar'
162 ),
163 'tx_someextensionname_somepluginname' => array(
164 'parameter1' => 'value1',
165 'parameter2' => array(
166 'parameter4' => 'value4'
167 )
168 )
169 );
170
171 $request = $builder->build();
172 $expectedResult = array(
173 'parameter1' => 'value1',
174 'parameter2' => array(
175 'parameter3' => 'value3',
176 'parameter4' => 'value4',
177 ),
178 );
179 $actualResult = $request->getArguments();
180 $this->assertEquals($expectedResult, $actualResult);
181 }
182
183 }
184 ?>