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