[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 tslib_cObj
44 */
45 protected $mockContentObject;
46
47 /**
48 * @var Tx_Extbase_MVC_Web_Request
49 */
50 protected $mockRequest;
51
52 /**
53 * @var Tx_Extbase_Service_ExtensionService
54 */
55 protected $mockExtensionService;
56
57 /**
58 * @var Tx_Extbase_MVC_Web_Routing_UriBuilder
59 */
60 protected $uriBuilder;
61
62 public function setUp() {
63 $this->tsfeBackup = $GLOBALS['TSFE'];
64 $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE);
65
66 $this->getBackup = t3lib_div::_GET();
67
68 $this->mockContentObject = $this->getMock('tslib_cObj');
69 $this->mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
70 $this->mockExtensionService = $this->getMock('Tx_Extbase_Service_ExtensionService');
71
72 $this->uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('build'));
73 $this->uriBuilder->setRequest($this->mockRequest);
74 $this->uriBuilder->_set('contentObject', $this->mockContentObject);
75
76 $this->uriBuilder->injectExtensionService($this->mockExtensionService);
77 }
78
79 public function tearDown() {
80 $GLOBALS['TSFE'] = $this->tsfeBackup;
81 t3lib_div::_GETset($this->getBackup);
82 }
83
84 /**
85 * @test
86 */
87 public function settersAndGettersWorkAsExpected() {
88 $this->uriBuilder
89 ->reset()
90 ->setArguments(array('test' => 'arguments'))
91 ->setSection('testSection')
92 ->setFormat('testFormat')
93 ->setCreateAbsoluteUri(TRUE)
94 ->setAddQueryString(TRUE)
95 ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
96 ->setArgumentPrefix('testArgumentPrefix')
97 ->setLinkAccessRestrictedPages(TRUE)
98 ->setTargetPageUid(123)
99 ->setTargetPageType(321)
100 ->setNoCache(TRUE)
101 ->setUseCacheHash(FALSE);
102
103 $this->assertEquals(array('test' => 'arguments'), $this->uriBuilder->getArguments());
104 $this->assertEquals('testSection', $this->uriBuilder->getSection());
105 $this->assertEquals('testFormat', $this->uriBuilder->getFormat());
106 $this->assertEquals(TRUE, $this->uriBuilder->getCreateAbsoluteUri());
107 $this->assertEquals(TRUE, $this->uriBuilder->getAddQueryString());
108 $this->assertEquals(array('test' => 'addQueryStringExcludeArguments'), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
109 $this->assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix());
110 $this->assertEquals(TRUE, $this->uriBuilder->getLinkAccessRestrictedPages());
111 $this->assertEquals(123, $this->uriBuilder->getTargetPageUid());
112 $this->assertEquals(321, $this->uriBuilder->getTargetPageType());
113 $this->assertEquals(TRUE, $this->uriBuilder->getNoCache());
114 $this->assertEquals(FALSE, $this->uriBuilder->getUseCacheHash());
115 }
116
117 /**
118 * @test
119 */
120 public function uriForPrefixesArgumentsWithExtensionAndPluginNameAndSetsControllerArgument() {
121 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
122 $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'bar', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'));
123 $GLOBALS['TSFE'] = NULL;
124 $this->uriBuilder->uriFor(NULL, array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')), 'SomeController', 'SomeExtension', 'SomePlugin');
125 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
126 }
127
128 /**
129 * @test
130 */
131 public function uriForRecursivelyMergesAndOverrulesControllerArgumentsWithArguments() {
132 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
133 $arguments = array('tx_someextension_someplugin' => array('foo' => 'bar'), 'additionalParam' => 'additionalValue');
134 $controllerArguments = array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'));
135 $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'overruled', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'), 'additionalParam' => 'additionalValue');
136
137 $this->uriBuilder->setArguments($arguments);
138 $this->uriBuilder->uriFor(NULL, $controllerArguments, 'SomeController', 'SomeExtension', 'SomePlugin');
139 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
140 }
141
142 /**
143 * @test
144 */
145 public function uriForOnlySetsActionArgumentIfSpecified() {
146 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
147 $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeController'));
148
149 $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension', 'SomePlugin');
150 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
151 }
152
153 /**
154 * @test
155 */
156 public function uriForSetsControllerFromRequestIfControllerIsNotSet() {
157 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_someplugin'));
158 $this->mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
159
160 $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeControllerFromRequest'));
161
162 $this->uriBuilder->uriFor(NULL, array(), NULL, 'SomeExtension', 'SomePlugin');
163 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
164 }
165
166 /**
167 * @test
168 */
169 public function uriForSetsExtensionNameFromRequestIfExtensionNameIsNotSet() {
170 $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_someextensionnamefromrequest_someplugin'));
171 $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
172
173 $expectedArguments = array('tx_someextensionnamefromrequest_someplugin' => array('controller' => 'SomeController'));
174
175 $this->uriBuilder->uriFor(NULL, array(), 'SomeController', NULL, 'SomePlugin');
176 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
177 }
178
179 /**
180 * @test
181 */
182 public function uriForSetsPluginNameFromRequestIfPluginNameIsNotSet() {
183 $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->will($this->returnValue('tx_someextension_somepluginnamefromrequest'));
184 $this->mockRequest->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
185
186 $expectedArguments = array('tx_someextension_somepluginnamefromrequest' => array('controller' => 'SomeController'));
187
188 $this->uriBuilder->uriFor(NULL, array(), 'SomeController', 'SomeExtension');
189 $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
190 }
191
192 /**
193 * @test
194 */
195 public function uriForDoesNotDisableCacheHashForNonCacheableActions() {
196 $this->mockExtensionService->expects($this->any())->method('isActionCacheable')->will($this->returnValue(FALSE));
197 $this->uriBuilder->uriFor('someNonCacheableAction', array(), 'SomeController', 'SomeExtension');
198 $this->assertTrue($this->uriBuilder->getUseCacheHash());
199 }
200
201 /**
202 * @test
203 */
204 public function buildBackendUriKeepsQueryParametersIfAddQueryStringIsSet() {
205 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
206
207 $this->uriBuilder->setAddQueryString(TRUE);
208
209 $expectedResult = 'mod.php?M=moduleKey&id=pageId&foo=bar';
210 $actualResult = $this->uriBuilder->buildBackendUri();
211
212 $this->assertEquals($expectedResult, $actualResult);
213 }
214
215 /**
216 * @test
217 */
218 public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet() {
219 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
220
221 $this->uriBuilder->setAddQueryString(TRUE);
222 $this->uriBuilder->setArgumentsToBeExcludedFromQueryString(array('M', 'id'));
223
224 $expectedResult = 'mod.php?foo=bar';
225 $actualResult = $this->uriBuilder->buildBackendUri();
226
227 $this->assertEquals($expectedResult, $actualResult);
228 }
229
230 /**
231 * @test
232 */
233 public function buildBackendUriKeepsModuleQueryParametersIfAddQueryStringIsNotSet() {
234 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
235
236 $expectedResult = 'mod.php?M=moduleKey&id=pageId';
237 $actualResult = $this->uriBuilder->buildBackendUri();
238
239 $this->assertEquals($expectedResult, $actualResult);
240 }
241
242 /**
243 * @test
244 */
245 public function buildBackendUriMergesAndOverrulesQueryParametersWithArguments() {
246 t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
247
248 $this->uriBuilder->setArguments(array('M' => 'overwrittenModuleKey', 'somePrefix' => array('bar' => 'baz')));
249
250 $expectedResult = 'mod.php?M=overwrittenModuleKey&id=pageId&somePrefix%5Bbar%5D=baz';
251 $actualResult = $this->uriBuilder->buildBackendUri();
252
253 $this->assertEquals($expectedResult, $actualResult);
254 }
255
256 /**
257 * @test
258 */
259 public function buildBackendUriConvertsDomainObjectsAfterArgumentsHaveBeenMerged() {
260 t3lib_div::_GETset(array('M' => 'moduleKey'));
261
262 $mockDomainObject = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
263 $mockDomainObject->_set('uid', '123');
264
265 $this->uriBuilder->setArguments(array('somePrefix' => array('someDomainObject' => $mockDomainObject)));
266
267 $expectedResult = 'mod.php?M=moduleKey&somePrefix%5BsomeDomainObject%5D=123';
268 $actualResult = $this->uriBuilder->buildBackendUri();
269
270 $this->assertEquals($expectedResult, $actualResult);
271 }
272
273 /**
274 * @test
275 */
276 public function buildBackendUriRespectsSection() {
277 t3lib_div::_GETset(array('M' => 'moduleKey'));
278
279 $this->uriBuilder->setSection('someSection');
280
281 $expectedResult = 'mod.php?M=moduleKey#someSection';
282 $actualResult = $this->uriBuilder->buildBackendUri();
283
284 $this->assertEquals($expectedResult, $actualResult);
285 }
286
287 /**
288 * @test
289 */
290 public function buildBackendUriCreatesAbsoluteUrisIfSpecified() {
291 t3lib_div::_GETset(array('M' => 'moduleKey'));
292
293 $this->mockRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue('http://baseuri/' . TYPO3_mainDir));
294 $this->uriBuilder->setCreateAbsoluteUri(TRUE);
295
296 $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'mod.php?M=moduleKey';
297 $actualResult = $this->uriBuilder->buildBackendUri();
298 $this->assertSame($expectedResult, $actualResult);
299 }
300
301 /**
302 * @test
303 */
304 public function buildFrontendUriCreatesTypoLink() {
305 $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
306 $uriBuilder->_set('contentObject', $this->mockContentObject);
307 $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('someTypoLinkConfiguration')));
308
309 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('someTypoLinkConfiguration'));
310
311 $uriBuilder->buildFrontendUri();
312 }
313
314 /**
315 * @test
316 */
317 public function buildFrontendUriCreatesRelativeUrisByDefault() {
318 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
319
320 $expectedResult = 'relative/uri';
321 $actualResult = $this->uriBuilder->buildFrontendUri();
322
323 $this->assertSame($expectedResult, $actualResult);
324 }
325
326 /**
327 * @test
328 */
329 public function buildFrontendUriDoesNotStripLeadingSlashesFromRelativeUris() {
330 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
331
332 $expectedResult = '/relative/uri';
333 $actualResult = $this->uriBuilder->buildFrontendUri();
334
335 $this->assertSame($expectedResult, $actualResult);
336 }
337
338 /**
339 * @test
340 */
341 public function buildFrontendUriCreatesAbsoluteUrisIfSpecified() {
342 $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
343 $uriBuilder->_set('contentObject', $this->mockContentObject);
344 $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
345
346 $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE))->will($this->returnValue('http://baseuri/relative/uri'));
347 $uriBuilder->setCreateAbsoluteUri(TRUE);
348
349 $expectedResult = 'http://baseuri/relative/uri';
350 $actualResult = $uriBuilder->buildFrontendUri();
351 $this->assertSame($expectedResult, $actualResult);
352 }
353
354 /**
355 * @test
356 */
357 public function resetSetsAllOptionsToTheirDefaultValue() {
358 $this->uriBuilder
359 ->setArguments(array('test' => 'arguments'))
360 ->setSection('testSection')
361 ->setFormat('someFormat')
362 ->setCreateAbsoluteUri(TRUE)
363 ->setAddQueryString(TRUE)
364 ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
365 ->setArgumentPrefix('testArgumentPrefix')
366 ->setLinkAccessRestrictedPages(TRUE)
367 ->setTargetPageUid(123)
368 ->setTargetPageType(321)
369 ->setNoCache(TRUE)
370 ->setUseCacheHash(FALSE);
371
372 $this->uriBuilder->reset();
373
374 $this->assertEquals(array(), $this->uriBuilder->getArguments());
375 $this->assertEquals('', $this->uriBuilder->getSection());
376 $this->assertEquals('', $this->uriBuilder->getFormat());
377 $this->assertEquals(FALSE, $this->uriBuilder->getCreateAbsoluteUri());
378 $this->assertEquals(FALSE, $this->uriBuilder->getAddQueryString());
379 $this->assertEquals(array(), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
380 $this->assertEquals(NULL, $this->uriBuilder->getArgumentPrefix());
381 $this->assertEquals(FALSE, $this->uriBuilder->getLinkAccessRestrictedPages());
382 $this->assertEquals(NULL, $this->uriBuilder->getTargetPageUid());
383 $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
384 $this->assertEquals(FALSE, $this->uriBuilder->getNoCache());
385 $this->assertEquals(TRUE, $this->uriBuilder->getUseCacheHash());
386 }
387
388 /**
389 * @test
390 */
391 public function buildTypolinkConfigurationRespectsSpecifiedTargetPageUid() {
392 $GLOBALS['TSFE']->id = 123;
393 $this->uriBuilder->setTargetPageUid(321);
394
395 $expectedConfiguration = array('parameter' => 321, 'useCacheHash' => 1);
396 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
397
398 $this->assertEquals($expectedConfiguration, $actualConfiguration);
399 }
400
401 /**
402 * @test
403 */
404 public function buildTypolinkConfigurationUsesCurrentPageUidIfTargetPageUidIsNotSet() {
405 $GLOBALS['TSFE']->id = 123;
406
407 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1);
408 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
409
410 $this->assertEquals($expectedConfiguration, $actualConfiguration);
411 }
412
413 /**
414 * @test
415 */
416 public function buildTypolinkConfigurationProperlySetsAdditionalArguments() {
417 $this->uriBuilder->setTargetPageUid(123);
418 $this->uriBuilder->setArguments(array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')));
419
420 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&foo=bar&baz[extbase]=fluid');
421 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
422
423 $this->assertEquals($expectedConfiguration, $actualConfiguration);
424 }
425
426 /**
427 * @test
428 */
429 public function buildTypolinkConfigurationConvertsDomainObjects() {
430 $mockDomainObject1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
431 $mockDomainObject1->_set('uid', '123');
432
433 $mockDomainObject2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
434 $mockDomainObject2->_set('uid', '321');
435
436 $this->uriBuilder->setTargetPageUid(123);
437 $this->uriBuilder->setArguments(array('someDomainObject' => $mockDomainObject1, 'baz' => array('someOtherDomainObject' => $mockDomainObject2)));
438
439 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'additionalParams' => '&someDomainObject=123&baz[someOtherDomainObject]=321');
440 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
441
442 $this->assertEquals($expectedConfiguration, $actualConfiguration);
443 }
444
445 /**
446 * @test
447 */
448 public function buildTypolinkConfigurationConsidersPageType() {
449 $this->uriBuilder->setTargetPageUid(123);
450 $this->uriBuilder->setTargetPageType(2);
451
452 $expectedConfiguration = array('parameter' => '123,2', 'useCacheHash' => 1);
453 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
454
455 $this->assertEquals($expectedConfiguration, $actualConfiguration);
456 }
457
458 /**
459 * @test
460 */
461 public function buildTypolinkConfigurationDisablesCacheHashIfNoCacheIsSet() {
462 $this->uriBuilder->setTargetPageUid(123);
463 $this->uriBuilder->setNoCache(TRUE);
464
465 $expectedConfiguration = array('parameter' => 123, 'no_cache' => 1);
466 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
467
468 $this->assertEquals($expectedConfiguration, $actualConfiguration);
469 }
470
471 /**
472 * @test
473 */
474 public function buildTypolinkConfigurationDoesNotSetUseCacheHashOptionIfUseCacheHashIsDisabled() {
475 $this->uriBuilder->setTargetPageUid(123);
476 $this->uriBuilder->setUseCacheHash(FALSE);
477
478 $expectedConfiguration = array('parameter' => 123);
479 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
480
481 $this->assertEquals($expectedConfiguration, $actualConfiguration);
482 }
483
484 /**
485 * @test
486 */
487 public function buildTypolinkConfigurationConsidersSection() {
488 $this->uriBuilder->setTargetPageUid(123);
489 $this->uriBuilder->setSection('SomeSection');
490
491 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'section' => 'SomeSection');
492 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
493
494 $this->assertEquals($expectedConfiguration, $actualConfiguration);
495 }
496
497 /**
498 * @test
499 */
500 public function buildTypolinkConfigurationLinkAccessRestrictedPagesSetting() {
501 $this->uriBuilder->setTargetPageUid(123);
502 $this->uriBuilder->setLinkAccessRestrictedPages(TRUE);
503
504 $expectedConfiguration = array('parameter' => 123, 'useCacheHash' => 1, 'linkAccessRestrictedPages' => 1);
505 $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration');
506
507 $this->assertEquals($expectedConfiguration, $actualConfiguration);
508 }
509
510 /**
511 * @test
512 */
513 public function convertDomainObjectsToIdentityArraysConvertsDomainObjects() {
514 $mockDomainObject1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
515 $mockDomainObject1->_set('uid', '123');
516
517 $mockDomainObject2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_DomainObject_AbstractEntity'), array('dummy'));
518 $mockDomainObject2->_set('uid', '321');
519
520 $expectedResult = array('foo' => array('bar' => 'baz'), 'domainObject1' => '123', 'second' => array('domainObject2' =>'321'));
521 $actualResult = $this->uriBuilder->_call('convertDomainObjectsToIdentityArrays', array('foo' => array('bar' => 'baz'), 'domainObject1' => $mockDomainObject1, 'second' => array('domainObject2' => $mockDomainObject2)));
522
523 $this->assertEquals($expectedResult, $actualResult);
524 }
525
526 /**
527 * @test
528 */
529 public function conversionOfTansientObjectsIsInvoked() {
530 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
531 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
532 $mockValueObject = new $className;
533 $mockValueObject->name = 'foo';
534
535 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('convertTransientObjectToArray'));
536 $mockUriBuilder->expects($this->once())->method('convertTransientObjectToArray')->will($this->returnValue(array('foo' => 'bar')));
537 $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockValueObject));
538
539 $expectedResult = array('object' => array('foo' => 'bar'));
540 $this->assertEquals($expectedResult, $actualResult);
541 }
542
543 /**
544 * @test
545 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentValue
546 */
547 public function conversionOfTansientObjectsThrowsExceptionForOtherThanValueObjects() {
548 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
549 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractEntity { public $name; public $uid; }');
550 $mockEntity = new $className;
551 $mockEntity->name = 'foo';
552
553 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
554 $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockEntity));
555 }
556
557 /**
558 * @test
559 */
560 public function tansientObjectsAreConvertedToAnArrayOfProperties() {
561 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
562 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
563 $mockValueObject = new $className;
564 $mockValueObject->name = 'foo';
565
566 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
567 $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
568
569 $expectedResult = array('name' => 'foo', 'uid' => NULL, 'pid' => NULL);
570 $this->assertEquals($expectedResult, $actualResult);
571 }
572
573 /**
574 * @test
575 */
576 public function tansientObjectsAreRecursivelyConverted() {
577 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
578 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $name; public $uid; }');
579 $mockInnerValueObject2 = new $className;
580 $mockInnerValueObject2->name = 'foo';
581 $mockInnerValueObject2->uid = 99;
582
583 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
584 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $object; public $uid; }');
585 $mockInnerValueObject1 = new $className;
586 $mockInnerValueObject1->object = $mockInnerValueObject2;
587
588 $className = uniqid('Tx_Extbase_Tests_Fixtures_Object');
589 eval('class ' . $className . ' extends Tx_Extbase_DomainObject_AbstractValueObject { public $object; public $uid; }');
590 $mockValueObject = new $className;
591 $mockValueObject->object = $mockInnerValueObject1;
592
593 $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
594 $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
595
596 $expectedResult = array(
597 'object' => array(
598 'object' => 99,
599 'uid' => NULL,
600 'pid' => NULL
601 ),
602 'uid' => NULL,
603 'pid' => NULL
604 );
605 $this->assertEquals($expectedResult, $actualResult);
606 }
607
608
609 }
610 ?>