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