TYPO3 CMS  TYPO3_7-6
UriBuilderTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
31 
36 {
41 
45  protected $mockContentObject;
46 
50  protected $mockRequest;
51 
56 
60  protected $uriBuilder;
61 
66  protected function setUp()
67  {
68  $GLOBALS['TSFE'] = $this->getMock(TypoScriptFrontendController::class, [], [], '', false);
69  $this->mockContentObject = $this->getMock(ContentObjectRenderer::class);
70  $this->mockRequest = $this->getMock(Request::class);
71  $this->mockExtensionService = $this->getMock(ExtensionService::class);
72  $this->mockConfigurationManager = $this->getMock(ConfigurationManagerInterface::class);
73  $this->uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['build']);
74  $this->uriBuilder->setRequest($this->mockRequest);
75  $this->uriBuilder->_set('contentObject', $this->mockContentObject);
76  $this->uriBuilder->_set('configurationManager', $this->mockConfigurationManager);
77  $this->uriBuilder->_set('extensionService', $this->mockExtensionService);
78  $this->uriBuilder->_set('environmentService', $this->getMock(EnvironmentService::class));
79  // Mocking backend user is required for backend URI generation as BackendUtility::getModuleUrl() is called
80  $backendUserMock = $this->getMock(BackendUserAuthentication::class);
81  $backendUserMock->expects($this->any())->method('check')->will($this->returnValue(true));
82  $GLOBALS['BE_USER'] = $backendUserMock;
83  }
84 
89  {
90  $this->uriBuilder
91  ->reset()
92  ->setArguments(['test' => 'arguments'])
93  ->setSection('testSection')
94  ->setFormat('testFormat')
95  ->setCreateAbsoluteUri(true)
96  ->setAbsoluteUriScheme('https')
97  ->setAddQueryString(true)
98  ->setArgumentsToBeExcludedFromQueryString(['test' => 'addQueryStringExcludeArguments'])
99  ->setAddQueryStringMethod('GET,POST')
100  ->setArgumentPrefix('testArgumentPrefix')
101  ->setLinkAccessRestrictedPages(true)
102  ->setTargetPageUid(123)
103  ->setTargetPageType(321)
104  ->setNoCache(true)
105  ->setUseCacheHash(false);
106  $this->assertEquals(['test' => 'arguments'], $this->uriBuilder->getArguments());
107  $this->assertEquals('testSection', $this->uriBuilder->getSection());
108  $this->assertEquals('testFormat', $this->uriBuilder->getFormat());
109  $this->assertEquals(true, $this->uriBuilder->getCreateAbsoluteUri());
110  $this->assertEquals('https', $this->uriBuilder->getAbsoluteUriScheme());
111  $this->assertEquals(true, $this->uriBuilder->getAddQueryString());
112  $this->assertEquals(['test' => 'addQueryStringExcludeArguments'], $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
113  $this->assertEquals('GET,POST', $this->uriBuilder->getAddQueryStringMethod());
114  $this->assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix());
115  $this->assertEquals(true, $this->uriBuilder->getLinkAccessRestrictedPages());
116  $this->assertEquals(123, $this->uriBuilder->getTargetPageUid());
117  $this->assertEquals(321, $this->uriBuilder->getTargetPageType());
118  $this->assertEquals(true, $this->uriBuilder->getNoCache());
119  $this->assertEquals(false, $this->uriBuilder->getUseCacheHash());
120  }
121 
126  {
127  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
128  $expectedArguments = ['tx_someextension_someplugin' => ['foo' => 'bar', 'baz' => ['extbase' => 'fluid'], 'controller' => 'SomeController']];
129  $GLOBALS['TSFE'] = null;
130  $this->uriBuilder->uriFor(null, ['foo' => 'bar', 'baz' => ['extbase' => 'fluid']], 'SomeController', 'SomeExtension', 'SomePlugin');
131  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
132  }
133 
138  {
139  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
140  $arguments = ['tx_someextension_someplugin' => ['foo' => 'bar'], 'additionalParam' => 'additionalValue'];
141  $controllerArguments = ['foo' => 'overruled', 'baz' => ['extbase' => 'fluid']];
142  $expectedArguments = ['tx_someextension_someplugin' => ['foo' => 'overruled', 'baz' => ['extbase' => 'fluid'], 'controller' => 'SomeController'], 'additionalParam' => 'additionalValue'];
143  $this->uriBuilder->setArguments($arguments);
144  $this->uriBuilder->uriFor(null, $controllerArguments, 'SomeController', 'SomeExtension', 'SomePlugin');
145  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
146  }
147 
152  {
153  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
154  $expectedArguments = ['tx_someextension_someplugin' => ['controller' => 'SomeController']];
155  $this->uriBuilder->uriFor(null, [], 'SomeController', 'SomeExtension', 'SomePlugin');
156  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
157  }
158 
163  {
164  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
165  $this->mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
166  $expectedArguments = ['tx_someextension_someplugin' => ['controller' => 'SomeControllerFromRequest']];
167  $this->uriBuilder->uriFor(null, [], null, 'SomeExtension', 'SomePlugin');
168  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
169  }
170 
175  {
176  $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_someextensionnamefromrequest_someplugin'));
177  $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
178  $expectedArguments = ['tx_someextensionnamefromrequest_someplugin' => ['controller' => 'SomeController']];
179  $this->uriBuilder->uriFor(null, [], 'SomeController', null, 'SomePlugin');
180  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
181  }
182 
187  {
188  $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_somepluginnamefromrequest'));
189  $this->mockRequest->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
190  $expectedArguments = ['tx_someextension_somepluginnamefromrequest' => ['controller' => 'SomeController']];
191  $this->uriBuilder->uriFor(null, [], 'SomeController', 'SomeExtension');
192  $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
193  }
194 
199  {
200  $this->mockExtensionService->expects($this->any())->method('isActionCacheable')->will($this->returnValue(false));
201  $this->uriBuilder->uriFor('someNonCacheableAction', [], 'SomeController', 'SomeExtension');
202  $this->assertTrue($this->uriBuilder->getUseCacheHash());
203  }
204 
209  {
210  GeneralUtility::_GETset(['M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar']);
211  $_POST = [];
212  $_POST['foo2'] = 'bar2';
213  $this->uriBuilder->setAddQueryString(true);
214  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
215  $expectedResult = '/typo3/index.php?M=moduleKey&moduleToken=dummyToken&id=pageId&foo=bar&foo2=bar2';
216  $actualResult = $this->uriBuilder->buildBackendUri();
217  $this->assertEquals($expectedResult, $actualResult);
218  }
219 
224  {
225  GeneralUtility::_GETset(['M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar']);
226  $_POST = [];
227  $_POST['foo2'] = 'bar2';
228  $this->uriBuilder->setAddQueryString(true);
229  $this->uriBuilder->setAddQueryStringMethod(null);
230  $expectedResult = '/typo3/index.php?M=moduleKey&moduleToken=dummyToken&id=pageId&foo=bar';
231  $actualResult = $this->uriBuilder->buildBackendUri();
232  $this->assertEquals($expectedResult, $actualResult);
233  }
234 
239  {
240  return [
241  'Arguments to be excluded in the beginning' => [
242  [
243  'M' => 'moduleKey',
244  'id' => 'pageId',
245  'foo' => 'bar'
246  ],
247  [
248  'foo2' => 'bar2'
249  ],
250  [
251  'M',
252  'id'
253  ],
254  '/typo3/index.php?M=&moduleToken=dummyToken&foo=bar&foo2=bar2'
255  ],
256  'Arguments to be excluded in the end' => [
257  [
258  'foo' => 'bar',
259  'id' => 'pageId',
260  'M' => 'moduleKey'
261  ],
262  [
263  'foo2' => 'bar2'
264  ],
265  [
266  'M',
267  'id'
268  ],
269  '/typo3/index.php?M=&moduleToken=dummyToken&foo=bar&foo2=bar2'
270  ],
271  'Arguments in nested array to be excluded' => [
272  [
273  'tx_foo' => [
274  'bar' => 'baz'
275  ],
276  'id' => 'pageId',
277  'M' => 'moduleKey'
278  ],
279  [
280  'foo2' => 'bar2'
281  ],
282  [
283  'id',
284  'tx_foo[bar]'
285  ],
286  '/typo3/index.php?M=moduleKey&moduleToken=dummyToken&foo2=bar2'
287  ],
288  'Arguments in multidimensional array to be excluded' => [
289  [
290  'tx_foo' => [
291  'bar' => [
292  'baz' => 'bay'
293  ]
294  ],
295  'id' => 'pageId',
296  'M' => 'moduleKey'
297  ],
298  [
299  'foo2' => 'bar2'
300  ],
301  [
302  'id',
303  'tx_foo[bar][baz]'
304  ],
305  '/typo3/index.php?M=moduleKey&moduleToken=dummyToken&foo2=bar2'
306  ],
307  ];
308  }
309 
318  public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet(array $parameters, array $postArguments, array $excluded, $expected)
319  {
320  GeneralUtility::_GETset($parameters);
321  $_POST = $postArguments;
322  $this->uriBuilder->setAddQueryString(true);
323  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
324  $this->uriBuilder->setArgumentsToBeExcludedFromQueryString($excluded);
325  $actualResult = $this->uriBuilder->buildBackendUri();
326  $this->assertEquals($expected, $actualResult);
327  }
328 
333  {
334  GeneralUtility::_GETset(['M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar']);
335  $expectedResult = '/typo3/index.php?M=moduleKey&moduleToken=dummyToken&id=pageId';
336  $actualResult = $this->uriBuilder->buildBackendUri();
337  $this->assertEquals($expectedResult, $actualResult);
338  }
339 
344  {
345  GeneralUtility::_GETset(['M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar']);
346  $this->uriBuilder->setArguments(['M' => 'overwrittenModuleKey', 'somePrefix' => ['bar' => 'baz']]);
347  $expectedResult = '/typo3/index.php?M=overwrittenModuleKey&moduleToken=dummyToken&id=pageId&somePrefix%5Bbar%5D=baz';
348  $actualResult = $this->uriBuilder->buildBackendUri();
349  $this->assertEquals($expectedResult, $actualResult);
350  }
351 
356  {
357  GeneralUtility::_GETset(['M' => 'moduleKey']);
358  $mockDomainObject = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
359  $mockDomainObject->_set('uid', '123');
360  $this->uriBuilder->setArguments(['somePrefix' => ['someDomainObject' => $mockDomainObject]]);
361  $expectedResult = '/typo3/index.php?M=moduleKey&moduleToken=dummyToken&somePrefix%5BsomeDomainObject%5D=123';
362  $actualResult = $this->uriBuilder->buildBackendUri();
363  $this->assertEquals($expectedResult, $actualResult);
364  }
365 
370  {
371  GeneralUtility::_GETset(['M' => 'moduleKey']);
372  $this->uriBuilder->setSection('someSection');
373  $expectedResult = '/typo3/index.php?M=moduleKey&moduleToken=dummyToken#someSection';
374  $actualResult = $this->uriBuilder->buildBackendUri();
375  $this->assertEquals($expectedResult, $actualResult);
376  }
377 
382  {
384  GeneralUtility::_GETset(['M' => 'moduleKey']);
385  $_SERVER['HTTP_HOST'] = 'baseuri';
386  $_SERVER['SCRIPT_NAME'] = '/typo3/index.php';
387  $this->mockRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue('http://baseuri'));
388  $this->uriBuilder->setCreateAbsoluteUri(true);
389  $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'index.php?M=moduleKey&moduleToken=dummyToken';
390  $actualResult = $this->uriBuilder->buildBackendUri();
391  $this->assertSame($expectedResult, $actualResult);
392  }
393 
398  {
399  $_POST = [
400  'key1' => 'POST1',
401  'key2' => 'POST2',
402  'key3' => [
403  'key31' => 'POST31',
404  'key32' => 'POST32',
405  'key33' => [
406  'key331' => 'POST331',
407  'key332' => 'POST332',
408  ]
409  ],
410  ];
411  $_GET = [
412  'key2' => 'GET2',
413  'key3' => [
414  'key32' => 'GET32',
415  'key33' => [
416  'key331' => 'GET331',
417  ]
418  ]
419  ];
420  $this->uriBuilder->setAddQueryString(true);
421  $this->uriBuilder->setAddQueryStringMethod('POST,GET');
422  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('/typo3/index.php?M=&moduleToken=dummyToken&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
423  $actualResult = $this->uriBuilder->buildBackendUri();
424  $this->assertEquals($expectedResult, $actualResult);
425  }
426 
431  {
432  $_GET = [
433  'key1' => 'GET1',
434  'key2' => 'GET2',
435  'key3' => [
436  'key31' => 'GET31',
437  'key32' => 'GET32',
438  'key33' => [
439  'key331' => 'GET331',
440  'key332' => 'GET332',
441  ]
442  ],
443  ];
444  $_POST = [
445  'key2' => 'POST2',
446  'key3' => [
447  'key32' => 'POST32',
448  'key33' => [
449  'key331' => 'POST331',
450  ]
451  ]
452  ];
453  $this->uriBuilder->setAddQueryString(true);
454  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
455  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('/typo3/index.php?M=&moduleToken=dummyToken&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
456  $actualResult = $this->uriBuilder->buildBackendUri();
457  $this->assertEquals($expectedResult, $actualResult);
458  }
459 
466  private function rawUrlEncodeSquareBracketsInUrl($string)
467  {
468  return str_replace(['[', ']'], ['%5B', '%5D'], $string);
469  }
470 
474  public function buildFrontendUriCreatesTypoLink()
475  {
477  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
478  $uriBuilder->_set('contentObject', $this->mockContentObject);
479  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['someTypoLinkConfiguration']));
480  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['someTypoLinkConfiguration']);
481  $uriBuilder->buildFrontendUri();
482  }
483 
488  {
489  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
490  $expectedResult = 'relative/uri';
491  $actualResult = $this->uriBuilder->buildFrontendUri();
492  $this->assertSame($expectedResult, $actualResult);
493  }
494 
499  {
500  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
501  $expectedResult = '/relative/uri';
502  $actualResult = $this->uriBuilder->buildFrontendUri();
503  $this->assertSame($expectedResult, $actualResult);
504  }
505 
509  public function buildFrontendUriCreatesAbsoluteUrisIfSpecified()
510  {
512  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
513  $uriBuilder->_set('contentObject', $this->mockContentObject);
514  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['foo' => 'bar']));
515  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['foo' => 'bar', 'forceAbsoluteUrl' => true])->will($this->returnValue('http://baseuri/relative/uri'));
516  $uriBuilder->setCreateAbsoluteUri(true);
517  $expectedResult = 'http://baseuri/relative/uri';
518  $actualResult = $uriBuilder->buildFrontendUri();
519  $this->assertSame($expectedResult, $actualResult);
520  }
521 
525  public function buildFrontendUriSetsAbsoluteUriSchemeIfSpecified()
526  {
528  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
529  $uriBuilder->_set('contentObject', $this->mockContentObject);
530  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['foo' => 'bar']));
531  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['foo' => 'bar', 'forceAbsoluteUrl' => true, 'forceAbsoluteUrl.' => ['scheme' => 'someScheme']])->will($this->returnValue('http://baseuri/relative/uri'));
532  $uriBuilder->setCreateAbsoluteUri(true);
533  $uriBuilder->setAbsoluteUriScheme('someScheme');
534  $expectedResult = 'http://baseuri/relative/uri';
535  $actualResult = $uriBuilder->buildFrontendUri();
536  $this->assertSame($expectedResult, $actualResult);
537  }
538 
542  public function buildFrontendUriDoesNotSetAbsoluteUriSchemeIfCreateAbsoluteUriIsFalse()
543  {
545  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
546  $uriBuilder->_set('contentObject', $this->mockContentObject);
547  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['foo' => 'bar']));
548  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['foo' => 'bar'])->will($this->returnValue('http://baseuri/relative/uri'));
549  $uriBuilder->setCreateAbsoluteUri(false);
550  $uriBuilder->setAbsoluteUriScheme('someScheme');
551  $expectedResult = 'http://baseuri/relative/uri';
552  $actualResult = $uriBuilder->buildFrontendUri();
553  $this->assertSame($expectedResult, $actualResult);
554  }
555 
560  {
561  $this->uriBuilder->setArguments(['test' => 'arguments'])->setSection('testSection')->setFormat('someFormat')->setCreateAbsoluteUri(true)->setAddQueryString(true)->setArgumentsToBeExcludedFromQueryString(['test' => 'addQueryStringExcludeArguments'])->setAddQueryStringMethod(null)->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(true)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(true)->setUseCacheHash(false);
562  $this->uriBuilder->reset();
563  $this->assertEquals([], $this->uriBuilder->getArguments());
564  $this->assertEquals('', $this->uriBuilder->getSection());
565  $this->assertEquals('', $this->uriBuilder->getFormat());
566  $this->assertEquals(false, $this->uriBuilder->getCreateAbsoluteUri());
567  $this->assertEquals(false, $this->uriBuilder->getAddQueryString());
568  $this->assertEquals([], $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
569  $this->assertEquals(null, $this->uriBuilder->getAddQueryStringMethod());
570  $this->assertEquals(null, $this->uriBuilder->getArgumentPrefix());
571  $this->assertEquals(false, $this->uriBuilder->getLinkAccessRestrictedPages());
572  $this->assertEquals(null, $this->uriBuilder->getTargetPageUid());
573  $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
574  $this->assertEquals(false, $this->uriBuilder->getNoCache());
575  $this->assertEquals(true, $this->uriBuilder->getUseCacheHash());
576  }
577 
582  {
583  $GLOBALS['TSFE']->id = 123;
584  $this->uriBuilder->setTargetPageUid(321);
585  $expectedConfiguration = ['parameter' => 321, 'useCacheHash' => 1];
586  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
587  $this->assertEquals($expectedConfiguration, $actualConfiguration);
588  }
589 
594  {
595  $GLOBALS['TSFE']->id = 123;
596  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1];
597  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
598  $this->assertEquals($expectedConfiguration, $actualConfiguration);
599  }
600 
605  {
606  $this->uriBuilder->setTargetPageUid(123);
607  $this->uriBuilder->setArguments(['foo' => 'bar', 'baz' => ['extbase' => 'fluid']]);
608  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&foo=bar&baz[extbase]=fluid'];
609  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
610  $this->assertEquals($expectedConfiguration, $actualConfiguration);
611  }
612 
617  {
618  $this->uriBuilder->setTargetPageUid(123);
619  $this->uriBuilder->setAddQueryString(true);
620  $expectedConfiguration = ['parameter' => 123, 'addQueryString' => 1, 'useCacheHash' => 1];
621  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
622  $this->assertEquals($expectedConfiguration, $actualConfiguration);
623  }
624 
629  {
630  $this->uriBuilder->setTargetPageUid(123);
631  $this->uriBuilder->setAddQueryString(true);
632  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
633  $expectedConfiguration = ['parameter' => 123, 'addQueryString' => 1, 'addQueryString.' => ['method' => 'GET,POST'], 'useCacheHash' => 1];
634  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
635  $this->assertEquals($expectedConfiguration, $actualConfiguration);
636  }
637 
642  {
643  $mockDomainObject1 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
644  $mockDomainObject1->_set('uid', '123');
645  $mockDomainObject2 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
646  $mockDomainObject2->_set('uid', '321');
647  $this->uriBuilder->setTargetPageUid(123);
648  $this->uriBuilder->setArguments(['someDomainObject' => $mockDomainObject1, 'baz' => ['someOtherDomainObject' => $mockDomainObject2]]);
649  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&someDomainObject=123&baz[someOtherDomainObject]=321'];
650  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
651  $this->assertEquals($expectedConfiguration, $actualConfiguration);
652  }
653 
658  {
659  $this->uriBuilder->setTargetPageUid(123);
660  $this->uriBuilder->setFormat('txt');
661  $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
662 
663  $mockConfigurationManager = $this->getMock(ConfigurationManager::class);
664  $mockConfigurationManager->expects($this->any())->method('getConfiguration')
665  ->will($this->returnValue(['view' => ['formatToPageTypeMapping' => ['txt' => 2]]]));
666  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
667 
668  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
669  ->with('SomeExtensionNameFromRequest', 'txt')
670  ->will($this->returnValue(2));
671 
672  $expectedConfiguration = ['parameter' => '123,2', 'useCacheHash' => 1];
673  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
674  $this->assertEquals($expectedConfiguration, $actualConfiguration);
675  }
676 
681  {
682  $this->uriBuilder->setTargetPageUid(123);
683  $this->uriBuilder->setFormat('txt');
684 
685  $mockConfigurationManager = $this->getMock(ConfigurationManager::class);
686  $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue([]));
687  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
688 
689  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
690  ->with(null, 'txt')
691  ->will($this->returnValue(0));
692 
693  $expectedConfiguration = ['parameter' => '123,0', 'useCacheHash' => 1];
694  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
695 
696  $this->assertEquals($expectedConfiguration, $actualConfiguration);
697  }
698 
703  {
704  $this->uriBuilder->setTargetPageUid(123);
705  $this->uriBuilder->setFormat('txt');
706 
707  $mockConfigurationManager = $this->getMock(ConfigurationManager::class);
708  $mockConfigurationManager->expects($this->any())->method('getConfiguration')
709  ->will($this->returnValue([['view' => ['formatToPageTypeMapping' => ['pdf' => 2]]]]));
710  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
711 
712  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
713  ->with(null, 'txt')
714  ->will($this->returnValue(0));
715 
716  $expectedConfiguration = ['parameter' => '123,0', 'useCacheHash' => 1];
717  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
718 
719  $this->assertEquals($expectedConfiguration, $actualConfiguration);
720  }
721 
726  {
727  $this->uriBuilder->setTargetPageUid(123);
728  $this->uriBuilder->setNoCache(true);
729  $expectedConfiguration = ['parameter' => 123, 'no_cache' => 1];
730  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
731  $this->assertEquals($expectedConfiguration, $actualConfiguration);
732  }
733 
738  {
739  $this->uriBuilder->setTargetPageUid(123);
740  $this->uriBuilder->setUseCacheHash(false);
741  $expectedConfiguration = ['parameter' => 123];
742  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
743  $this->assertEquals($expectedConfiguration, $actualConfiguration);
744  }
745 
750  {
751  $this->uriBuilder->setTargetPageUid(123);
752  $this->uriBuilder->setSection('SomeSection');
753  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'section' => 'SomeSection'];
754  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
755  $this->assertEquals($expectedConfiguration, $actualConfiguration);
756  }
757 
762  {
763  $this->uriBuilder->setTargetPageUid(123);
764  $this->uriBuilder->setLinkAccessRestrictedPages(true);
765  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'linkAccessRestrictedPages' => 1];
766  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
767  $this->assertEquals($expectedConfiguration, $actualConfiguration);
768  }
769 
774  {
775  $mockDomainObject1 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
776  $mockDomainObject1->_set('uid', '123');
777  $mockDomainObject2 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
778  $mockDomainObject2->_set('uid', '321');
779  $expectedResult = ['foo' => ['bar' => 'baz'], 'domainObject1' => '123', 'second' => ['domainObject2' => '321']];
780  $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', ['foo' => ['bar' => 'baz'], 'domainObject1' => $mockDomainObject1, 'second' => ['domainObject2' => $mockDomainObject2]]);
781  $this->assertEquals($expectedResult, $actualResult);
782  }
783 
788  {
789  $objectStorage = new ObjectStorage();
790  $mockChildObject1 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
791  $mockChildObject1->_set('uid', '123');
792  $objectStorage->attach($mockChildObject1);
793  $expectedResult = ['foo' => ['bar' => 'baz'], 'objectStorage' => ['123']];
794  $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', ['foo' => ['bar' => 'baz'], 'objectStorage' => $objectStorage]);
795  $this->assertEquals($expectedResult, $actualResult);
796  }
797 
801  public function conversionOfTansientObjectsIsInvoked()
802  {
803  $mockValueObject = new ValueObjectFixture();
804  $mockValueObject->name = 'foo';
806  $mockUriBuilder = $this->getAccessibleMock(UriBuilder::class, ['convertTransientObjectToArray']);
807  $mockUriBuilder->expects($this->once())->method('convertTransientObjectToArray')->will($this->returnValue(['foo' => 'bar']));
808  $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', ['object' => $mockValueObject]);
809  $expectedResult = ['object' => ['foo' => 'bar']];
810  $this->assertEquals($expectedResult, $actualResult);
811  }
812 
817  public function conversionOfTansientObjectsThrowsExceptionForOtherThanValueObjects()
818  {
819  $mockEntity = new EntityFixture();
820  $mockEntity->name = 'foo';
822  $mockUriBuilder = $this->getAccessibleMock(UriBuilder::class, ['dummy']);
823  $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', ['object' => $mockEntity]);
824  }
825 
830  {
831  $mockValueObject = new ValueObjectFixture();
832  $mockValueObject->name = 'foo';
833  $uriBuilder = new UriBuilder();
834  $actualResult = $uriBuilder->convertTransientObjectToArray($mockValueObject);
835  $expectedResult = ['name' => 'foo', 'object' => null, 'uid' => null, 'pid' => null];
836  $this->assertEquals($expectedResult, $actualResult);
837  }
838 
843  {
844  $mockValueObject = new ValueObjectFixture();
845  $objectStorage = new ObjectStorage();
846  $mockValueObject->name = 'foo';
847  $mockValueObject2 = new ValueObjectFixture();
848  $mockValueObject2->name = 'bar';
849  $objectStorage->attach($mockValueObject2);
850  $mockValueObject->object = $objectStorage;
851  $uriBuilder = new UriBuilder();
852  $actualResult = $uriBuilder->convertTransientObjectToArray($mockValueObject);
853  $expectedResult = [
854  'name' => 'foo',
855  'object' => [
856  [
857  'name' => 'bar',
858  'uid' => null,
859  'pid' => null,
860  'object' => null
861  ]
862  ],
863  'uid' => null,
864  'pid' => null
865  ];
866  $this->assertEquals($expectedResult, $actualResult);
867  }
868 
873  {
874  $mockInnerValueObject2 = new ValueObjectFixture();
875  $mockInnerValueObject2->name = 'foo';
876  $mockInnerValueObject2->uid = 99;
877  $mockInnerValueObject1 = new ValueObjectFixture();
878  $mockInnerValueObject1->object = $mockInnerValueObject2;
879  $mockValueObject = new ValueObjectFixture();
880  $mockValueObject->object = $mockInnerValueObject1;
881  $uriBuilder = new UriBuilder();
882  $actualResult = $uriBuilder->convertTransientObjectToArray($mockValueObject);
883  $expectedResult = [
884  'name' => null,
885  'object' => [
886  'name' => null,
887  'object' => 99,
888  'uid' => null,
889  'pid' => null
890  ],
891  'uid' => null,
892  'pid' => null
893  ];
894  $this->assertEquals($expectedResult, $actualResult);
895  }
896 
901  {
902  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
903  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'SomeController')->will($this->returnValue('defaultAction'));
904  $arguments = ['controller' => 'SomeController', 'action' => 'someAction', 'foo' => 'bar'];
905  $extensionName = 'ExtensionName';
906  $pluginName = 'PluginName';
907  $expectedResult = ['controller' => 'SomeController', 'action' => 'someAction', 'foo' => 'bar'];
908  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
909  $this->assertEquals($expectedResult, $actualResult);
910  }
911 
916  {
917  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
918  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
919  $arguments = ['controller' => 'DefaultController', 'action' => 'someAction', 'foo' => 'bar'];
920  $extensionName = 'ExtensionName';
921  $pluginName = 'PluginName';
922  $expectedResult = ['action' => 'someAction', 'foo' => 'bar'];
923  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
924  $this->assertEquals($expectedResult, $actualResult);
925  }
926 
931  {
932  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
933  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'SomeController')->will($this->returnValue('defaultAction'));
934  $arguments = ['controller' => 'SomeController', 'action' => 'defaultAction', 'foo' => 'bar'];
935  $extensionName = 'ExtensionName';
936  $pluginName = 'PluginName';
937  $expectedResult = ['controller' => 'SomeController', 'foo' => 'bar'];
938  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
939  $this->assertEquals($expectedResult, $actualResult);
940  }
941 
946  {
947  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
948  $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
949  $arguments = ['controller' => 'DefaultController', 'action' => 'defaultAction', 'foo' => 'bar'];
950  $extensionName = 'ExtensionName';
951  $pluginName = 'PluginName';
952  $expectedResult = ['foo' => 'bar'];
953  $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
954  $this->assertEquals($expectedResult, $actualResult);
955  }
956 
961  {
962  return [
963  'Extbase ObjectStorage' => [new ObjectStorage()],
964  'SplObjectStorage' => [new \SplObjectStorage()],
965  'ArrayIterator' => [new \ArrayIterator()]
966  ];
967  }
968 
974  {
975  $result = $this->uriBuilder->_call('convertIteratorToArray', $iterator);
976  $this->assertTrue(is_array($result));
977  }
978 }
static _GETset($inputGet, $key='')
buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet(array $parameters, array $postArguments, array $excluded, $expected)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']