Raised DBAL version from 1.1.5 to 1.1.6
[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_BaseTestCase {
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['action']);
122 $this->builder->initialize($configuration);
123 $request = $this->builder->build();
124 $this->assertEquals('pi1', $request->getPluginName());
125 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
126 $this->assertEquals('TheFirstController', $request->getControllerName());
127 $this->assertEquals('index', $request->getControllerActionName());
128 }
129
130 /**
131 * @test
132 */
133 public function buildSetsTheRequestURIInTheRequestObject() {
134 $this->builder->initialize($this->configuration);
135 $request = $this->builder->build();
136 $this->assertEquals(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), $request->getRequestURI());
137 }
138
139 /**
140 * @test
141 */
142 public function buildSetsParametersFromGetAndPostVariables() {
143 $builder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_RequestBuilder'), array('dummy'));
144 $builder->_set('extensionName', 'someExtensionName');
145 $builder->_set('pluginName', 'somePluginName');
146
147 $_GET = array(
148 'tx_someotherextensionname_somepluginname' => array(
149 'foo' => 'bar'
150 ),
151 'tx_someextensionname_somepluginname' => array(
152 'parameter1' => 'valueGetsOverwritten',
153 'parameter2' => array(
154 'parameter3' => 'value3'
155 )
156 )
157 );
158 $_POST = array(
159 'tx_someextensionname_someotherpluginname' => array(
160 'foo' => 'bar'
161 ),
162 'tx_someextensionname_somepluginname' => array(
163 'parameter1' => 'value1',
164 'parameter2' => array(
165 'parameter4' => 'value4'
166 )
167 )
168 );
169
170 $request = $builder->build();
171 $expectedResult = array(
172 'parameter1' => 'value1',
173 'parameter2' => array(
174 'parameter3' => 'value3',
175 'parameter4' => 'value4',
176 ),
177 );
178 $actualResult = $request->getArguments();
179 $this->assertEquals($expectedResult, $actualResult);
180 }
181
182 }
183 ?>