TYPO3 CMS  TYPO3_6-2
UriBuilderTest.php
Go to the documentation of this file.
1 <?php
3 
21 
26 
30  protected $mockContentObject;
31 
35  protected $mockRequest;
36 
41 
45  protected $uriBuilder;
46 
47  public function setUp() {
48  $GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
49  $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
50  $this->mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
51  $this->mockExtensionService = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\ExtensionService');
52  $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
53  $this->uriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('build'));
54  $this->uriBuilder->setRequest($this->mockRequest);
55  $this->uriBuilder->_set('contentObject', $this->mockContentObject);
56  $this->uriBuilder->_set('configurationManager', $this->mockConfigurationManager);
57  $this->uriBuilder->_set('extensionService', $this->mockExtensionService);
58  $this->uriBuilder->_set('environmentService', $this->getMock('TYPO3\\CMS\\Extbase\\Service\\EnvironmentService'));
59  // Mocking backend user is required for backend URI generation as BackendUtility::getModuleUrl() is called
60  $backendUserMock = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
61  $backendUserMock->expects($this->any())->method('check')->will($this->returnValue(TRUE));
62  $GLOBALS['BE_USER'] = $backendUserMock;
63  }
64 
68  public function settersAndGettersWorkAsExpected() {
69  $this->uriBuilder->reset()->setArguments(array('test' => 'arguments'))->setSection('testSection')->setFormat('testFormat')->setCreateAbsoluteUri(TRUE)->setAbsoluteUriScheme('https')->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))->setAddQueryStringMethod('GET,POST')->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(TRUE)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(TRUE)->setUseCacheHash(FALSE);
70  $this->assertEquals(array('test' => 'arguments'), $this->uriBuilder->getArguments());
71  $this->assertEquals('testSection', $this->uriBuilder->getSection());
72  $this->assertEquals('testFormat', $this->uriBuilder->getFormat());
73  $this->assertEquals(TRUE, $this->uriBuilder->getCreateAbsoluteUri());
74  $this->assertEquals('https', $this->uriBuilder->getAbsoluteUriScheme());
75  $this->assertEquals(TRUE, $this->uriBuilder->getAddQueryString());
76  $this->assertEquals(array('test' => 'addQueryStringExcludeArguments'), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
77  $this->assertEquals('GET,POST', $this->uriBuilder->getAddQueryStringMethod());
78  $this->assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix());
79  $this->assertEquals(TRUE, $this->uriBuilder->getLinkAccessRestrictedPages());
80  $this->assertEquals(123, $this->uriBuilder->getTargetPageUid());
81  $this->assertEquals(321, $this->uriBuilder->getTargetPageType());
82  $this->assertEquals(TRUE, $this->uriBuilder->getNoCache());
83  $this->assertEquals(FALSE, $this->uriBuilder->getUseCacheHash());
84  }
85 
90  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
91  $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'bar', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'));
92  $GLOBALS['TSFE'] = NULL;
93  $this->uriBuilder->uriFor(NULL, array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')), 'SomeController', 'SomeExtension', 'SomePlugin');
94  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
95  }
96 
101  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
102  $arguments = array('tx_someextension_someplugin' => array('foo' => 'bar'), 'additionalParam' => 'additionalValue');
103  $controllerArguments = array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'));
104  $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'), 'additionalParam' => 'additionalValue');
105  $this->uriBuilder->setArguments($arguments);
106  $this->uriBuilder->uriFor(NULL, $controllerArguments, 'SomeController', 'SomeExtension', 'SomePlugin');
107  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
108  }
109 
114  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
115  $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeController'));
116  $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension', 'SomePlugin');
117  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
118  }
119 
124  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
125  $this->mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
126  $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeControllerFromRequest'));
127  $this->uriBuilder->uriFor(NULL, array(), NULL, 'SomeExtension', 'SomePlugin');
128  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
129  }
130 
135  $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_someextensionnamefromrequest_someplugin'));
136  $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
137  $expectedArguments = array('tx_someextensionnamefromrequest_someplugin' => array('controller' => 'SomeController'));
138  $this->uriBuilder->uriFor(NULL, array(), 'SomeController', NULL, 'SomePlugin');
139  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
140  }
141 
146  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_somepluginnamefromrequest'));
147  $this->mockRequest->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
148  $expectedArguments = array('tx_someextension_somepluginnamefromrequest' => array('controller' => 'SomeController'));
149  $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension');
150  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
151  }
152 
157  $this->mockExtensionService->expects($this->any())->method('isActionCacheable')->will($this->returnValue(FALSE));
158  $this->uriBuilder->uriFor('someNonCacheableAction', array(), 'SomeController', 'SomeExtension');
159  $this->assertTrue($this->uriBuilder->getUseCacheHash());
160  }
161 
166  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
167  $_POST = array();
168  $_POST['foo2'] = 'bar2';
169  $this->uriBuilder->setAddQueryString(TRUE);
170  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
171  $expectedResult = 'mod.php?M=moduleKey&moduleToken=dummyToken&id=pageId&foo=bar&foo2=bar2';
172  $actualResult = $this->uriBuilder->buildBackendUri();
173  $this->assertEquals($expectedResult, $actualResult);
174  }
175 
180  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
181  $_POST = array();
182  $_POST['foo2'] = 'bar2';
183  $this->uriBuilder->setAddQueryString(TRUE);
184  $this->uriBuilder->setAddQueryStringMethod(NULL);
185  $expectedResult = 'mod.php?M=moduleKey&moduleToken=dummyToken&id=pageId&foo=bar';
186  $actualResult = $this->uriBuilder->buildBackendUri();
187  $this->assertEquals($expectedResult, $actualResult);
188  }
189 
194  return array(
195  'Arguments to be excluded in the beginning' => array(
196  array(
197  'M' => 'moduleKey',
198  'id' => 'pageId',
199  'foo' => 'bar'
200  ),
201  array(
202  'foo2' => 'bar2'
203  ),
204  array(
205  'M',
206  'id'
207  ),
208  'mod.php?moduleToken=dummyToken&foo=bar&foo2=bar2'
209  ),
210  'Arguments to be excluded in the end' => array(
211  array(
212  'foo' => 'bar',
213  'id' => 'pageId',
214  'M' => 'moduleKey'
215  ),
216  array(
217  'foo2' => 'bar2'
218  ),
219  array(
220  'M',
221  'id'
222  ),
223  'mod.php?moduleToken=dummyToken&foo=bar&foo2=bar2'
224  ),
225  'Arguments in nested array to be excluded' => array(
226  array(
227  'tx_foo' => array(
228  'bar' => 'baz'
229  ),
230  'id' => 'pageId',
231  'M' => 'moduleKey'
232  ),
233  array(
234  'foo2' => 'bar2'
235  ),
236  array(
237  'id',
238  'tx_foo[bar]'
239  ),
240  'mod.php?M=moduleKey&moduleToken=dummyToken&foo2=bar2'
241  ),
242  'Arguments in multidimensional array to be excluded' => array(
243  array(
244  'tx_foo' => array(
245  'bar' => array(
246  'baz' => 'bay'
247  )
248  ),
249  'id' => 'pageId',
250  'M' => 'moduleKey'
251  ),
252  array(
253  'foo2' => 'bar2'
254  ),
255  array(
256  'id',
257  'tx_foo[bar][baz]'
258  ),
259  'mod.php?M=moduleKey&moduleToken=dummyToken&foo2=bar2'
260  ),
261  );
262  }
263 
268  public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet(array $parameters, array $postArguments, array $excluded, $expected) {
270  $_POST = $postArguments;
271  $this->uriBuilder->setAddQueryString(TRUE);
272  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
273  $this->uriBuilder->setArgumentsToBeExcludedFromQueryString($excluded);
274  $actualResult = $this->uriBuilder->buildBackendUri();
275  $this->assertEquals($expected, $actualResult);
276  }
277 
282  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
283  $expectedResult = 'mod.php?M=moduleKey&moduleToken=dummyToken&id=pageId';
284  $actualResult = $this->uriBuilder->buildBackendUri();
285  $this->assertEquals($expectedResult, $actualResult);
286  }
287 
292  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
293  $this->uriBuilder->setArguments(array('M' => 'overwrittenModuleKey', 'somePrefix' => array('bar' => 'baz')));
294  $expectedResult = 'mod.php?M=overwrittenModuleKey&moduleToken=dummyToken&id=pageId&somePrefix%5Bbar%5D=baz';
295  $actualResult = $this->uriBuilder->buildBackendUri();
296  $this->assertEquals($expectedResult, $actualResult);
297  }
298 
303  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey'));
304  $mockDomainObject = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity', array('dummy'));
305  $mockDomainObject->_set('uid', '123');
306  $this->uriBuilder->setArguments(array('somePrefix' => array('someDomainObject' => $mockDomainObject)));
307  $expectedResult = 'mod.php?M=moduleKey&moduleToken=dummyToken&somePrefix%5BsomeDomainObject%5D=123';
308  $actualResult = $this->uriBuilder->buildBackendUri();
309  $this->assertEquals($expectedResult, $actualResult);
310  }
311 
315  public function buildBackendUriRespectsSection() {
316  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey'));
317  $this->uriBuilder->setSection('someSection');
318  $expectedResult = 'mod.php?M=moduleKey&moduleToken=dummyToken#someSection';
319  $actualResult = $this->uriBuilder->buildBackendUri();
320  $this->assertEquals($expectedResult, $actualResult);
321  }
322 
327  \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey'));
328  $this->mockRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue('http://baseuri/' . TYPO3_mainDir));
329  $this->uriBuilder->setCreateAbsoluteUri(TRUE);
330  $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'mod.php?M=moduleKey&moduleToken=dummyToken';
331  $actualResult = $this->uriBuilder->buildBackendUri();
332  $this->assertSame($expectedResult, $actualResult);
333  }
334 
339  $_POST = array(
340  'key1' => 'POST1',
341  'key2' => 'POST2',
342  'key3' => array(
343  'key31' => 'POST31',
344  'key32' => 'POST32',
345  'key33' => array(
346  'key331' => 'POST331',
347  'key332' => 'POST332',
348  )
349  ),
350  );
351  $_GET = array(
352  'key2' => 'GET2',
353  'key3' => array(
354  'key32' => 'GET32',
355  'key33' => array(
356  'key331' => 'GET331',
357  )
358  )
359  );
360  $this->uriBuilder->setAddQueryString(TRUE);
361  $this->uriBuilder->setAddQueryStringMethod('POST,GET');
362  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('mod.php?moduleToken=dummyToken&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
363  $actualResult = $this->uriBuilder->buildBackendUri();
364  $this->assertEquals($expectedResult, $actualResult);
365  }
366 
371  $_GET = array(
372  'key1' => 'GET1',
373  'key2' => 'GET2',
374  'key3' => array(
375  'key31' => 'GET31',
376  'key32' => 'GET32',
377  'key33' => array(
378  'key331' => 'GET331',
379  'key332' => 'GET332',
380  )
381  ),
382  );
383  $_POST = array(
384  'key2' => 'POST2',
385  'key3' => array(
386  'key32' => 'POST32',
387  'key33' => array(
388  'key331' => 'POST331',
389  )
390  )
391  );
392  $this->uriBuilder->setAddQueryString(TRUE);
393  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
394  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('mod.php?moduleToken=dummyToken&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
395  $actualResult = $this->uriBuilder->buildBackendUri();
396  $this->assertEquals($expectedResult, $actualResult);
397  }
398 
405  private function rawUrlEncodeSquareBracketsInUrl($string) {
406  return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
407  }
408 
412  public function buildFrontendUriCreatesTypoLink() {
414  $uriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('buildTypolinkConfiguration'));
415  $uriBuilder->_set('contentObject', $this->mockContentObject);
416  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('someTypoLinkConfiguration')));
417  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('someTypoLinkConfiguration'));
418  $uriBuilder->buildFrontendUri();
419  }
420 
425  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
426  $expectedResult = 'relative/uri';
427  $actualResult = $this->uriBuilder->buildFrontendUri();
428  $this->assertSame($expectedResult, $actualResult);
429  }
430 
435  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
436  $expectedResult = '/relative/uri';
437  $actualResult = $this->uriBuilder->buildFrontendUri();
438  $this->assertSame($expectedResult, $actualResult);
439  }
440 
444  public function buildFrontendUriCreatesAbsoluteUrisIfSpecified() {
446  $uriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('buildTypolinkConfiguration'));
447  $uriBuilder->_set('contentObject', $this->mockContentObject);
448  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
449  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE))->will($this->returnValue('http://baseuri/relative/uri'));
450  $uriBuilder->setCreateAbsoluteUri(TRUE);
451  $expectedResult = 'http://baseuri/relative/uri';
452  $actualResult = $uriBuilder->buildFrontendUri();
453  $this->assertSame($expectedResult, $actualResult);
454  }
455 
459  public function buildFrontendUriSetsAbsoluteUriSchemeIfSpecified() {
461  $uriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('buildTypolinkConfiguration'));
462  $uriBuilder->_set('contentObject', $this->mockContentObject);
463  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
464  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE, 'forceAbsoluteUrl.' => array('scheme' => 'someScheme')))->will($this->returnValue('http://baseuri/relative/uri'));
465  $uriBuilder->setCreateAbsoluteUri(TRUE);
466  $uriBuilder->setAbsoluteUriScheme('someScheme');
467  $expectedResult = 'http://baseuri/relative/uri';
468  $actualResult = $uriBuilder->buildFrontendUri();
469  $this->assertSame($expectedResult, $actualResult);
470  }
471 
475  public function buildFrontendUriDoesNotSetAbsoluteUriSchemeIfCreateAbsoluteUriIsFalse() {
477  $uriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('buildTypolinkConfiguration'));
478  $uriBuilder->_set('contentObject', $this->mockContentObject);
479  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
480  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar'))->will($this->returnValue('http://baseuri/relative/uri'));
481  $uriBuilder->setCreateAbsoluteUri(FALSE);
482  $uriBuilder->setAbsoluteUriScheme('someScheme');
483  $expectedResult = 'http://baseuri/relative/uri';
484  $actualResult = $uriBuilder->buildFrontendUri();
485  $this->assertSame($expectedResult, $actualResult);
486  }
487 
492  $this->uriBuilder->setArguments(array('test' => 'arguments'))->setSection('testSection')->setFormat('someFormat')->setCreateAbsoluteUri(TRUE)->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))->setAddQueryStringMethod(NULL)->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(TRUE)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(TRUE)->setUseCacheHash(FALSE);
493  $this->uriBuilder->reset();
494  $this->assertEquals(array(), $this->uriBuilder->getArguments());
495  $this->assertEquals('', $this->uriBuilder->getSection());
496  $this->assertEquals('', $this->uriBuilder->getFormat());
497  $this->assertEquals(FALSE, $this->uriBuilder->getCreateAbsoluteUri());
498  $this->assertEquals(FALSE, $this->uriBuilder->getAddQueryString());
499  $this->assertEquals(array(), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
500  $this->assertEquals(NULL, $this->uriBuilder->getAddQueryStringMethod());
501  $this->assertEquals(NULL, $this->uriBuilder->getArgumentPrefix());
502  $this->assertEquals(FALSE, $this->uriBuilder->getLinkAccessRestrictedPages());
503  $this->assertEquals(NULL, $this->uriBuilder->getTargetPageUid());
504  $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
505  $this->assertEquals(FALSE, $this->uriBuilder->getNoCache());
506  $this->assertEquals(TRUE, $this->uriBuilder->getUseCacheHash());
507  }
508 
513  $GLOBALS['TSFE']->id = 123;
514  $this->uriBuilder->setTargetPageUid(321);
515  $expectedConfiguration = array('parameter' => 321, 'useCacheHash' => 1);
516  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
517  $this->assertEquals($expectedConfiguration, $actualConfiguration);
518  }
519 
524  $GLOBALS['TSFE']->id = 123;
525  $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1);
526  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
527  $this->assertEquals($expectedConfiguration, $actualConfiguration);
528  }
529 
534  $this->uriBuilder->setTargetPageUid(123);
535  $this->uriBuilder->setArguments(array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')));
536  $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&foo=bar&baz[extbase]=fluid');
537  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
538  $this->assertEquals($expectedConfiguration, $actualConfiguration);
539  }
540 
545  $this->uriBuilder->setTargetPageUid(123);
546  $this->uriBuilder->setAddQueryString(TRUE);
547  $expectedConfiguration = array('parameter' => 123, 'addQueryString' => 1, 'useCacheHash' => 1);
548  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
549  $this->assertEquals($expectedConfiguration, $actualConfiguration);
550  }
551 
556  $this->uriBuilder->setTargetPageUid(123);
557  $this->uriBuilder->setAddQueryString(TRUE);
558  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
559  $expectedConfiguration = array('parameter' => 123, 'addQueryString' => 1, 'addQueryString.' => array('method' => 'GET,POST'), 'useCacheHash' => 1);
560  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
561  $this->assertEquals($expectedConfiguration, $actualConfiguration);
562  }
563 
568  $mockDomainObject1 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity', array('dummy'));
569  $mockDomainObject1->_set('uid', '123');
570  $mockDomainObject2 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity', array('dummy'));
571  $mockDomainObject2->_set('uid', '321');
572  $this->uriBuilder->setTargetPageUid(123);
573  $this->uriBuilder->setArguments(array('someDomainObject' => $mockDomainObject1, 'baz' => array('someOtherDomainObject' => $mockDomainObject2)));
574  $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&someDomainObject=123&baz[someOtherDomainObject]=321');
575  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
576  $this->assertEquals($expectedConfiguration, $actualConfiguration);
577  }
578 
583  $this->uriBuilder->setTargetPageUid(123);
584  $this->uriBuilder->setFormat('txt');
585  $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
586 
587  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
588  $mockConfigurationManager->expects($this->any())->method('getConfiguration')
589  ->will($this->returnValue(array('view' => array('formatToPageTypeMapping' => array('txt' => 2)))));
590  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
591 
592  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
593  ->with('SomeExtensionNameFromRequest', 'txt')
594  ->will($this->returnValue(2));
595 
596  $expectedConfiguration = array('parameter' => '123,2', 'useCacheHash' => 1);
597  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
598  $this->assertEquals($expectedConfiguration, $actualConfiguration);
599  }
600 
605  $this->uriBuilder->setTargetPageUid(123);
606  $this->uriBuilder->setFormat('txt');
607 
608  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
609  $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue(array()));
610  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
611 
612  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
613  ->with(NULL, 'txt')
614  ->will($this->returnValue(0));
615 
616  $expectedConfiguration = array('parameter' => '123,0', 'useCacheHash' => 1);
617  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
618 
619  $this->assertEquals($expectedConfiguration, $actualConfiguration);
620  }
621 
626  $this->uriBuilder->setTargetPageUid(123);
627  $this->uriBuilder->setFormat('txt');
628 
629  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
630  $mockConfigurationManager->expects($this->any())->method('getConfiguration')
631  ->will($this->returnValue(array(array('view' => array('formatToPageTypeMapping' => array('pdf' => 2))))));
632  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
633 
634  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
635  ->with(NULL, 'txt')
636  ->will($this->returnValue(0));
637 
638  $expectedConfiguration = array('parameter' => '123,0', 'useCacheHash' => 1);
639  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
640 
641  $this->assertEquals($expectedConfiguration, $actualConfiguration);
642  }
643 
644 
649  $this->uriBuilder->setTargetPageUid(123);
650  $this->uriBuilder->setNoCache(TRUE);
651  $expectedConfiguration = array('parameter' => 123, 'no_cache' => 1);
652  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
653  $this->assertEquals($expectedConfiguration, $actualConfiguration);
654  }
655 
660  $this->uriBuilder->setTargetPageUid(123);
661  $this->uriBuilder->setUseCacheHash(FALSE);
662  $expectedConfiguration = array('parameter' => 123);
663  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
664  $this->assertEquals($expectedConfiguration, $actualConfiguration);
665  }
666 
671  $this->uriBuilder->setTargetPageUid(123);
672  $this->uriBuilder->setSection('SomeSection');
673  $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'section' => 'SomeSection');
674  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
675  $this->assertEquals($expectedConfiguration, $actualConfiguration);
676  }
677 
682  $this->uriBuilder->setTargetPageUid(123);
683  $this->uriBuilder->setLinkAccessRestrictedPages(TRUE);
684  $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'linkAccessRestrictedPages' => 1);
685  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
686  $this->assertEquals($expectedConfiguration, $actualConfiguration);
687  }
688 
693  $mockDomainObject1 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity', array('dummy'));
694  $mockDomainObject1->_set('uid', '123');
695  $mockDomainObject2 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity', array('dummy'));
696  $mockDomainObject2->_set('uid', '321');
697  $expectedResult = array('foo' => array('bar' => 'baz'), 'domainObject1' => '123', 'second' => array('domainObject2' => '321'));
698  $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', array('foo' => array('bar' => 'baz'), 'domainObject1' => $mockDomainObject1, 'second' => array('domainObject2' => $mockDomainObject2)));
699  $this->assertEquals($expectedResult, $actualResult);
700  }
701 
706  $className = $this->getUniqueId('FixturesObject_');
707  $classNameWithNS = __NAMESPACE__ . '\\' . $className;
708  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject { public $name; public $uid; }');
709  $mockValueObject = new $classNameWithNS();
710  $mockValueObject->name = 'foo';
711  $mockUriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('convertTransientObjectToArray'));
712  $mockUriBuilder->expects($this->once())->method('convertTransientObjectToArray')->will($this->returnValue(array('foo' => 'bar')));
713  $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockValueObject));
714  $expectedResult = array('object' => array('foo' => 'bar'));
715  $this->assertEquals($expectedResult, $actualResult);
716  }
717 
723  $className = $this->getUniqueId('FixturesObject_');
724  $classNameWithNS = __NAMESPACE__ . '\\' . $className;
725  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity { public $name; public $uid; }');
726  $mockEntity = new $classNameWithNS();
727  $mockEntity->name = 'foo';
728  $mockUriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('dummy'));
729  $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockEntity));
730  }
731 
736  $className = $this->getUniqueId('FixturesObject_');
737  $classNameWithNS = __NAMESPACE__ . '\\' . $className;
738  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject { public $name; public $uid; }');
739  $mockValueObject = new $classNameWithNS();
740  $mockValueObject->name = 'foo';
741  $mockUriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('dummy'));
742  $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
743  $expectedResult = array('name' => 'foo', 'uid' => NULL, 'pid' => NULL);
744  $this->assertEquals($expectedResult, $actualResult);
745  }
746 
751  $className = $this->getUniqueId('FixturesObject_');
752  $classNameWithNS = __NAMESPACE__ . '\\' . $className;
753  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject { public $name; public $uid; }');
754  $mockInnerValueObject2 = new $classNameWithNS();
755  $mockInnerValueObject2->name = 'foo';
756  $mockInnerValueObject2->uid = 99;
757  $className = $this->getUniqueId('FixturesObject_');
758  $classNameWithNS = __NAMESPACE__ . '\\' . $className;
759  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject { public $object; public $uid; }');
760  $mockInnerValueObject1 = new $classNameWithNS();
761  $mockInnerValueObject1->object = $mockInnerValueObject2;
762  $className = $this->getUniqueId('FixturesObject_');
763  $classNameWithNS = __NAMESPACE__ . '\\' . $className;
764  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject { public $object; public $uid; }');
765  $mockValueObject = new $classNameWithNS();
766  $mockValueObject->object = $mockInnerValueObject1;
767  $mockUriBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder', array('dummy'));
768  $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
769  $expectedResult = array(
770  'object' => array(
771  'object' => 99,
772  'uid' => NULL,
773  'pid' => NULL
774  ),
775  'uid' => NULL,
776  'pid' => NULL
777  );
778  $this->assertEquals($expectedResult, $actualResult);
779  }
780 
785  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
786  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'SomeController')->will($this->returnValue('defaultAction'));
787  $arguments = array('controller' => 'SomeController', 'action' => 'someAction', 'foo' => 'bar');
788  $extensionName = 'ExtensionName';
789  $pluginName = 'PluginName';
790  $expectedResult = array('controller' => 'SomeController', 'action' => 'someAction', 'foo' => 'bar');
791  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
792  $this->assertEquals($expectedResult, $actualResult);
793  }
794 
799  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
800  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
801  $arguments = array('controller' => 'DefaultController', 'action' => 'someAction', 'foo' => 'bar');
802  $extensionName = 'ExtensionName';
803  $pluginName = 'PluginName';
804  $expectedResult = array('action' => 'someAction', 'foo' => 'bar');
805  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
806  $this->assertEquals($expectedResult, $actualResult);
807  }
808 
813  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
814  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'SomeController')->will($this->returnValue('defaultAction'));
815  $arguments = array('controller' => 'SomeController', 'action' => 'defaultAction', 'foo' => 'bar');
816  $extensionName = 'ExtensionName';
817  $pluginName = 'PluginName';
818  $expectedResult = array('controller' => 'SomeController', 'foo' => 'bar');
819  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
820  $this->assertEquals($expectedResult, $actualResult);
821  }
822 
827  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
828  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
829  $arguments = array('controller' => 'DefaultController', 'action' => 'defaultAction', 'foo' => 'bar');
830  $extensionName = 'ExtensionName';
831  $pluginName = 'PluginName';
832  $expectedResult = array('foo' => 'bar');
833  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
834  $this->assertEquals($expectedResult, $actualResult);
835  }
836 }
$parameters
Definition: FileDumpEID.php:15
static _GETset($inputGet, $key='')
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet(array $parameters, array $postArguments, array $excluded, $expected)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]