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