TYPO3 CMS  TYPO3_6-2
RequestTest.php
Go to the documentation of this file.
1 <?php
3 
21 
27  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
28  $request->setArgument('someArgumentName', 'theValue');
29  $this->assertEquals('theValue', $request->getArgument('someArgumentName'));
30  }
31 
38  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
39  $request->setArgument(123, 'theValue');
40  }
41 
48  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
49  $request->setArgument('', 'theValue');
50  }
51 
58  $this->markTestSkipped('Differing behavior from FLOW3 because of backwards compatibility reasons.');
59  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
60  $request->setArgument('theKey', new \stdClass());
61  }
62 
68  $arguments = array('key1' => 'value1', 'key2' => 'value2');
69  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
70  $request->setArgument('someKey', 'shouldBeOverridden');
71  $request->setArguments($arguments);
72  $actualResult = $request->getArguments();
73  $this->assertEquals($arguments, $actualResult);
74  }
75 
81  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setArgument'));
82  $request->expects($this->at(0))->method('setArgument')->with('key1', 'value1');
83  $request->expects($this->at(1))->method('setArgument')->with('key2', 'value2');
84  $request->setArguments(array('key1' => 'value1', 'key2' => 'value2'));
85  }
86 
91  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setControllerExtensionName'));
92  $request->expects($this->any())->method('setControllerExtensionName')->with('MyExtension');
93  $request->setArgument('@extension', 'MyExtension');
94  $this->assertFalse($request->hasArgument('@extension'));
95  }
96 
101  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setControllerSubpackageKey'));
102  $request->expects($this->any())->method('setControllerSubpackageKey')->with('MySubPackage');
103  $request->setArgument('@subpackage', 'MySubPackage');
104  $this->assertFalse($request->hasArgument('@subpackage'));
105  }
106 
111  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setControllerName'));
112  $request->expects($this->any())->method('setControllerName')->with('MyController');
113  $request->setArgument('@controller', 'MyController');
114  $this->assertFalse($request->hasArgument('@controller'));
115  }
116 
121  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setControllerActionName'));
122  $request->expects($this->any())->method('setControllerActionName')->with('foo');
123  $request->setArgument('@action', 'foo');
124  $this->assertFalse($request->hasArgument('@action'));
125  }
126 
131  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setFormat'));
132  $request->expects($this->any())->method('setFormat')->with('txt');
133  $request->setArgument('@format', 'txt');
134  $this->assertFalse($request->hasArgument('@format'));
135  }
136 
141  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('setFormat'));
142  $request->expects($this->any())->method('setVendor')->with('VENDOR');
143  $request->setArgument('@vendor', 'VENDOR');
144  $this->assertFalse($request->hasArgument('@vendor'));
145  }
146 
151  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
152  $request->setArgument('__referrer', 'foo');
153  $this->assertFalse($request->hasArgument('__referrer'));
154  }
155 
160  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
161  $request->setArgument('__referrer', 'foo');
162  $this->assertSame('foo', $request->getInternalArgument('__referrer'));
163  }
164 
169  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
170  $this->assertNull($request->getInternalArgument('__nonExistingInternalArgument'));
171  }
172 
178  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
179  $object = new \stdClass();
180  $request->setArgument('__theKey', $object);
181  $this->assertSame($object, $request->getInternalArgument('__theKey'));
182  }
183 
189  $arguments = array(
190  'firstArgument' => 'firstValue',
191  'dænishÅrgument' => 'görman välju',
192  '3a' => '3v'
193  );
194  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
195  $request->setArguments($arguments);
196  $this->assertEquals($arguments, $request->getArguments());
197  }
198 
204  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
205  $request->setArgument('existingArgument', 'theValue');
206  $this->assertTrue($request->hasArgument('existingArgument'));
207  $this->assertFalse($request->hasArgument('notExistingArgument'));
208  }
209 
215  $request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('getControllerObjectName'), array(), '', FALSE);
216  $request->expects($this->once())->method('getControllerObjectName')->will($this->returnValue(''));
217  $request->setControllerActionName('theAction');
218  $this->assertEquals('theAction', $request->getControllerActionName());
219  }
220 
226  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
227  $request->setFormat('html');
228  $this->assertEquals('html', $request->getFormat());
229  }
230 
235  $this->markTestSkipped('Different behavior from FLOW3 because of backwards compatibility.');
236  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
237  $request->setFormat('hTmL');
238  $this->assertEquals('html', $request->getFormat());
239  }
240 
246  $request = new \TYPO3\CMS\Extbase\Mvc\Request();
247  $this->assertFalse($request->isDispatched());
248  $request->setDispatched(TRUE);
249  $this->assertTrue($request->isDispatched());
250  }
251 
258  return array(
259  'Vendor TYPO3\CMS, extension, controller given' => array(
260  array(
261  'vendorName' => 'TYPO3\\CMS',
262  'extensionName' => 'Ext',
263  'subpackageKey' => '',
264  'controllerName' => 'Foo',
265  ),
266  'TYPO3\\CMS\\Ext\\Controller\\FooController',
267  ),
268  'Vendor TYPO3\CMS, extension, subpackage, controlle given' => array(
269  array(
270  'vendorName' => 'TYPO3\\CMS',
271  'extensionName' => 'Fluid',
272  'subpackageKey' => 'ViewHelpers\\Widget',
273  'controllerName' => 'Paginate',
274  ),
275  'TYPO3\\CMS\\Fluid\\ViewHelpers\\Widget\\Controller\\PaginateController',
276  ),
277  'Vendor VENDOR, extension, controller given' => array(
278  array(
279  'vendorName' => 'VENDOR',
280  'extensionName' => 'Ext',
281  'subpackageKey' => '',
282  'controllerName' => 'Foo',
283  ),
284  'VENDOR\\Ext\\Controller\\FooController',
285  ),
286  'Vendor VENDOR, extension subpackage, controller given' => array(
287  array(
288  'vendorName' => 'VENDOR',
289  'extensionName' => 'Ext',
290  'subpackageKey' => 'ViewHelpers\\Widget',
291  'controllerName' => 'Foo',
292  ),
293  'VENDOR\\Ext\\ViewHelpers\\Widget\\Controller\\FooController',
294  ),
295  'No vendor, extension, controller given' => array(
296  array(
297  'vendorName' => NULL,
298  'extensionName' => 'Ext',
299  'subpackageKey' => '',
300  'controllerName' => 'Foo',
301  ),
302  'Tx_Ext_Controller_FooController',
303  ),
304  'No vendor, extension, subpackage, controller given' => array(
305  array(
306  'vendorName' => NULL,
307  'extensionName' => 'Fluid',
308  'subpackageKey' => 'ViewHelpers_Widget',
309  'controllerName' => 'Paginate',
310  ),
311  'Tx_Fluid_ViewHelpers_Widget_Controller_PaginateController',
312  ),
313  );
314  }
315 
323  public function getControllerObjectNameResolvesControllerObjectNameCorrectly($controllerArguments, $controllerObjectName) {
325  $request = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('dummy'));
326  $request->_set('controllerVendorName', $controllerArguments['vendorName']);
327  $request->_set('controllerExtensionName', $controllerArguments['extensionName']);
328  $request->_set('controllerSubpackageKey', $controllerArguments['subpackageKey']);
329  $request->_set('controllerName', $controllerArguments['controllerName']);
330 
331  $this->assertEquals($controllerObjectName, $request->getControllerObjectName());
332  }
333 
341  public function setControllerObjectNameResolvesControllerObjectNameArgumentsCorrectly($controllerArguments, $controllerObjectName) {
343  $request = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array('dummy'));
344  $request->setControllerObjectName($controllerObjectName);
345 
346  $actualControllerArguments = array(
347  'vendorName' => $request->_get('controllerVendorName'),
348  'extensionName' => $request->_get('controllerExtensionName'),
349  'subpackageKey' => $request->_get('controllerSubpackageKey'),
350  'controllerName' => $request->_get('controllerName'),
351  );
352 
353  $this->assertSame($controllerArguments, $actualControllerArguments);
354  }
355 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)