Merge "[BUGFIX] ConfigurationManager use FrontendSimulator only if neccessary"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / MVC / Web / Routing / UriBuilderTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 require_once (t3lib_extMgm::extPath('extbase') . 'Tests/Unit/Fixtures/Entity.php');
29
30 class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
31
32 /**
33 * @var tslib_fe
34 */
35 protected $tsfeBackup;
36
37 /**
38 * @var array
39 */
40 protected $getBackup;
41
42 /**
43 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
44 */
45 protected $mockConfigurationManager;
46
47 /**
48 * @var tslib_cObj
49 */
50 protected $mockContentObject;
51
52 /**
53 * @var Tx_Extbase_MVC_Web_Request
54 */
55 protected $mockRequest;
56
57 /**
58 * @var Tx_Extbase_Service_ExtensionService
59 */
60 protected $mockExtensionService;
61
62 /**
63 * @var Tx_Extbase_MVC_Web_Routing_UriBuilder
64 */
65 protected $uriBuilder;
66
67 public function setUp() {
68 $this->tsfeBackup = $GLOBALS['TSFE'];
69 $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE);
70
71 $this->getBackup = t3lib_div::_GET();
72
73 $this->mockContentObject = $this->getMock('tslib_cObj');
74 $this->mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
75 $this->mockExtensionService = $this->getMock('Tx_Extbase_Service_ExtensionService');
76 $this->mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
77
78 $this->uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('build'));
79 $this->uriBuilder->setRequest($this->mockRequest);
80 $this->uriBuilder->_set('contentObject', $this->mockContentObject);
81 $this->uriBuilder->injectConfigurationManager($this->mockConfigurationManager);
82
83 $this->uriBuilder->injectExtensionService($this->mockExtensionService);
84 }
85
86 public function tearDown() {
87 $GLOBALS['TSFE'] = $this->tsfeBackup;
88 t3lib_div::_GETset($this->getBackup);
89 }
90
91 /**
92 * @test
93 */
94 public function settersAndGettersWorkAsExpected() {
95 $this->uriBuilder
96 ->reset()
97 ->setArguments(array('test' => 'arguments'))
98 ->setSection('testSection')
99 ->setFormat('testFormat')
100 ->setCreateAbsoluteUri(TRUE)
101 ->setAbsoluteUriScheme('https')
102 ->setAddQueryString(TRUE)
103 ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
104 ->setArgumentPrefix('testArgumentPrefix')
105 ->setLinkAccessRestrictedPages(TRUE)
106 ->setTargetPageUid(123)
107 ->setTargetPageType(321)
108 ->setNoCache(TRUE)
109 ->setUseCacheHash(FALSE);
110
111 $this->assertEquals(array('test' => 'arguments'), $this->uriBuilder->getArguments());
112 $this->assertEquals('testSection', $this->uriBuilder->getSection());
113 $this->assertEquals('testFormat', $this->uriBuilder->getFormat());
114 $this->assertEquals(TRUE, $this->uriBuilder->getCreateAbsoluteUri());
115 $this->assertEquals('https', $this->uriBuilder->getAbsoluteUriScheme());
116 $this->assertEquals(TRUE, $this->uriBuilder->getAddQueryString());
117 $this->assertEquals(array('test' => 'addQueryStringExcludeArguments'), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
118 $this->assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix());
119 $this->assertEquals(TRUE, $this->uriBuilder->getLinkAccessRestrictedPages());
120 $this->assertEquals(123, $this->uriBuilder->getTargetPageUid());
121 $this->assertEquals(321, $this->uriBuilder->getTargetPageType());
122 $this->assertEquals(TRUE, $this->uriBuilder->getNoCache());
123 $this->assertEquals(FALSE, $this->uriBuilder->getUseCacheHash());
124 }
125
126 /**
127 * @test
128 */
129 public function uriForPrefixesArgumentsWithExtensionAndPluginNameAndSetsControllerArgument() {
130 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
131 $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'bar', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'));
132 $GLOBALS['TSFE'] = NULL;
133 $this->uriBuilder->uriFor(NULL, array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')), 'SomeController', 'SomeExtension', 'SomePlugin');
134 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
135 }
136
137 /**
138 * @test
139 */
140 public function uriForRecursivelyMergesAndOverrulesControllerArgumentsWithArguments() {
141 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
142 $arguments = array('tx_someextension_someplugin' => array('foo' => 'bar'), 'additionalParam' => 'additionalValue');
143 $controllerArguments = array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'));
144 $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'), 'additionalParam' => 'additionalValue');
145
146 $this->uriBuilder->setArguments($arguments);
147 $this->uriBuilder->uriFor(NULL, $controllerArguments, 'SomeController', 'SomeExtension', 'SomePlugin');
148 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
149 }
150
151 /**
152 * @test
153 */
154 public function uriForOnlySetsActionArgumentIfSpecified() {
155 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
156 $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeController'));
157
158 $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension', 'SomePlugin');
159 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
160 }
161
162 /**
163 * @test
164 */
165 public function uriForSetsControllerFromRequestIfControllerIsNotSet() {
166 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
167 $this->mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
168
169 $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeControllerFromRequest'));
170
171 $this->uriBuilder->uriFor(NULL, array(), NULL, 'SomeExtension', 'SomePlugin');
172 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
173 }
174
175 /**
176 * @test
177 */
178 public function uriForSetsExtensionNameFromRequestIfExtensionNameIsNotSet() {
179 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_someextensionnamefromrequest_someplugin'));
180 $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
181
182 $expectedArguments = array('tx_someextensionnamefromrequest_someplugin' => array('controller' => 'SomeController'));
183
184 $this->uriBuilder->uriFor(NULL, array(), 'SomeController', NULL, 'SomePlugin');
185 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
186 }
187
188 /**
189 * @test
190 */
191 public function uriForSetsPluginNameFromRequestIfPluginNameIsNotSet() {
192 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_somepluginnamefromrequest'));
193 $this->mockRequest->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
194
195 $expectedArguments = array('tx_someextension_somepluginnamefromrequest' => array('controller' => 'SomeController'));
196
197 $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension');
198 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
199 }
200
201 /**
202 * @test
203 */
204 public function uriForDoesNotDisableCacheHashForNonCacheableActions() {
205 $this->mockExtensionService->expects($this->any())->method('isActionCacheable')->will($this->returnValue(FALSE));
206 $this->uriBuilder->uriFor('someNonCacheableAction', array(), 'SomeController', 'SomeExtension');
207 $this->assertTrue($this->uriBuilder->getUseCacheHash());
208 }
209
210 /**
211 * @test
212 */
213 public function buildBackendUriKeepsQueryParametersIfAddQueryStringIsSet() {
214 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
215
216 $this->uriBuilder->setAddQueryString(TRUE);
217
218 $expectedResult = 'mod.php?M=moduleKey&id=pageId&foo=bar';
219 $actualResult = $this->uriBuilder->buildBackendUri();
220
221 $this->assertEquals($expectedResult, $actualResult);
222 }
223
224 /**
225 * @test
226 */
227 public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet() {
228 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
229
230 $this->uriBuilder->setAddQueryString(TRUE);
231 $this->uriBuilder->setArgumentsToBeExcludedFromQueryString(array('M', 'id'));
232
233 $expectedResult = 'mod.php?foo=bar';
234 $actualResult = $this->uriBuilder->buildBackendUri();
235
236 $this->assertEquals($expectedResult, $actualResult);
237 }
238
239 /**
240 * @test
241 */
242 public function buildBackendUriKeepsModuleQueryParametersIfAddQueryStringIsNotSet() {
243 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
244
245 $expectedResult = 'mod.php?M=moduleKey&id=pageId';
246 $actualResult = $this->uriBuilder->buildBackendUri();
247
248 $this->assertEquals($expectedResult, $actualResult);
249 }
250
251 /**
252 * @test
253 */
254 public function buildBackendUriMergesAndOverrulesQueryParametersWithArguments() {
255 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
256
257 $this->uriBuilder->setArguments(array('M' => 'overwrittenModuleKey', 'somePrefix' => array('bar' => 'baz')));
258
259 $expectedResult = 'mod.php?M=overwrittenModuleKey&id=pageId&somePrefix%5Bbar%5D=baz';
260 $actualResult = $this->uriBuilder->buildBackendUri();
261
262 $this->assertEquals($expectedResult, $actualResult);
263 }
264
265 /**
266 * @test
267 */
268 public function buildBackendUriConvertsDomainObjectsAfterArgumentsHaveBeenMerged() {
269 t3lib_div::_GETset(array('M' => 'moduleKey'));
270
271 $mockDomainObject = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
272 $mockDomainObject->_set('uid', '123');
273
274 $this->uriBuilder->setArguments(array('somePrefix' => array('someDomainObject' => $mockDomainObject)));
275
276 $expectedResult = 'mod.php?M=moduleKey&somePrefix%5BsomeDomainObject%5D=123';
277 $actualResult = $this->uriBuilder->buildBackendUri();
278
279 $this->assertEquals($expectedResult, $actualResult);
280 }
281
282 /**
283 * @test
284 */
285 public function buildBackendUriRespectsSection() {
286 t3lib_div::_GETset(array('M' => 'moduleKey'));
287
288 $this->uriBuilder->setSection('someSection');
289
290 $expectedResult = 'mod.php?M=moduleKey#someSection';
291 $actualResult = $this->uriBuilder->buildBackendUri();
292
293 $this->assertEquals($expectedResult, $actualResult);
294 }
295
296 /**
297 * @test
298 */
299 public function buildBackendUriCreatesAbsoluteUrisIfSpecified() {
300 t3lib_div::_GETset(array('M' => 'moduleKey'));
301
302 $this->mockRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue('http://baseuri/' . TYPO3_mainDir));
303 $this->uriBuilder->setCreateAbsoluteUri(TRUE);
304
305 $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'mod.php?M=moduleKey';
306 $actualResult = $this->uriBuilder->buildBackendUri();
307 $this->assertSame($expectedResult, $actualResult);
308 }
309
310 /**
311 * @test
312 */
313 public function buildFrontendUriCreatesTypoLink() {
314 $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
315 $uriBuilder->_set('contentObject', $this->mockContentObject);
316 $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('someTypoLinkConfiguration')));
317
318 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('someTypoLinkConfiguration'));
319
320 $uriBuilder->buildFrontendUri();
321 }
322
323 /**
324 * @test
325 */
326 public function buildFrontendUriCreatesRelativeUrisByDefault() {
327 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
328
329 $expectedResult = 'relative/uri';
330 $actualResult = $this->uriBuilder->buildFrontendUri();
331
332 $this->assertSame($expectedResult, $actualResult);
333 }
334
335 /**
336 * @test
337 */
338 public function buildFrontendUriDoesNotStripLeadingSlashesFromRelativeUris() {
339 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
340
341 $expectedResult = '/relative/uri';
342 $actualResult = $this->uriBuilder->buildFrontendUri();
343
344 $this->assertSame($expectedResult, $actualResult);
345 }
346
347 /**
348 * @test
349 */
350 public function buildFrontendUriCreatesAbsoluteUrisIfSpecified() {
351 $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
352 $uriBuilder->_set('contentObject', $this->mockContentObject);
353 $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
354
355 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE))->will($this->returnValue('http://baseuri/relative/uri'));
356 $uriBuilder->setCreateAbsoluteUri(TRUE);
357
358 $expectedResult = 'http://baseuri/relative/uri';
359 $actualResult = $uriBuilder->buildFrontendUri();
360 $this->assertSame($expectedResult, $actualResult);
361 }
362
363 /**
364 * @test
365 */
366 public function buildFrontendUriSetsAbsoluteUriSchemeIfSpecified() {
367 $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
368 $uriBuilder->_set('contentObject', $this->mockContentObject);
369 $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
370
371 $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'));
372 $uriBuilder->setCreateAbsoluteUri(TRUE);
373 $uriBuilder->setAbsoluteUriScheme('someScheme');
374
375 $expectedResult = 'http://baseuri/relative/uri';
376 $actualResult = $uriBuilder->buildFrontendUri();
377 $this->assertSame($expectedResult, $actualResult);
378 }
379
380 /**
381 * @test
382 */
383 public function buildFrontendUriDoesNotSetAbsoluteUriSchemeIfCreateAbsoluteUriIsFalse() {
384 $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
385 $uriBuilder->_set('contentObject', $this->mockContentObject);
386 $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
387
388 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar'))->will($this->returnValue('http://baseuri/relative/uri'));
389 $uriBuilder->setCreateAbsoluteUri(FALSE);
390 $uriBuilder->setAbsoluteUriScheme('someScheme');
391
392 $expectedResult = 'http://baseuri/relative/uri';
393 $actualResult = $uriBuilder->buildFrontendUri();
394 $this->assertSame($expectedResult, $actualResult);
395 }
396
397 /**
398 * @test
399 */
400 public function resetSetsAllOptionsToTheirDefaultValue() {
401 $this->uriBuilder
402 ->setArguments(array('test' => 'arguments'))
403 ->setSection('testSection')
404 ->setFormat('someFormat')
405 ->setCreateAbsoluteUri(TRUE)
406 ->setAddQueryString(TRUE)
407 ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
408 ->setArgumentPrefix('testArgumentPrefix')
409 ->setLinkAccessRestrictedPages(TRUE)
410 ->setTargetPageUid(123)
411 ->setTargetPageType(321)
412 ->setNoCache(TRUE)
413 ->setUseCacheHash(FALSE);
414
415 $this->uriBuilder->reset();
416
417 $this->assertEquals(array(), $this->uriBuilder->getArguments());
418 $this->assertEquals('', $this->uriBuilder->getSection());
419 $this->assertEquals('', $this->uriBuilder->getFormat());
420 $this->assertEquals(FALSE, $this->uriBuilder->getCreateAbsoluteUri());
421 $this->assertEquals(FALSE, $this->uriBuilder->getAddQueryString());
422 $this->assertEquals(array(), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
423 $this->assertEquals(NULL, $this->uriBuilder->getArgumentPrefix());
424 $this->assertEquals(FALSE, $this->uriBuilder->getLinkAccessRestrictedPages());
425 $this->assertEquals(NULL, $this->uriBuilder->getTargetPageUid());
426 $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
427 $this->assertEquals(FALSE, $this->uriBuilder->getNoCache());
428 $this->assertEquals(TRUE, $this->uriBuilder->getUseCacheHash());
429 }
430
431 /**
432 * @test
433 */
434 public function buildTypolinkConfigurationRespectsSpecifiedTargetPageUid() {
435 $GLOBALS['TSFE']->id = 123;
436 $this->uriBuilder->setTargetPageUid(321);
437
438 $expectedConfiguration = array('parameter' => 321, 'useCacheHash' => 1);
439 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
440
441 $this->assertEquals($expectedConfiguration, $actualConfiguration);
442 }
443
444 /**
445 * @test
446 */
447 public function buildTypolinkConfigurationUsesCurrentPageUidIfTargetPageUidIsNotSet() {
448 $GLOBALS['TSFE']->id = 123;
449
450 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1);
451 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
452
453 $this->assertEquals($expectedConfiguration, $actualConfiguration);
454 }
455
456 /**
457 * @test
458 */
459 public function buildTypolinkConfigurationProperlySetsAdditionalArguments() {
460 $this->uriBuilder->setTargetPageUid(123);
461 $this->uriBuilder->setArguments(array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')));
462
463 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&foo=bar&baz[extbase]=fluid');
464 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
465
466 $this->assertEquals($expectedConfiguration, $actualConfiguration);
467 }
468
469 /**
470 * @test
471 */
472 public function buildTypolinkConfigurationConvertsDomainObjects() {
473 $mockDomainObject1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
474 $mockDomainObject1->_set('uid', '123');
475
476 $mockDomainObject2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
477 $mockDomainObject2->_set('uid', '321');
478
479 $this->uriBuilder->setTargetPageUid(123);
480 $this->uriBuilder->setArguments(array('someDomainObject' => $mockDomainObject1, 'baz' => array('someOtherDomainObject' => $mockDomainObject2)));
481
482 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&someDomainObject=123&baz[someOtherDomainObject]=321');
483 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
484
485 $this->assertEquals($expectedConfiguration, $actualConfiguration);
486 }
487
488 /**
489 * @test
490 */
491 public function buildTypolinkConfigurationConsidersPageType() {
492 $this->uriBuilder->setTargetPageUid(123);
493 $this->uriBuilder->setTargetPageType(2);
494
495 $expectedConfiguration = array('parameter' => '123,2', 'useCacheHash' => 1);
496 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
497
498 $this->assertEquals($expectedConfiguration, $actualConfiguration);
499 }
500
501 /**
502 * @test
503 */
504 public function buildTypolinkConfigurationDisablesCacheHashIfNoCacheIsSet() {
505 $this->uriBuilder->setTargetPageUid(123);
506 $this->uriBuilder->setNoCache(TRUE);
507
508 $expectedConfiguration = array('parameter' => 123, 'no_cache' => 1);
509 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
510
511 $this->assertEquals($expectedConfiguration, $actualConfiguration);
512 }
513
514 /**
515 * @test
516 */
517 public function buildTypolinkConfigurationDoesNotSetUseCacheHashOptionIfUseCacheHashIsDisabled() {
518 $this->uriBuilder->setTargetPageUid(123);
519 $this->uriBuilder->setUseCacheHash(FALSE);
520
521 $expectedConfiguration = array('parameter' => 123);
522 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
523
524 $this->assertEquals($expectedConfiguration, $actualConfiguration);
525 }
526
527 /**
528 * @test
529 */
530 public function buildTypolinkConfigurationConsidersSection() {
531 $this->uriBuilder->setTargetPageUid(123);
532 $this->uriBuilder->setSection('SomeSection');
533
534 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'section' => 'SomeSection');
535 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
536
537 $this->assertEquals($expectedConfiguration, $actualConfiguration);
538 }
539
540 /**
541 * @test
542 */
543 public function buildTypolinkConfigurationLinkAccessRestrictedPagesSetting() {
544 $this->uriBuilder->setTargetPageUid(123);
545 $this->uriBuilder->setLinkAccessRestrictedPages(TRUE);
546
547 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'linkAccessRestrictedPages' => 1);
548 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
549
550 $this->assertEquals($expectedConfiguration, $actualConfiguration);
551 }
552
553 /**
554 * @test
555 */
556 public function convertDomainObjectsToIdentityArraysConvertsDomainObjects() {
557 $mockDomainObject1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
558 $mockDomainObject1->_set('uid', '123');
559
560 $mockDomainObject2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
561 $mockDomainObject2->_set('uid', '321');
562
563 $expectedResult = array('foo' => array('bar' => 'baz'), 'domainObject1' => '123', 'second' => array('domainObject2' =>'321'));
564 $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', array('foo' => array('bar' => 'baz'), 'domainObject1' => $mockDomainObject1, 'second' => array('domainObject2' => $mockDomainObject2)));
565
566 $this->assertEquals($expectedResult, $actualResult);
567 }
568
569 /**
570 * @test
571 */
572 public function conversionOfTansientObjectsIsInvoked() {
573 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
574 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
575 $mockValueObject = new $className;
576 $mockValueObject->name = 'foo';
577
578 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('convertTransientObjectToArray'));
579 $mockUriBuilder->expects($this->once())->method('convertTransientObjectToArray')->will($this->returnValue(array('foo' => 'bar')));
580 $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockValueObject));
581
582 $expectedResult = array('object' => array('foo' => 'bar'));
583 $this->assertEquals($expectedResult, $actualResult);
584 }
585
586 /**
587 * @test
588 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentValue
589 */
590 public function conversionOfTansientObjectsThrowsExceptionForOtherThanValueObjects() {
591 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
592 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractEntity { public $name; public $uid; }');
593 $mockEntity = new $className;
594 $mockEntity->name = 'foo';
595
596 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
597 $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockEntity));
598 }
599
600 /**
601 * @test
602 */
603 public function tansientObjectsAreConvertedToAnArrayOfProperties() {
604 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
605 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
606 $mockValueObject = new $className;
607 $mockValueObject->name = 'foo';
608
609 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
610 $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
611
612 $expectedResult = array('name' => 'foo', 'uid' => NULL, 'pid' => NULL);
613 $this->assertEquals($expectedResult, $actualResult);
614 }
615
616 /**
617 * @test
618 */
619 public function tansientObjectsAreRecursivelyConverted() {
620 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
621 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
622 $mockInnerValueObject2 = new $className;
623 $mockInnerValueObject2->name = 'foo';
624 $mockInnerValueObject2->uid = 99;
625
626 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
627 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $object; public $uid; }');
628 $mockInnerValueObject1 = new $className;
629 $mockInnerValueObject1->object = $mockInnerValueObject2;
630
631 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
632 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $object; public $uid; }');
633 $mockValueObject = new $className;
634 $mockValueObject->object = $mockInnerValueObject1;
635
636 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
637 $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
638
639 $expectedResult = array(
640 'object' => array(
641 'object' => 99,
642 'uid' => NULL,
643 'pid' => NULL
644 ),
645 'uid' => NULL,
646 'pid' => NULL
647 );
648 $this->assertEquals($expectedResult, $actualResult);
649 }
650
651 /**
652 * @test
653 */
654 public function removeDefaultControllerAndActionDoesNotModifyArgumentsifSpecifiedControlerAndActionIsNotEqualToDefaults() {
655 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
656 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'SomeController')->will($this->returnValue('defaultAction'));
657
658 $arguments = array('controller' => 'SomeController', 'action' => 'someAction', 'foo' => 'bar');
659 $extensionName = 'ExtensionName';
660 $pluginName = 'PluginName';
661 $expectedResult = array('controller' => 'SomeController', 'action' => 'someAction', 'foo' => 'bar');
662
663 $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
664 $this->assertEquals($expectedResult, $actualResult);
665 }
666
667 /**
668 * @test
669 */
670 public function removeDefaultControllerAndActionRemovesControllerIfItIsEqualToTheDefault() {
671 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
672 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
673
674 $arguments = array('controller' => 'DefaultController', 'action' => 'someAction', 'foo' => 'bar');
675 $extensionName = 'ExtensionName';
676 $pluginName = 'PluginName';
677 $expectedResult = array('action' => 'someAction', 'foo' => 'bar');
678
679 $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
680 $this->assertEquals($expectedResult, $actualResult);
681 }
682
683 /**
684 * @test
685 */
686 public function removeDefaultControllerAndActionRemovesActionIfItIsEqualToTheDefault() {
687 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
688 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'SomeController')->will($this->returnValue('defaultAction'));
689
690 $arguments = array('controller' => 'SomeController', 'action' => 'defaultAction', 'foo' => 'bar');
691 $extensionName = 'ExtensionName';
692 $pluginName = 'PluginName';
693 $expectedResult = array('controller' => 'SomeController', 'foo' => 'bar');
694
695 $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
696 $this->assertEquals($expectedResult, $actualResult);
697 }
698
699 /**
700 * @test
701 */
702 public function removeDefaultControllerAndActionRemovesControllerAndActionIfBothAreEqualToTheDefault() {
703 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
704 $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
705
706 $arguments = array('controller' => 'DefaultController', 'action' => 'defaultAction', 'foo' => 'bar');
707 $extensionName = 'ExtensionName';
708 $pluginName = 'PluginName';
709 $expectedResult = array('foo' => 'bar');
710
711 $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
712 $this->assertEquals($expectedResult, $actualResult);
713 }
714
715 }
716 ?>