TYPO3 CMS  TYPO3_8-7
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 
35 class UriBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
36 {
41 
45  protected $mockContentObject;
46 
50  protected $mockRequest;
51 
56 
60  protected $uriBuilder;
61 
66  protected function setUp()
67  {
68  $GLOBALS['TSFE'] = $this->createMock(TypoScriptFrontendController::class);
69  $this->mockContentObject = $this->createMock(ContentObjectRenderer::class);
70  $this->mockRequest = $this->createMock(Request::class);
71  $this->mockExtensionService = $this->createMock(ExtensionService::class);
72  $this->mockConfigurationManager = $this->createMock(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->createMock(EnvironmentService::class));
79  // Mocking backend user is required for backend URI generation as BackendUtility::getModuleUrl() is called
80  $backendUserMock = $this->createMock(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  {
383  GeneralUtility::_GETset(['M' => 'moduleKey']);
384  $_SERVER['HTTP_HOST'] = 'baseuri';
385  $_SERVER['SCRIPT_NAME'] = '/typo3/index.php';
386  $this->mockRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue('http://baseuri'));
387  $this->uriBuilder->setCreateAbsoluteUri(true);
388  $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'index.php?M=moduleKey&moduleToken=dummyToken';
389  $actualResult = $this->uriBuilder->buildBackendUri();
390  $this->assertSame($expectedResult, $actualResult);
391  }
392 
397  {
398  $_POST = [
399  'key1' => 'POST1',
400  'key2' => 'POST2',
401  'key3' => [
402  'key31' => 'POST31',
403  'key32' => 'POST32',
404  'key33' => [
405  'key331' => 'POST331',
406  'key332' => 'POST332',
407  ]
408  ],
409  ];
410  $_GET = [
411  'key2' => 'GET2',
412  'key3' => [
413  'key32' => 'GET32',
414  'key33' => [
415  'key331' => 'GET331',
416  ]
417  ]
418  ];
419  $this->uriBuilder->setAddQueryString(true);
420  $this->uriBuilder->setAddQueryStringMethod('POST,GET');
421  $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');
422  $actualResult = $this->uriBuilder->buildBackendUri();
423  $this->assertEquals($expectedResult, $actualResult);
424  }
425 
430  {
431  $_GET = [
432  'key1' => 'GET1',
433  'key2' => 'GET2',
434  'key3' => [
435  'key31' => 'GET31',
436  'key32' => 'GET32',
437  'key33' => [
438  'key331' => 'GET331',
439  'key332' => 'GET332',
440  ]
441  ],
442  ];
443  $_POST = [
444  'key2' => 'POST2',
445  'key3' => [
446  'key32' => 'POST32',
447  'key33' => [
448  'key331' => 'POST331',
449  ]
450  ]
451  ];
452  $this->uriBuilder->setAddQueryString(true);
453  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
454  $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');
455  $actualResult = $this->uriBuilder->buildBackendUri();
456  $this->assertEquals($expectedResult, $actualResult);
457  }
458 
465  private function rawUrlEncodeSquareBracketsInUrl($string)
466  {
467  return str_replace(['[', ']'], ['%5B', '%5D'], $string);
468  }
469 
473  public function buildFrontendUriCreatesTypoLink()
474  {
476  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
477  $uriBuilder->_set('contentObject', $this->mockContentObject);
478  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['someTypoLinkConfiguration']));
479  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['someTypoLinkConfiguration']);
480  $uriBuilder->buildFrontendUri();
481  }
482 
487  {
488  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
489  $expectedResult = 'relative/uri';
490  $actualResult = $this->uriBuilder->buildFrontendUri();
491  $this->assertSame($expectedResult, $actualResult);
492  }
493 
498  {
499  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
500  $expectedResult = '/relative/uri';
501  $actualResult = $this->uriBuilder->buildFrontendUri();
502  $this->assertSame($expectedResult, $actualResult);
503  }
504 
508  public function buildFrontendUriCreatesAbsoluteUrisIfSpecified()
509  {
511  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
512  $uriBuilder->_set('contentObject', $this->mockContentObject);
513  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['foo' => 'bar']));
514  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['foo' => 'bar', 'forceAbsoluteUrl' => true])->will($this->returnValue('http://baseuri/relative/uri'));
515  $uriBuilder->setCreateAbsoluteUri(true);
516  $expectedResult = 'http://baseuri/relative/uri';
517  $actualResult = $uriBuilder->buildFrontendUri();
518  $this->assertSame($expectedResult, $actualResult);
519  }
520 
524  public function buildFrontendUriSetsAbsoluteUriSchemeIfSpecified()
525  {
527  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
528  $uriBuilder->_set('contentObject', $this->mockContentObject);
529  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['foo' => 'bar']));
530  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['foo' => 'bar', 'forceAbsoluteUrl' => true, 'forceAbsoluteUrl.' => ['scheme' => 'someScheme']])->will($this->returnValue('http://baseuri/relative/uri'));
531  $uriBuilder->setCreateAbsoluteUri(true);
532  $uriBuilder->setAbsoluteUriScheme('someScheme');
533  $expectedResult = 'http://baseuri/relative/uri';
534  $actualResult = $uriBuilder->buildFrontendUri();
535  $this->assertSame($expectedResult, $actualResult);
536  }
537 
541  public function buildFrontendUriDoesNotSetAbsoluteUriSchemeIfCreateAbsoluteUriIsFalse()
542  {
544  $uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['buildTypolinkConfiguration']);
545  $uriBuilder->_set('contentObject', $this->mockContentObject);
546  $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(['foo' => 'bar']));
547  $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(['foo' => 'bar'])->will($this->returnValue('http://baseuri/relative/uri'));
548  $uriBuilder->setCreateAbsoluteUri(false);
549  $uriBuilder->setAbsoluteUriScheme('someScheme');
550  $expectedResult = 'http://baseuri/relative/uri';
551  $actualResult = $uriBuilder->buildFrontendUri();
552  $this->assertSame($expectedResult, $actualResult);
553  }
554 
559  {
560  $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);
561  $this->uriBuilder->reset();
562  $this->assertEquals([], $this->uriBuilder->getArguments());
563  $this->assertEquals('', $this->uriBuilder->getSection());
564  $this->assertEquals('', $this->uriBuilder->getFormat());
565  $this->assertEquals(false, $this->uriBuilder->getCreateAbsoluteUri());
566  $this->assertEquals(false, $this->uriBuilder->getAddQueryString());
567  $this->assertEquals([], $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
568  $this->assertEquals(null, $this->uriBuilder->getAddQueryStringMethod());
569  $this->assertEquals(null, $this->uriBuilder->getArgumentPrefix());
570  $this->assertEquals(false, $this->uriBuilder->getLinkAccessRestrictedPages());
571  $this->assertEquals(null, $this->uriBuilder->getTargetPageUid());
572  $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
573  $this->assertEquals(false, $this->uriBuilder->getNoCache());
574  $this->assertEquals(true, $this->uriBuilder->getUseCacheHash());
575  }
576 
581  {
582  $GLOBALS['TSFE']->id = 123;
583  $this->uriBuilder->setTargetPageUid(321);
584  $expectedConfiguration = ['parameter' => 321, 'useCacheHash' => 1];
585  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
586  $this->assertEquals($expectedConfiguration, $actualConfiguration);
587  }
588 
593  {
594  $GLOBALS['TSFE']->id = 123;
595  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1];
596  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
597  $this->assertEquals($expectedConfiguration, $actualConfiguration);
598  }
599 
604  {
605  $this->uriBuilder->setTargetPageUid(123);
606  $this->uriBuilder->setArguments(['foo' => 'bar', 'baz' => ['extbase' => 'fluid']]);
607  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&foo=bar&baz[extbase]=fluid'];
608  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
609  $this->assertEquals($expectedConfiguration, $actualConfiguration);
610  }
611 
616  {
617  $this->uriBuilder->setTargetPageUid(123);
618  $this->uriBuilder->setAddQueryString(true);
619  $expectedConfiguration = ['parameter' => 123, 'addQueryString' => 1, 'useCacheHash' => 1];
620  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
621  $this->assertEquals($expectedConfiguration, $actualConfiguration);
622  }
623 
628  {
629  $this->uriBuilder->setTargetPageUid(123);
630  $this->uriBuilder->setAddQueryString(true);
631  $this->uriBuilder->setAddQueryStringMethod('GET,POST');
632  $expectedConfiguration = ['parameter' => 123, 'addQueryString' => 1, 'addQueryString.' => ['method' => 'GET,POST'], 'useCacheHash' => 1];
633  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
634  $this->assertEquals($expectedConfiguration, $actualConfiguration);
635  }
636 
641  {
642  $mockDomainObject1 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
643  $mockDomainObject1->_set('uid', '123');
644  $mockDomainObject2 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
645  $mockDomainObject2->_set('uid', '321');
646  $this->uriBuilder->setTargetPageUid(123);
647  $this->uriBuilder->setArguments(['someDomainObject' => $mockDomainObject1, 'baz' => ['someOtherDomainObject' => $mockDomainObject2]]);
648  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&someDomainObject=123&baz[someOtherDomainObject]=321'];
649  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
650  $this->assertEquals($expectedConfiguration, $actualConfiguration);
651  }
652 
657  {
658  $this->uriBuilder->setTargetPageUid(123);
659  $this->uriBuilder->setFormat('txt');
660  $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
661 
662  $mockConfigurationManager = $this->createMock(ConfigurationManager::class);
663  $mockConfigurationManager->expects($this->any())->method('getConfiguration')
664  ->will($this->returnValue(['view' => ['formatToPageTypeMapping' => ['txt' => 2]]]));
665  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
666 
667  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
668  ->with('SomeExtensionNameFromRequest', 'txt')
669  ->will($this->returnValue(2));
670 
671  $expectedConfiguration = ['parameter' => '123,2', 'useCacheHash' => 1];
672  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
673  $this->assertEquals($expectedConfiguration, $actualConfiguration);
674  }
675 
680  {
681  $this->uriBuilder->setTargetPageUid(123);
682  $this->uriBuilder->setFormat('txt');
683 
684  $mockConfigurationManager = $this->createMock(ConfigurationManager::class);
685  $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue([]));
686  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
687 
688  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
689  ->with(null, 'txt')
690  ->will($this->returnValue(0));
691 
692  $expectedConfiguration = ['parameter' => '123,0', 'useCacheHash' => 1];
693  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
694 
695  $this->assertEquals($expectedConfiguration, $actualConfiguration);
696  }
697 
702  {
703  $this->uriBuilder->setTargetPageUid(123);
704  $this->uriBuilder->setFormat('txt');
705 
706  $mockConfigurationManager = $this->createMock(ConfigurationManager::class);
707  $mockConfigurationManager->expects($this->any())->method('getConfiguration')
708  ->will($this->returnValue([['view' => ['formatToPageTypeMapping' => ['pdf' => 2]]]]));
709  $this->uriBuilder->_set('configurationManager', $mockConfigurationManager);
710 
711  $this->mockExtensionService->expects($this->any())->method('getTargetPageTypeByFormat')
712  ->with(null, 'txt')
713  ->will($this->returnValue(0));
714 
715  $expectedConfiguration = ['parameter' => '123,0', 'useCacheHash' => 1];
716  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
717 
718  $this->assertEquals($expectedConfiguration, $actualConfiguration);
719  }
720 
725  {
726  $this->uriBuilder->setTargetPageUid(123);
727  $this->uriBuilder->setNoCache(true);
728  $expectedConfiguration = ['parameter' => 123, 'no_cache' => 1];
729  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
730  $this->assertEquals($expectedConfiguration, $actualConfiguration);
731  }
732 
737  {
738  $this->uriBuilder->setTargetPageUid(123);
739  $this->uriBuilder->setUseCacheHash(false);
740  $expectedConfiguration = ['parameter' => 123];
741  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
742  $this->assertEquals($expectedConfiguration, $actualConfiguration);
743  }
744 
749  {
750  $this->uriBuilder->setTargetPageUid(123);
751  $this->uriBuilder->setSection('SomeSection');
752  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'section' => 'SomeSection'];
753  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
754  $this->assertEquals($expectedConfiguration, $actualConfiguration);
755  }
756 
761  {
762  $this->uriBuilder->setTargetPageUid(123);
763  $this->uriBuilder->setLinkAccessRestrictedPages(true);
764  $expectedConfiguration = ['parameter' => 123, 'useCacheHash' => 1, 'linkAccessRestrictedPages' => 1];
765  $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
766  $this->assertEquals($expectedConfiguration, $actualConfiguration);
767  }
768 
773  {
774  $mockDomainObject1 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
775  $mockDomainObject1->_set('uid', '123');
776  $mockDomainObject2 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
777  $mockDomainObject2->_set('uid', '321');
778  $expectedResult = ['foo' => ['bar' => 'baz'], 'domainObject1' => '123', 'second' => ['domainObject2' => '321']];
779  $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', ['foo' => ['bar' => 'baz'], 'domainObject1' => $mockDomainObject1, 'second' => ['domainObject2' => $mockDomainObject2]]);
780  $this->assertEquals($expectedResult, $actualResult);
781  }
782 
787  {
788  $objectStorage = new ObjectStorage();
789  $mockChildObject1 = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
790  $mockChildObject1->_set('uid', '123');
791  $objectStorage->attach($mockChildObject1);
792  $expectedResult = ['foo' => ['bar' => 'baz'], 'objectStorage' => ['123']];
793  $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', ['foo' => ['bar' => 'baz'], 'objectStorage' => $objectStorage]);
794  $this->assertEquals($expectedResult, $actualResult);
795  }
796 
800  public function conversionOfTansientObjectsIsInvoked()
801  {
802  $mockValueObject = new ValueObjectFixture();
803  $mockValueObject->name = 'foo';
805  $mockUriBuilder = $this->getAccessibleMock(UriBuilder::class, ['convertTransientObjectToArray']);
806  $mockUriBuilder->expects($this->once())->method('convertTransientObjectToArray')->will($this->returnValue(['foo' => 'bar']));
807  $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', ['object' => $mockValueObject]);
808  $expectedResult = ['object' => ['foo' => 'bar']];
809  $this->assertEquals($expectedResult, $actualResult);
810  }
811 
815  public function conversionOfTansientObjectsThrowsExceptionForOtherThanValueObjects()
816  {
817  $this->expectException(InvalidArgumentValueException::class);
818  $this->expectExceptionCode(1260881688);
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)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']