[TASK] Add unit tests for forceAbsoluteUrl()
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / ContentObject / ContentObjectRendererTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Testcase for TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
18 *
19 * @author Oliver Hader <oliver@typo3.org>
20 * @author Oliver Klee <typo3-coding@oliverklee.de>
21 */
22 class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
26 */
27 protected $cObj = NULL;
28
29 /**
30 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
31 */
32 protected $tsfe = NULL;
33
34 /**
35 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\TypoScript\TemplateService
36 */
37 protected $template = NULL;
38
39 /**
40 * Set up
41 */
42 public function setUp() {
43 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array());
44 $this->template = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('getFileName', 'linkData'));
45 $this->tsfe = $this->getAccessibleMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
46 $this->tsfe->tmpl = $this->template;
47 $this->tsfe->config = array();
48 $this->tsfe->page = array();
49 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('getRawRecord'));
50 $this->tsfe->sys_page = $sysPageMock;
51 $GLOBALS['TSFE'] = $this->tsfe;
52 $GLOBALS['TSFE']->csConvObj = new \TYPO3\CMS\Core\Charset\CharsetConverter();
53 $GLOBALS['TSFE']->renderCharset = 'utf-8';
54 $GLOBALS['TYPO3_CONF_VARS']['SYS']['TYPO3\\CMS\\Core\\Charset\\CharsetConverter_utils'] = 'mbstring';
55 $this->cObj = $this->getAccessibleMock(
56 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
57 array('getResourceFactory', 'getEnvironmentVariable')
58 );
59 $this->cObj->start(array(), 'tt_content');
60 }
61
62 ////////////////////////
63 // Utitility functions
64 ////////////////////////
65 /**
66 * Converts the subject and the expected result into the target charset.
67 *
68 * @param string $charset the target charset
69 * @param string $subject the subject, will be modified
70 * @param string $expected the expected result, will be modified
71 */
72 protected function handleCharset($charset, &$subject, &$expected) {
73 $GLOBALS['TSFE']->renderCharset = $charset;
74 $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset);
75 $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset);
76 }
77
78 /////////////////////////////////////////////
79 // Tests concerning the getImgResource hook
80 /////////////////////////////////////////////
81 /**
82 * @test
83 */
84 public function getImgResourceCallsGetImgResourcePostProcessHook() {
85 $this->template
86 ->expects($this->atLeastOnce())
87 ->method('getFileName')
88 ->with('typo3/clear.gif')
89 ->will($this->returnValue('typo3/clear.gif'));
90
91 $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array(), array(), '', FALSE);
92 $this->cObj->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
93
94 $className = uniqid('tx_coretest');
95 $getImgResourceHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectGetImageResourceHookInterface', array('getImgResourcePostProcess'), array(), $className);
96 $getImgResourceHookMock
97 ->expects($this->once())
98 ->method('getImgResourcePostProcess')
99 ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
100 $getImgResourceHookObjects = array($getImgResourceHookMock);
101 $this->cObj->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
102 $this->cObj->getImgResource('typo3/clear.gif', array());
103 }
104
105 /**
106 * Handles the arguments that have been sent to the getImgResource hook.
107 *
108 * @return array
109 * @see getImgResourceHookGetsCalled
110 */
111 public function isGetImgResourceHookCalledCallback() {
112 list($file, $fileArray, $imageResource, $parent) = func_get_args();
113 $this->assertEquals('typo3/clear.gif', $file);
114 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
115 $this->assertTrue(is_array($fileArray));
116 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer);
117 return $imageResource;
118 }
119
120
121 /*************************
122 * Tests concerning getContentObject
123 ************************/
124 public function getContentObjectValidContentObjectsDataProvider() {
125 return array(
126 array('TEXT', 'Text'),
127 array('CASE', 'Case'),
128 array('CLEARGIF', 'ClearGif'),
129 array('COBJ_ARRAY', 'ContentObjectArray'),
130 array('COA', 'ContentObjectArray'),
131 array('COA_INT', 'ContentObjectArrayInternal'),
132 array('USER', 'User'),
133 array('USER_INT', 'UserInternal'),
134 array('FILE', 'File'),
135 array('FILES', 'Files'),
136 array('IMAGE', 'Image'),
137 array('IMG_RESOURCE', 'ImageResource'),
138 array('IMGTEXT', 'ImageText'),
139 array('CONTENT', 'Content'),
140 array('RECORDS', 'Records'),
141 array('HMENU', 'HierarchicalMenu'),
142 array('CTABLE', 'ContentTable'),
143 array('OTABLE', 'OffsetTable'),
144 array('COLUMNS', 'Columns'),
145 array('HRULER', 'HorizontalRuler'),
146 array('CASEFUNC', 'Case'),
147 array('LOAD_REGISTER', 'LoadRegister'),
148 array('RESTORE_REGISTER', 'RestoreRegister'),
149 array('FORM', 'Form'),
150 array('SEARCHRESULT', 'SearchResult'),
151 array('TEMPLATE', 'Template'),
152 array('FLUIDTEMPLATE', 'FluidTemplate'),
153 array('MULTIMEDIA', 'Multimedia'),
154 array('MEDIA', 'Media'),
155 array('SWFOBJECT', 'ShockwaveFlashObject'),
156 array('FLOWPLAYER', 'FlowPlayer'),
157 array('QTOBJECT', 'QuicktimeObject'),
158 array('SVG', 'ScalableVectorGraphics'),
159 array('EDITPANEL', 'EditPanel'),
160 );
161 }
162
163 /**
164 * @test
165 * @dataProvider getContentObjectValidContentObjectsDataProvider
166 * @param string $name TypoScript name of content object
167 * @param string $className Expected class name
168 */
169 public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $className) {
170 $fullClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $className . 'ContentObject';
171 $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', FALSE);
172 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($fullClassName, $contentObjectInstance);
173 $this->assertSame($contentObjectInstance, $this->cObj->getContentObject($name));
174 }
175
176 //////////////////////////
177 // Tests concerning FORM
178 //////////////////////////
179 /**
180 * @test
181 */
182 public function formWithSecureFormMailEnabledDoesNotContainRecipientField() {
183 $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = TRUE;
184 $this->assertNotContains('name="recipient', $this->cObj->FORM(array('recipient' => 'foo@bar.com', 'recipient.' => array()), array()));
185 }
186
187 /**
188 * @test
189 */
190 public function formWithSecureFormMailDisabledDoesNotContainRecipientField() {
191 $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = FALSE;
192 $this->assertContains('name="recipient', $this->cObj->FORM(array('recipient' => 'foo@bar.com', 'recipient.' => array()), array()));
193 }
194
195 /////////////////////////////////////////
196 // Tests concerning getQueryArguments()
197 /////////////////////////////////////////
198 /**
199 * @test
200 */
201 public function getQueryArgumentsExcludesParameters() {
202 $this->cObj->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
203 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
204 );
205 $getQueryArgumentsConfiguration = array();
206 $getQueryArgumentsConfiguration['exclude'] = array();
207 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
208 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
209 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
210 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
211 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
212 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
213 $this->assertEquals($expectedResult, $actualResult);
214 }
215
216 /**
217 * @test
218 */
219 public function getQueryArgumentsExcludesGetParameters() {
220 $_GET = array(
221 'key1' => 'value1',
222 'key2' => 'value2',
223 'key3' => array(
224 'key31' => 'value31',
225 'key32' => array(
226 'key321' => 'value321',
227 'key322' => 'value322'
228 )
229 )
230 );
231 $getQueryArgumentsConfiguration = array();
232 $getQueryArgumentsConfiguration['method'] = 'GET';
233 $getQueryArgumentsConfiguration['exclude'] = array();
234 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
235 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
236 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
237 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
238 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
239 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
240 $this->assertEquals($expectedResult, $actualResult);
241 }
242
243 /**
244 * @test
245 */
246 public function getQueryArgumentsOverrulesSingleParameter() {
247 $this->cObj->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
248 $this->returnValue('key1=value1')
249 );
250 $getQueryArgumentsConfiguration = array();
251 $overruleArguments = array(
252 // Should be overridden
253 'key1' => 'value1Overruled',
254 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
255 'key2' => 'value2Overruled'
256 );
257 $expectedResult = '&key1=value1Overruled';
258 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
259 $this->assertEquals($expectedResult, $actualResult);
260 }
261
262 /**
263 * @test
264 */
265 public function getQueryArgumentsOverrulesMultiDimensionalParameters() {
266 $_POST = array(
267 'key1' => 'value1',
268 'key2' => 'value2',
269 'key3' => array(
270 'key31' => 'value31',
271 'key32' => array(
272 'key321' => 'value321',
273 'key322' => 'value322'
274 )
275 )
276 );
277 $getQueryArgumentsConfiguration = array();
278 $getQueryArgumentsConfiguration['method'] = 'POST';
279 $getQueryArgumentsConfiguration['exclude'] = array();
280 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
281 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
282 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
283 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
284 $overruleArguments = array(
285 // Should be overriden
286 'key2' => 'value2Overruled',
287 'key3' => array(
288 'key32' => array(
289 // Shouldn't be set: Parameter is excluded and not forced
290 'key321' => 'value321Overruled',
291 // Should be overriden: Parameter is not excluded
292 'key322' => 'value322Overruled',
293 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
294 'key323' => 'value323Overruled'
295 )
296 )
297 );
298 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
299 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
300 $this->assertEquals($expectedResult, $actualResult);
301 }
302
303 /**
304 * @test
305 */
306 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters() {
307 $this->cObj->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
308 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
309 );
310 $_POST = array(
311 'key1' => 'value1',
312 'key2' => 'value2',
313 'key3' => array(
314 'key31' => 'value31',
315 'key32' => array(
316 'key321' => 'value321',
317 'key322' => 'value322'
318 )
319 )
320 );
321 $getQueryArgumentsConfiguration = array();
322 $getQueryArgumentsConfiguration['exclude'] = array();
323 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
324 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
325 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
326 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
327 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
328 $overruleArguments = array(
329 // Should be overriden
330 'key2' => 'value2Overruled',
331 'key3' => array(
332 'key32' => array(
333 // Should be set: Parameter is excluded but forced
334 'key321' => 'value321Overruled',
335 // Should be set: Parameter doesn't exist in source array but is forced
336 'key323' => 'value323Overruled'
337 )
338 )
339 );
340 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
341 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
342 $this->assertEquals($expectedResult, $actualResult);
343 $getQueryArgumentsConfiguration['method'] = 'POST';
344 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
345 $this->assertEquals($expectedResult, $actualResult);
346 }
347
348 /**
349 * @test
350 */
351 public function getQueryArgumentsWithMethodPostGetMergesParameters() {
352 $_POST = array(
353 'key1' => 'POST1',
354 'key2' => 'POST2',
355 'key3' => array(
356 'key31' => 'POST31',
357 'key32' => 'POST32',
358 'key33' => array(
359 'key331' => 'POST331',
360 'key332' => 'POST332',
361 )
362 )
363 );
364 $_GET = array(
365 'key2' => 'GET2',
366 'key3' => array(
367 'key32' => 'GET32',
368 'key33' => array(
369 'key331' => 'GET331',
370 )
371 )
372 );
373 $getQueryArgumentsConfiguration = array();
374 $getQueryArgumentsConfiguration['method'] = 'POST,GET';
375 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
376 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
377 $this->assertEquals($expectedResult, $actualResult);
378 }
379
380 /**
381 * @test
382 */
383 public function getQueryArgumentsWithMethodGetPostMergesParameters() {
384 $_GET = array(
385 'key1' => 'GET1',
386 'key2' => 'GET2',
387 'key3' => array(
388 'key31' => 'GET31',
389 'key32' => 'GET32',
390 'key33' => array(
391 'key331' => 'GET331',
392 'key332' => 'GET332',
393 )
394 )
395 );
396 $_POST = array(
397 'key2' => 'POST2',
398 'key3' => array(
399 'key32' => 'POST32',
400 'key33' => array(
401 'key331' => 'POST331',
402 )
403 )
404 );
405 $getQueryArgumentsConfiguration = array();
406 $getQueryArgumentsConfiguration['method'] = 'GET,POST';
407 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
408 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
409 $this->assertEquals($expectedResult, $actualResult);
410 }
411
412 /**
413 * Encodes square brackets in URL.
414 *
415 * @param string $string
416 * @return string
417 */
418 private function rawUrlEncodeSquareBracketsInUrl($string) {
419 return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
420 }
421
422 //////////////////////////////
423 // Tests concerning crop
424 //////////////////////////////
425 /**
426 * @test
427 */
428 public function cropIsMultibyteSafe() {
429 $this->assertEquals('бла', $this->cObj->crop('бла', '3|...'));
430 }
431
432 //////////////////////////////
433 // Tests concerning cropHTML
434 //////////////////////////////
435 /**
436 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
437 * of charset, text type, and configuration options to be tested.
438 *
439 * @return array two-dimensional array with the second level like this:
440 * @see cropHtmlWithDataProvider
441 */
442 public function cropHtmlDataProvider() {
443 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
444 $textWithMarkup = '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>' . ' implemented</strong> the original version of the crop function.';
445 $textWithEntities = 'Kasper Sk&aring;rh&oslash;j implemented the; original ' . 'version of the crop function.';
446 $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
447 $data = array();
448 foreach ($charsets as $charset) {
449 $data = array_merge($data, array(
450 $charset . ' plain text; 11|...' => array(
451 '11|...',
452 $plainText,
453 'Kasper Sk' . chr(229) . 'r...',
454 $charset
455 ),
456 $charset . ' plain text; -58|...' => array(
457 '-58|...',
458 $plainText,
459 '...h' . chr(248) . 'j implemented the original version of the crop function.',
460 $charset
461 ),
462 $charset . ' plain text; 4|...|1' => array(
463 '4|...|1',
464 $plainText,
465 'Kasp...',
466 $charset
467 ),
468 $charset . ' plain text; 20|...|1' => array(
469 '20|...|1',
470 $plainText,
471 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...',
472 $charset
473 ),
474 $charset . ' plain text; -5|...|1' => array(
475 '-5|...|1',
476 $plainText,
477 '...tion.',
478 $charset
479 ),
480 $charset . ' plain text; -49|...|1' => array(
481 '-49|...|1',
482 $plainText,
483 '...the original version of the crop function.',
484 $charset
485 ),
486 $charset . ' text with markup; 11|...' => array(
487 '11|...',
488 $textWithMarkup,
489 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>',
490 $charset
491 ),
492 $charset . ' text with markup; 13|...' => array(
493 '13|...',
494 $textWithMarkup,
495 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>',
496 $charset
497 ),
498 $charset . ' text with markup; 14|...' => array(
499 '14|...',
500 $textWithMarkup,
501 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
502 $charset
503 ),
504 $charset . ' text with markup; 15|...' => array(
505 '15|...',
506 $textWithMarkup,
507 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>',
508 $charset
509 ),
510 $charset . ' text with markup; 29|...' => array(
511 '29|...',
512 $textWithMarkup,
513 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...',
514 $charset
515 ),
516 $charset . ' text with markup; -58|...' => array(
517 '-58|...',
518 $textWithMarkup,
519 '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
520 $charset
521 ),
522 $charset . ' text with markup 4|...|1' => array(
523 '4|...|1',
524 $textWithMarkup,
525 '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>',
526 $charset
527 ),
528 $charset . ' text with markup; 11|...|1' => array(
529 '11|...|1',
530 $textWithMarkup,
531 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
532 $charset
533 ),
534 $charset . ' text with markup; 13|...|1' => array(
535 '13|...|1',
536 $textWithMarkup,
537 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
538 $charset
539 ),
540 $charset . ' text with markup; 14|...|1' => array(
541 '14|...|1',
542 $textWithMarkup,
543 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
544 $charset
545 ),
546 $charset . ' text with markup; 15|...|1' => array(
547 '15|...|1',
548 $textWithMarkup,
549 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
550 $charset
551 ),
552 $charset . ' text with markup; 29|...|1' => array(
553 '29|...|1',
554 $textWithMarkup,
555 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...',
556 $charset
557 ),
558 $charset . ' text with markup; -66|...|1' => array(
559 '-66|...|1',
560 $textWithMarkup,
561 '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
562 $charset
563 ),
564 $charset . ' text with entities 9|...' => array(
565 '9|...',
566 $textWithEntities,
567 'Kasper Sk...',
568 $charset
569 ),
570 $charset . ' text with entities 10|...' => array(
571 '10|...',
572 $textWithEntities,
573 'Kasper Sk&aring;...',
574 $charset
575 ),
576 $charset . ' text with entities 11|...' => array(
577 '11|...',
578 $textWithEntities,
579 'Kasper Sk&aring;r...',
580 $charset
581 ),
582 $charset . ' text with entities 13|...' => array(
583 '13|...',
584 $textWithEntities,
585 'Kasper Sk&aring;rh&oslash;...',
586 $charset
587 ),
588 $charset . ' text with entities 14|...' => array(
589 '14|...',
590 $textWithEntities,
591 'Kasper Sk&aring;rh&oslash;j...',
592 $charset
593 ),
594 $charset . ' text with entities 15|...' => array(
595 '15|...',
596 $textWithEntities,
597 'Kasper Sk&aring;rh&oslash;j ...',
598 $charset
599 ),
600 $charset . ' text with entities 16|...' => array(
601 '16|...',
602 $textWithEntities,
603 'Kasper Sk&aring;rh&oslash;j i...',
604 $charset
605 ),
606 $charset . ' text with entities -57|...' => array(
607 '-57|...',
608 $textWithEntities,
609 '...j implemented the; original version of the crop function.',
610 $charset
611 ),
612 $charset . ' text with entities -58|...' => array(
613 '-58|...',
614 $textWithEntities,
615 '...&oslash;j implemented the; original version of the crop function.',
616 $charset
617 ),
618 $charset . ' text with entities -59|...' => array(
619 '-59|...',
620 $textWithEntities,
621 '...h&oslash;j implemented the; original version of the crop function.',
622 $charset
623 ),
624 $charset . ' text with entities 4|...|1' => array(
625 '4|...|1',
626 $textWithEntities,
627 'Kasp...',
628 $charset
629 ),
630 $charset . ' text with entities 9|...|1' => array(
631 '9|...|1',
632 $textWithEntities,
633 'Kasper...',
634 $charset
635 ),
636 $charset . ' text with entities 10|...|1' => array(
637 '10|...|1',
638 $textWithEntities,
639 'Kasper...',
640 $charset
641 ),
642 $charset . ' text with entities 11|...|1' => array(
643 '11|...|1',
644 $textWithEntities,
645 'Kasper...',
646 $charset
647 ),
648 $charset . ' text with entities 13|...|1' => array(
649 '13|...|1',
650 $textWithEntities,
651 'Kasper...',
652 $charset
653 ),
654 $charset . ' text with entities 14|...|1' => array(
655 '14|...|1',
656 $textWithEntities,
657 'Kasper Sk&aring;rh&oslash;j...',
658 $charset
659 ),
660 $charset . ' text with entities 15|...|1' => array(
661 '15|...|1',
662 $textWithEntities,
663 'Kasper Sk&aring;rh&oslash;j...',
664 $charset
665 ),
666 $charset . ' text with entities 16|...|1' => array(
667 '16|...|1',
668 $textWithEntities,
669 'Kasper Sk&aring;rh&oslash;j...',
670 $charset
671 ),
672 $charset . ' text with entities -57|...|1' => array(
673 '-57|...|1',
674 $textWithEntities,
675 '...implemented the; original version of the crop function.',
676 $charset
677 ),
678 $charset . ' text with entities -58|...|1' => array(
679 '-58|...|1',
680 $textWithEntities,
681 '...implemented the; original version of the crop function.',
682 $charset
683 ),
684 $charset . ' text with entities -59|...|1' => array(
685 '-59|...|1',
686 $textWithEntities,
687 '...implemented the; original version of the crop function.',
688 $charset
689 ),
690 $charset . ' text with dash in html-element 28|...|1' => array(
691 '28|...|1',
692 'Some text with a link to <link email.address@example.org - mail "Open email window">my email.address@example.org</link> and text after it',
693 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>',
694 $charset
695 )
696 ));
697 }
698 return $data;
699 }
700
701 /**
702 * Checks if stdWrap.cropHTML works with plain text cropping from left
703 *
704 * @test
705 * @dataProvider cropHtmlDataProvider
706 * @param string $settings
707 * @param string $subject the string to crop
708 * @param string $expected the expected cropped result
709 * @param string $charset the charset that will be set as renderCharset
710 */
711 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
712 $this->handleCharset($charset, $subject, $expected);
713 $this->assertEquals($expected, $this->cObj->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"');
714 }
715
716 /**
717 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
718 * counts multiple invisible characters not as one (as the browser will output the content).
719 *
720 * @test
721 */
722 public function cropHtmlWorksWithComplexContent() {
723 $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
724 $subject = '
725 <h1>Blog Example</h1>
726 <hr>
727 <div class="csc-header csc-header-n1">
728 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
729 </div>
730 <p class="bodytext">
731 A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.
732 </p>
733 <div class="tx-blogexample-list-container">
734 <p class="bodytext">
735 Below are the most recent posts:
736 </p>
737 <ul>
738 <li>
739 <h3>
740 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog]=&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=003b0131ed">The Post #1</a>
741 </h3>
742 <p class="bodytext">
743 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
744 </p>
745 <p class="metadata">
746 Published on 26.08.2009 by Jochen Rau
747 </p>
748 <p>
749 Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>
750 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=f982643bc3">read more &gt;&gt;</a><br>
751 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=edit&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=5b481bc8f0">Edit</a>&nbsp;<a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=delete&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=4e52879656">Delete</a>
752 </p>
753 </li>
754 </ul>
755 <p>
756 <a href="index.php?id=99&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=new&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=2718a4b1a0">Create a new Post</a>
757 </p>
758 </div>
759 <hr>
760 <p>
761 ? TYPO3 Association
762 </p>
763 ';
764 $result = $this->cObj->cropHTML($subject, '300');
765 $expected = '
766 <h1>Blog Example</h1>
767 <hr>
768 <div class="csc-header csc-header-n1">
769 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
770 </div>
771 <p class="bodytext">
772 A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.
773 </p>
774 <div class="tx-blogexample-list-container">
775 <p class="bodytext">
776 Below are the most recent posts:
777 </p>
778 <ul>
779 <li>
780 <h3>
781 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog]=&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=003b0131ed">The Pos</a></h3></li></ul></div>';
782 $this->assertEquals($expected, $result);
783 $result = $this->cObj->cropHTML($subject, '-100');
784 $expected = '<div class="tx-blogexample-list-container"><ul><li><p>Design]&nbsp;<br>
785 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=f982643bc3">read more &gt;&gt;</a><br>
786 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=edit&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=5b481bc8f0">Edit</a>&nbsp;<a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=delete&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=4e52879656">Delete</a>
787 </p>
788 </li>
789 </ul>
790 <p>
791 <a href="index.php?id=99&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=new&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=2718a4b1a0">Create a new Post</a>
792 </p>
793 </div>
794 <hr>
795 <p>
796 ? TYPO3 Association
797 </p>
798 ';
799 $this->assertEquals($expected, $result);
800 }
801
802 /**
803 * @return array
804 */
805 public function stdWrap_roundDataProvider() {
806 return array(
807 'rounding off without any configuration' => array(
808 1.123456789,
809 array(),
810 1
811 ),
812 'rounding up without any configuration' => array(
813 1.523456789,
814 array(),
815 2
816 ),
817 'regular rounding (off) to two decimals' => array(
818 0.123456789,
819 array(
820 'decimals' => 2
821 ),
822 0.12
823 ),
824 'regular rounding (up) to two decimals' => array(
825 0.1256789,
826 array(
827 'decimals' => 2
828 ),
829 0.13
830 ),
831 'rounding up to integer with type ceil' => array(
832 0.123456789,
833 array(
834 'roundType' => 'ceil'
835 ),
836 1
837 ),
838 'rounding down to integer with type floor' => array(
839 2.3481,
840 array(
841 'roundType' => 'floor'
842 ),
843 2
844 )
845 );
846 }
847
848 /**
849 * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
850 *
851 * @test
852 */
853 public function cropHtmlWorksWithLinebreaks() {
854 $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
855 $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
856 $result = $this->cObj->cropHTML($subject, '121');
857 $this->assertEquals($expected, $result);
858 }
859
860 /**
861 * Test for the stdWrap function "round"
862 *
863 * @param float $float
864 * @param array $conf
865 * @param float $expected
866 * @return void
867 * @dataProvider stdWrap_roundDataProvider
868 * @test
869 */
870 public function stdWrap_round($float, $conf, $expected) {
871 $conf = array(
872 'round.' => $conf
873 );
874 $result = $this->cObj->stdWrap_round($float, $conf);
875 $this->assertEquals($expected, $result);
876 }
877
878 /**
879 * @return array
880 */
881 public function stdWrap_strPadDataProvider() {
882 return array(
883 'pad string with default settings and length 10' => array(
884 'Alien',
885 array(
886 'length' => '10',
887 ),
888 'Alien ',
889 ),
890 'pad string with padWith -= and type left and length 10' => array(
891 'Alien',
892 array(
893 'length' => '10',
894 'padWith' => '-=',
895 'type' => 'left',
896 ),
897 '-=-=-Alien',
898 ),
899 'pad string with padWith _ and type both and length 10' => array(
900 'Alien',
901 array(
902 'length' => '10',
903 'padWith' => '_',
904 'type' => 'both',
905 ),
906 '__Alien___',
907 ),
908 'pad string with padWith 0 and type both and length 10' => array(
909 'Alien',
910 array(
911 'length' => '10',
912 'padWith' => '0',
913 'type' => 'both',
914 ),
915 '00Alien000',
916 ),
917 'pad string with padWith ___ and type both and length 6' => array(
918 'Alien',
919 array(
920 'length' => '6',
921 'padWith' => '___',
922 'type' => 'both',
923 ),
924 'Alien_',
925 ),
926 'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
927 'Alien',
928 array(
929 'length' => '1',
930 'length.' => array(
931 'wrap' => '|2',
932 ),
933 'padWith' => '_',
934 'type' => 'both',
935 ),
936 '___Alien____',
937 ),
938 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
939 'Alien',
940 array(
941 'length' => '12',
942 'padWith' => '_',
943 'padWith.' => array(
944 'wrap' => '-|=',
945 ),
946 'type' => 'both',
947 ),
948 '-_=Alien-_=-',
949 ),
950 'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
951 'Alien',
952 array(
953 'length' => '12',
954 'padWith' => '_',
955 'type' => 'both',
956 // make type become "left"
957 'type.' => array(
958 'substring' => '2,1',
959 'wrap' => 'lef|',
960 ),
961 ),
962 '_______Alien',
963 ),
964 );
965 }
966
967 /**
968 * Test for the stdWrap function "strPad"
969 *
970 * @param string $content
971 * @param array $conf
972 * @param string $expected
973 *
974 * @dataProvider stdWrap_strPadDataProvider
975 * @test
976 */
977 public function stdWrap_strPad($content, $conf, $expected) {
978 $conf = array(
979 'strPad.' => $conf
980 );
981 $result = $this->cObj->stdWrap_strPad($content, $conf);
982 $this->assertEquals($expected, $result);
983 }
984
985 /**
986 * Data provider for the hash test
987 *
988 * @return array multi-dimensional array with the second level like this:
989 * @see hash
990 */
991 public function hashDataProvider() {
992 $data = array(
993 'testing md5' => array(
994 'joh316',
995 array(
996 'hash' => 'md5'
997 ),
998 'bacb98acf97e0b6112b1d1b650b84971'
999 ),
1000 'testing sha1' => array(
1001 'joh316',
1002 array(
1003 'hash' => 'sha1'
1004 ),
1005 '063b3d108bed9f88fa618c6046de0dccadcf3158'
1006 ),
1007 'testing non-existing hashing algorithm' => array(
1008 'joh316',
1009 array(
1010 'hash' => 'non-existing'
1011 ),
1012 ''
1013 ),
1014 'testing stdWrap capability' => array(
1015 'joh316',
1016 array(
1017 'hash.' => array(
1018 'cObject' => 'TEXT',
1019 'cObject.' => array(
1020 'value' => 'md5'
1021 )
1022 )
1023 ),
1024 'bacb98acf97e0b6112b1d1b650b84971'
1025 )
1026 );
1027 return $data;
1028 }
1029
1030 /**
1031 * Test for the stdWrap function "hash"
1032 *
1033 * @param string $text
1034 * @param array $conf
1035 * @param string $expected
1036 * @return void
1037 * @dataProvider hashDataProvider
1038 * @test
1039 */
1040 public function stdWrap_hash($text, array $conf, $expected) {
1041 $result = $this->cObj->stdWrap_hash($text, $conf);
1042 $this->assertEquals($expected, $result);
1043 }
1044
1045 /**
1046 * Data provider for the numberFormat test
1047 *
1048 * @return array multi-dimensional array with the second level like this:
1049 * @see numberFormat
1050 */
1051 public function numberFormatDataProvider() {
1052 $data = array(
1053 'testing decimals' => array(
1054 0.8,
1055 array(
1056 'decimals' => 2
1057 ),
1058 '0.80'
1059 ),
1060 'testing decimals with input as string' => array(
1061 '0.8',
1062 array(
1063 'decimals' => 2
1064 ),
1065 '0.80'
1066 ),
1067 'testing dec_point' => array(
1068 0.8,
1069 array(
1070 'decimals' => 1,
1071 'dec_point' => ','
1072 ),
1073 '0,8'
1074 ),
1075 'testing thousands_sep' => array(
1076 999.99,
1077 array(
1078 'decimals' => 0,
1079 'thousands_sep.' => array(
1080 'char' => 46
1081 )
1082 ),
1083 '1.000'
1084 ),
1085 'testing mixture' => array(
1086 1281731.45,
1087 array(
1088 'decimals' => 1,
1089 'dec_point.' => array(
1090 'char' => 44
1091 ),
1092 'thousands_sep.' => array(
1093 'char' => 46
1094 )
1095 ),
1096 '1.281.731,5'
1097 )
1098 );
1099 return $data;
1100 }
1101
1102 /**
1103 * Check if stdWrap.numberFormat and all of its properties work properly
1104 *
1105 * @dataProvider numberFormatDataProvider
1106 * @test
1107 */
1108 public function numberFormat($float, $formatConf, $expected) {
1109 $result = $this->cObj->numberFormat($float, $formatConf);
1110 $this->assertEquals($expected, $result);
1111 }
1112
1113 /**
1114 * Data provider for the replacement test
1115 *
1116 * @return array multi-dimensional array with the second level like this:
1117 * @see replacement
1118 */
1119 public function replacementDataProvider() {
1120 $data = array(
1121 'multiple replacements, including regex' => array(
1122 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1123 array(
1124 'replacement.' => array(
1125 '120.' => array(
1126 'search' => 'in da hood',
1127 'replace' => 'around the block'
1128 ),
1129 '20.' => array(
1130 'search' => '_',
1131 'replace.' => array('char' => '32')
1132 ),
1133 '130.' => array(
1134 'search' => '#a (Cat|Dog|Tiger)#i',
1135 'replace' => 'an animal',
1136 'useRegExp' => '1'
1137 )
1138 )
1139 ),
1140 'There is an animal, an animal and an animal around the block! Yeah!'
1141 ),
1142 'replacement with optionSplit, normal pattern' => array(
1143 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1144 array(
1145 'replacement.' => array(
1146 '10.' => array(
1147 'search' => '_',
1148 'replace' => '1 || 2 || 3',
1149 'useOptionSplitReplace' => '1'
1150 ),
1151 )
1152 ),
1153 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1154 ),
1155 'replacement with optionSplit, using regex' => array(
1156 'There is a cat, a dog and a tiger in da hood! Yeah!',
1157 array(
1158 'replacement.' => array(
1159 '10.' => array(
1160 'search' => '#(a) (Cat|Dog|Tiger)#i',
1161 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1162 'useOptionSplitReplace' => '1',
1163 'useRegExp' => '1'
1164 )
1165 )
1166 ),
1167 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1168 ),
1169 );
1170 return $data;
1171 }
1172
1173 /**
1174 * Check if stdWrap.replacement and all of its properties work properly
1175 *
1176 * @dataProvider replacementDataProvider
1177 * @test
1178 */
1179 public function replacement($input, $conf, $expected) {
1180 $result = $this->cObj->stdWrap_replacement($input, $conf);
1181 $this->assertEquals($expected, $result);
1182 }
1183
1184 /**
1185 * Data provider for the getQuery test
1186 *
1187 * @return array multi-dimensional array with the second level like this:
1188 * @see getQuery
1189 */
1190 public function getQueryDataProvider() {
1191 $data = array(
1192 'testing empty conf' => array(
1193 'tt_content',
1194 array(),
1195 array(
1196 'SELECT' => '*'
1197 )
1198 ),
1199 'testing #17284: adding uid/pid for workspaces' => array(
1200 'tt_content',
1201 array(
1202 'selectFields' => 'header,bodytext'
1203 ),
1204 array(
1205 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1206 )
1207 ),
1208 'testing #17284: no need to add' => array(
1209 'tt_content',
1210 array(
1211 'selectFields' => 'tt_content.*'
1212 ),
1213 array(
1214 'SELECT' => 'tt_content.*'
1215 )
1216 ),
1217 'testing #17284: no need to add #2' => array(
1218 'tt_content',
1219 array(
1220 'selectFields' => '*'
1221 ),
1222 array(
1223 'SELECT' => '*'
1224 )
1225 ),
1226 'testing #29783: joined tables, prefix tablename' => array(
1227 'tt_content',
1228 array(
1229 'selectFields' => 'tt_content.header,be_users.username',
1230 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1231 ),
1232 array(
1233 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1234 )
1235 ),
1236 'testing #34152: single count(*), add nothing' => array(
1237 'tt_content',
1238 array(
1239 'selectFields' => 'count(*)'
1240 ),
1241 array(
1242 'SELECT' => 'count(*)'
1243 )
1244 ),
1245 'testing #34152: single max(crdate), add nothing' => array(
1246 'tt_content',
1247 array(
1248 'selectFields' => 'max(crdate)'
1249 ),
1250 array(
1251 'SELECT' => 'max(crdate)'
1252 )
1253 ),
1254 'testing #34152: single min(crdate), add nothing' => array(
1255 'tt_content',
1256 array(
1257 'selectFields' => 'min(crdate)'
1258 ),
1259 array(
1260 'SELECT' => 'min(crdate)'
1261 )
1262 ),
1263 'testing #34152: single sum(is_siteroot), add nothing' => array(
1264 'tt_content',
1265 array(
1266 'selectFields' => 'sum(is_siteroot)'
1267 ),
1268 array(
1269 'SELECT' => 'sum(is_siteroot)'
1270 )
1271 ),
1272 'testing #34152: single avg(crdate), add nothing' => array(
1273 'tt_content',
1274 array(
1275 'selectFields' => 'avg(crdate)'
1276 ),
1277 array(
1278 'SELECT' => 'avg(crdate)'
1279 )
1280 )
1281 );
1282 return $data;
1283 }
1284
1285 /**
1286 * Check if sanitizeSelectPart works as expected
1287 *
1288 * @dataProvider getQueryDataProvider
1289 * @test
1290 */
1291 public function getQuery($table, $conf, $expected) {
1292 $GLOBALS['TCA'] = array(
1293 'pages' => array(
1294 'ctrl' => array(
1295 'enablecolumns' => array(
1296 'disabled' => 'hidden'
1297 )
1298 )
1299 ),
1300 'tt_content' => array(
1301 'ctrl' => array(
1302 'enablecolumns' => array(
1303 'disabled' => 'hidden'
1304 ),
1305 'versioningWS' => 2
1306 )
1307 ),
1308 );
1309 $result = $this->cObj->getQuery($table, $conf, TRUE);
1310 foreach ($expected as $field => $value) {
1311 $this->assertEquals($value, $result[$field]);
1312 }
1313 }
1314
1315 /**
1316 * @test
1317 */
1318 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet() {
1319 $GLOBALS['TCA'] = array(
1320 'pages' => array(
1321 'ctrl' => array(
1322 'enablecolumns' => array(
1323 'disabled' => 'hidden'
1324 )
1325 )
1326 ),
1327 'tt_content' => array(
1328 'ctrl' => array(
1329 'enablecolumns' => array(
1330 'disabled' => 'hidden'
1331 )
1332 )
1333 ),
1334 );
1335 $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
1336 $this->cObj->start(array(), 'tt_content');
1337 $conf = array(
1338 'recursive' => '15',
1339 'pidInList' => '16, -35'
1340 );
1341 $this->cObj->expects($this->at(0))
1342 ->method('getTreeList')
1343 ->with(-16, 15)
1344 ->will($this->returnValue('15,16'));
1345 $this->cObj->expects($this->at(1))
1346 ->method('getTreeList')
1347 ->with(-35, 15)
1348 ->will($this->returnValue('15,35'));
1349 $this->cObj->getQuery('tt_content', $conf, TRUE);
1350 }
1351
1352 /**
1353 * @test
1354 */
1355 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet() {
1356 $GLOBALS['TCA'] = array(
1357 'pages' => array(
1358 'ctrl' => array(
1359 'enablecolumns' => array(
1360 'disabled' => 'hidden'
1361 )
1362 )
1363 ),
1364 'tt_content' => array(
1365 'ctrl' => array(
1366 'enablecolumns' => array(
1367 'disabled' => 'hidden'
1368 )
1369 )
1370 ),
1371 );
1372 $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
1373 $GLOBALS['TSFE']->id = 27;
1374 $this->cObj->start(array(), 'tt_content');
1375 $conf = array(
1376 'pidInList' => 'this',
1377 'recursive' => '4'
1378 );
1379 $this->cObj->expects($this->once())
1380 ->method('getTreeList')
1381 ->with(-27)
1382 ->will($this->returnValue('27'));
1383 $this->cObj->getQuery('tt_content', $conf, TRUE);
1384 }
1385
1386 /**
1387 * Data provider for the stdWrap_strftime test
1388 *
1389 * @return array multi-dimensional array with the second level like this:
1390 * @see stdWrap_strftime
1391 */
1392 public function stdWrap_strftimeReturnsFormattedStringDataProvider() {
1393 $data = array(
1394 'given timestamp' => array(
1395 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1396 array(
1397 'strftime' => '%d-%m-%Y',
1398 ),
1399 ),
1400 'empty string' => array(
1401 '',
1402 array(
1403 'strftime' => '%d-%m-%Y',
1404 ),
1405 ),
1406 'testing null' => array(
1407 NULL,
1408 array(
1409 'strftime' => '%d-%m-%Y',
1410 ),
1411 ),
1412 );
1413 return $data;
1414 }
1415
1416 /**
1417 * @test
1418 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1419 */
1420 public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1421 // Set exec_time to a hard timestamp
1422 $GLOBALS['EXEC_TIME'] = 1346500800;
1423 // Save current timezone and set to UTC to make the system under test behave
1424 // the same in all server timezone settings
1425 $timezoneBackup = date_default_timezone_get();
1426 date_default_timezone_set('UTC');
1427
1428 $result = $this->cObj->stdWrap_strftime($content, $conf);
1429
1430 // Reset timezone
1431 date_default_timezone_set($timezoneBackup);
1432
1433 $this->assertEquals('01-09-2012', $result);
1434 }
1435
1436 /**
1437 * @param string|NULL $content
1438 * @param array $configuration
1439 * @param string $expected
1440 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
1441 * @test
1442 */
1443 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1444 $result = $this->cObj->stdWrap_ifNull($content, $configuration);
1445 $this->assertEquals($expected, $result);
1446 }
1447
1448 /**
1449 * Data provider for stdWrap_ifNullDeterminesNullValues test
1450 *
1451 * @return array
1452 */
1453 public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
1454 return array(
1455 'null value' => array(
1456 NULL,
1457 array(
1458 'ifNull' => '1',
1459 ),
1460 '1',
1461 ),
1462 'zero value' => array(
1463 '0',
1464 array(
1465 'ifNull' => '1',
1466 ),
1467 '0',
1468 ),
1469 );
1470 }
1471
1472 /**
1473 * @param $content
1474 * @param array $configuration
1475 * @param $expected
1476 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
1477 * @test
1478 */
1479 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1480 $result = $this->cObj->stdWrap_noTrimWrap($content, $configuration);
1481 $this->assertEquals($expected, $result);
1482 }
1483
1484 /**
1485 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
1486 *
1487 * @return array
1488 */
1489 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
1490 return array(
1491 'No char given' => array(
1492 'middle',
1493 array(
1494 'noTrimWrap' => '| left | right |',
1495 ),
1496 ' left middle right '
1497 ),
1498 'Zero char given' => array(
1499 'middle',
1500 array(
1501 'noTrimWrap' => '0 left 0 right 0',
1502 'noTrimWrap.' => array('splitChar' => '0'),
1503
1504 ),
1505 ' left middle right '
1506 ),
1507 'Default char given' => array(
1508 'middle',
1509 array(
1510 'noTrimWrap' => '| left | right |',
1511 'noTrimWrap.' => array('splitChar' => '|'),
1512 ),
1513 ' left middle right '
1514 ),
1515 'Split char is a' => array(
1516 'middle',
1517 array(
1518 'noTrimWrap' => 'a left a right a',
1519 'noTrimWrap.' => array('splitChar' => 'a'),
1520 ),
1521 ' left middle right '
1522 ),
1523 'Split char is multi-char (ab)' => array(
1524 'middle',
1525 array(
1526 'noTrimWrap' => 'ab left ab right ab',
1527 'noTrimWrap.' => array('splitChar' => 'ab'),
1528 ),
1529 ' left middle right '
1530 ),
1531 'Split char accepts stdWrap' => array(
1532 'middle',
1533 array(
1534 'noTrimWrap' => 'abc left abc right abc',
1535 'noTrimWrap.' => array(
1536 'splitChar' => 'b',
1537 'splitChar.' => array('wrap' => 'a|c'),
1538 ),
1539 ),
1540 ' left middle right '
1541 ),
1542 );
1543 }
1544
1545 /**
1546 * @param array $expectedTags
1547 * @param array $configuration
1548 * @test
1549 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
1550 */
1551 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
1552 $this->cObj->stdWrap_addPageCacheTags('', $configuration);
1553 $this->assertEquals($expectedTags, $this->tsfe->_get('pageCacheTags'));
1554 }
1555
1556 /**
1557 * @return array
1558 */
1559 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
1560 return array(
1561 'No Tag' => array(
1562 array(),
1563 array('addPageCacheTags' => ''),
1564 ),
1565 'Two expectedTags' => array(
1566 array('tag1', 'tag2'),
1567 array('addPageCacheTags' => 'tag1,tag2'),
1568 ),
1569 'Two expectedTags plus one with stdWrap' => array(
1570 array('tag1', 'tag2', 'tag3'),
1571 array(
1572 'addPageCacheTags' => 'tag1,tag2',
1573 'addPageCacheTags.' => array('wrap' => '|,tag3')
1574 ),
1575 ),
1576 );
1577 }
1578
1579 /**
1580 * Data provider for stdWrap_encodeForJavaScriptValue test
1581 *
1582 * @return array multi-dimensional array with the second level like this:
1583 * @see encodeForJavaScriptValue
1584 */
1585 public function stdWrap_encodeForJavaScriptValueDataProvider() {
1586 return array(
1587 'double quote in string' => array(
1588 'double quote"',
1589 array(),
1590 '\'double\u0020quote\u0022\''
1591 ),
1592 'backslash in string' => array(
1593 'backslash \\',
1594 array(),
1595 '\'backslash\u0020\u005C\''
1596 ),
1597 'exclamation mark' => array(
1598 'exclamation!',
1599 array(),
1600 '\'exclamation\u0021\''
1601 ),
1602 'whitespace tab, newline and carriage return' => array(
1603 "white\tspace\ns\r",
1604 array(),
1605 '\'white\u0009space\u000As\u000D\''
1606 ),
1607 'single quote in string' => array(
1608 'single quote \'',
1609 array(),
1610 '\'single\u0020quote\u0020\u0027\''
1611 ),
1612 'tag' => array(
1613 '<tag>',
1614 array(),
1615 '\'\u003Ctag\u003E\''
1616 ),
1617 'ampersand in string' => array(
1618 'amper&sand',
1619 array(),
1620 '\'amper\u0026sand\''
1621 ),
1622 );
1623 }
1624
1625 /**
1626 * Check if encodeForJavaScriptValue works properly
1627 *
1628 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
1629 * @test
1630 */
1631 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected) {
1632 $result = $this->cObj->stdWrap_encodeForJavaScriptValue($input, $conf);
1633 $this->assertEquals($expected, $result);
1634 }
1635
1636
1637 /////////////////////////////
1638 // Tests concerning getData()
1639 /////////////////////////////
1640
1641 /**
1642 * @return array
1643 */
1644 public function getDataWithTypeGpDataProvider() {
1645 return array(
1646 'Value in get-data' => array('onlyInGet', 'GetValue'),
1647 'Value in post-data' => array('onlyInPost', 'PostValue'),
1648 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
1649 );
1650 }
1651
1652 /**
1653 * Checks if getData() works with type "gp"
1654 *
1655 * @test
1656 * @dataProvider getDataWithTypeGpDataProvider
1657 */
1658 public function getDataWithTypeGp($key, $expectedValue) {
1659 $_GET = array(
1660 'onlyInGet' => 'GetValue',
1661 'inGetAndPost' => 'ValueInGet',
1662 );
1663 $_POST = array(
1664 'onlyInPost' => 'PostValue',
1665 'inGetAndPost' => 'ValueInPost',
1666 );
1667 $this->assertEquals($expectedValue, $this->cObj->getData('gp:' . $key));
1668 }
1669
1670 /**
1671 * Checks if getData() works with type "tsfe"
1672 *
1673 * @test
1674 */
1675 public function getDataWithTypeTsfe() {
1676 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('tsfe:renderCharset'));
1677 }
1678
1679 /**
1680 * Checks if getData() works with type "getenv"
1681 *
1682 * @test
1683 */
1684 public function getDataWithTypeGetenv() {
1685 $envName = uniqid('frontendtest');
1686 $value = uniqid('someValue');
1687 putenv($envName . '=' . $value);
1688 $this->assertEquals($value, $this->cObj->getData('getenv:' . $envName));
1689 }
1690
1691 /**
1692 * Checks if getData() works with type "getindpenv"
1693 *
1694 * @test
1695 */
1696 public function getDataWithTypeGetindpenv() {
1697 $this->cObj->expects($this->once())->method('getEnvironmentVariable')
1698 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
1699 $this->assertEquals('dummyPath', $this->cObj->getData('getindpenv:SCRIPT_FILENAME'));
1700 }
1701
1702 /**
1703 * Checks if getData() works with type "getindpenv"
1704 *
1705 * @test
1706 */
1707 public function getDataWithTypeField() {
1708 $key = 'someKey';
1709 $value = 'someValue';
1710 $field = array($key => $value);
1711
1712 $this->assertEquals($value, $this->cObj->getData('field:' . $key, $field));
1713 }
1714
1715 /**
1716 * Basic check if getData gets the uid of a file object
1717 *
1718 * @test
1719 */
1720 public function getDataWithTypeFileReturnsUidOfFileObject() {
1721 $uid = uniqid();
1722 $file = $this->getMock('TYPO3\\CMS\\Core\\Resource\File', array(), array(), '', FALSE);
1723 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
1724 $this->cObj->setCurrentFile($file);
1725 $this->assertEquals($uid, $this->cObj->getData('file:current:uid'));
1726 }
1727
1728 /**
1729 * Checks if getData() works with type "parameters"
1730 *
1731 * @test
1732 */
1733 public function getDataWithTypeParameters() {
1734 $key = uniqid('someKey');
1735 $value = uniqid('someValue');
1736 $this->cObj->parameters[$key] = $value;
1737
1738 $this->assertEquals($value, $this->cObj->getData('parameters:' . $key));
1739 }
1740
1741 /**
1742 * Checks if getData() works with type "register"
1743 *
1744 * @test
1745 */
1746 public function getDataWithTypeRegister() {
1747 $key = uniqid('someKey');
1748 $value = uniqid('someValue');
1749 $GLOBALS['TSFE']->register[$key] = $value;
1750
1751 $this->assertEquals($value, $this->cObj->getData('register:' . $key));
1752 }
1753
1754 /**
1755 * Checks if getData() works with type "level"
1756 *
1757 * @test
1758 */
1759 public function getDataWithTypeLevel() {
1760 $rootline = array(
1761 0 => array('uid' => 1, 'title' => 'title1'),
1762 1 => array('uid' => 2, 'title' => 'title2'),
1763 2 => array('uid' => 3, 'title' => 'title3'),
1764 );
1765
1766 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1767 $this->assertEquals(2, $this->cObj->getData('level'));
1768 }
1769
1770 /**
1771 * Checks if getData() works with type "global"
1772 *
1773 * @test
1774 */
1775 public function getDataWithTypeGlobal() {
1776 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('global:TSFE|renderCharset'));
1777 }
1778
1779 /**
1780 * Checks if getData() works with type "leveltitle"
1781 *
1782 * @test
1783 */
1784 public function getDataWithTypeLeveltitle() {
1785 $rootline = array(
1786 0 => array('uid' => 1, 'title' => 'title1'),
1787 1 => array('uid' => 2, 'title' => 'title2'),
1788 2 => array('uid' => 3, 'title' => ''),
1789 );
1790
1791 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1792 $this->assertEquals('', $this->cObj->getData('leveltitle:-1'));
1793 // since "title3" is not set, it will slide to "title2"
1794 $this->assertEquals('title2', $this->cObj->getData('leveltitle:-1,slide'));
1795 }
1796
1797 /**
1798 * Checks if getData() works with type "levelmedia"
1799 *
1800 * @test
1801 */
1802 public function getDataWithTypeLevelmedia() {
1803 $rootline = array(
1804 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
1805 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
1806 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
1807 );
1808
1809 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1810 $this->assertEquals('', $this->cObj->getData('levelmedia:-1'));
1811 // since "title3" is not set, it will slide to "title2"
1812 $this->assertEquals('media2', $this->cObj->getData('levelmedia:-1,slide'));
1813 }
1814
1815 /**
1816 * Checks if getData() works with type "leveluid"
1817 *
1818 * @test
1819 */
1820 public function getDataWithTypeLeveluid() {
1821 $rootline = array(
1822 0 => array('uid' => 1, 'title' => 'title1'),
1823 1 => array('uid' => 2, 'title' => 'title2'),
1824 2 => array('uid' => 3, 'title' => 'title3'),
1825 );
1826
1827 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1828 $this->assertEquals(3, $this->cObj->getData('leveluid:-1'));
1829 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
1830 $this->assertEquals(3, $this->cObj->getData('leveluid:-1,slide'));
1831 }
1832
1833 /**
1834 * Checks if getData() works with type "levelfield"
1835 *
1836 * @test
1837 */
1838 public function getDataWithTypeLevelfield() {
1839 $rootline = array(
1840 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1841 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1842 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
1843 );
1844
1845 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1846 $this->assertEquals('', $this->cObj->getData('levelfield:-1,testfield'));
1847 $this->assertEquals('field2', $this->cObj->getData('levelfield:-1,testfield,slide'));
1848 }
1849
1850 /**
1851 * Checks if getData() works with type "fullrootline"
1852 *
1853 * @test
1854 */
1855 public function getDataWithTypeFullrootline() {
1856 $rootline1 = array(
1857 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1858 );
1859 $rootline2 = array(
1860 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1861 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1862 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
1863 );
1864
1865 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
1866 $GLOBALS['TSFE']->rootLine = $rootline2;
1867 $this->assertEquals('field2', $this->cObj->getData('fullrootline:-1,testfield'));
1868 }
1869
1870 /**
1871 * Checks if getData() works with type "date"
1872 *
1873 * @test
1874 */
1875 public function getDataWithTypeDate() {
1876 $format = 'Y-M-D';
1877 $defaultFormat = 'd/m Y';
1878
1879 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date:' . $format));
1880 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date'));
1881 }
1882
1883 /**
1884 * Checks if getData() works with type "page"
1885 *
1886 * @test
1887 */
1888 public function getDataWithTypePage() {
1889 $uid = rand();
1890 $GLOBALS['TSFE']->page['uid'] = $uid;
1891 $this->assertEquals($uid, $this->cObj->getData('page:uid'));
1892 }
1893
1894 /**
1895 * Checks if getData() works with type "current"
1896 *
1897 * @test
1898 */
1899 public function getDataWithTypeCurrent() {
1900 $key = uniqid('someKey');
1901 $value = uniqid('someValue');
1902 $this->cObj->data[$key] = $value;
1903 $this->cObj->currentValKey = $key;
1904 $this->assertEquals($value, $this->cObj->getData('current'));
1905 }
1906
1907 /**
1908 * Checks if getData() works with type "db"
1909 *
1910 * @test
1911 */
1912 public function getDataWithTypeDb() {
1913 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
1914
1915 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
1916 $this->assertEquals($dummyRecord['title'], $this->cObj->getData('db:tt_content:106:title'));
1917 }
1918
1919 /**
1920 * Checks if getData() works with type "lll"
1921 *
1922 * @test
1923 */
1924 public function getDataWithTypeLll() {
1925 $key = uniqid('someKey');
1926 $value = uniqid('someValue');
1927 $language = uniqid('someLanguage');
1928 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
1929 $GLOBALS['TSFE']->lang = $language;
1930
1931 $this->assertEquals($value, $this->cObj->getData('lll:' . $key));
1932 }
1933
1934 /**
1935 * Checks if getData() works with type "path"
1936 *
1937 * @test
1938 */
1939 public function getDataWithTypePath() {
1940 $filenameIn = uniqid('someValue');
1941 $filenameOut = uniqid('someValue');
1942 $this->template->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
1943 $this->assertEquals($filenameOut, $this->cObj->getData('path:' . $filenameIn));
1944 }
1945
1946 /**
1947 * Checks if getData() works with type "parentRecordNumber"
1948 *
1949 * @test
1950 */
1951 public function getDataWithTypeParentRecordNumber() {
1952 $recordNumber = rand();
1953 $this->cObj->parentRecordNumber = $recordNumber;
1954 $this->assertEquals($recordNumber, $this->cObj->getData('cobj:parentRecordNumber'));
1955 }
1956
1957 /**
1958 * Checks if getData() works with type "debug:rootLine"
1959 *
1960 * @test
1961 */
1962 public function getDataWithTypeDebugRootline() {
1963 $rootline = array(
1964 0 => array('uid' => 1, 'title' => 'title1'),
1965 1 => array('uid' => 2, 'title' => 'title2'),
1966 2 => array('uid' => 3, 'title' => ''),
1967 );
1968 $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
1969 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1970
1971 $result = $this->cObj->getData('debug:rootLine');
1972 $cleanedResult = strip_tags($result);
1973 $cleanedResult = str_replace("\r", '', $cleanedResult);
1974 $cleanedResult = str_replace("\n", '', $cleanedResult);
1975 $cleanedResult = str_replace("\t", '', $cleanedResult);
1976 $cleanedResult = str_replace(' ', '', $cleanedResult);
1977
1978 $this->assertEquals($expectedResult, $cleanedResult);
1979 }
1980
1981 /**
1982 * Checks if getData() works with type "debug:fullRootLine"
1983 *
1984 * @test
1985 */
1986 public function getDataWithTypeDebugFullRootline() {
1987 $rootline = array(
1988 0 => array('uid' => 1, 'title' => 'title1'),
1989 1 => array('uid' => 2, 'title' => 'title2'),
1990 2 => array('uid' => 3, 'title' => ''),
1991 );
1992 $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
1993 $GLOBALS['TSFE']->rootLine = $rootline;
1994
1995 $result = $this->cObj->getData('debug:fullRootLine');
1996 $cleanedResult = strip_tags($result);
1997 $cleanedResult = str_replace("\r", '', $cleanedResult);
1998 $cleanedResult = str_replace("\n", '', $cleanedResult);
1999 $cleanedResult = str_replace("\t", '', $cleanedResult);
2000 $cleanedResult = str_replace(' ', '', $cleanedResult);
2001
2002 $this->assertEquals($expectedResult, $cleanedResult);
2003 }
2004
2005 /**
2006 * Checks if getData() works with type "debug:data"
2007 *
2008 * @test
2009 */
2010 public function getDataWithTypeDebugData() {
2011 $key = uniqid('someKey');
2012 $value = uniqid('someValue');
2013 $this->cObj->data = array($key => $value);
2014
2015 $expectedResult = $key . $value;
2016
2017 $result = $this->cObj->getData('debug:data');
2018 $cleanedResult = strip_tags($result);
2019 $cleanedResult = str_replace("\r", '', $cleanedResult);
2020 $cleanedResult = str_replace("\n", '', $cleanedResult);
2021 $cleanedResult = str_replace("\t", '', $cleanedResult);
2022 $cleanedResult = str_replace(' ', '', $cleanedResult);
2023
2024 $this->assertEquals($expectedResult, $cleanedResult);
2025 }
2026
2027 /**
2028 * Checks if getData() works with type "debug:register"
2029 *
2030 * @test
2031 */
2032 public function getDataWithTypeDebugRegister() {
2033 $key = uniqid('someKey');
2034 $value = uniqid('someValue');
2035 $GLOBALS['TSFE']->register = array($key => $value);
2036
2037 $expectedResult = $key . $value;
2038
2039 $result = $this->cObj->getData('debug:register');
2040 $cleanedResult = strip_tags($result);
2041 $cleanedResult = str_replace("\r", '', $cleanedResult);
2042 $cleanedResult = str_replace("\n", '', $cleanedResult);
2043 $cleanedResult = str_replace("\t", '', $cleanedResult);
2044 $cleanedResult = str_replace(' ', '', $cleanedResult);
2045
2046 $this->assertEquals($expectedResult, $cleanedResult);
2047 }
2048
2049 /**
2050 * Checks if getData() works with type "data:page"
2051 *
2052 * @test
2053 */
2054 public function getDataWithTypeDebugPage() {
2055 $uid = rand();
2056 $GLOBALS['TSFE']->page = array('uid' => $uid);
2057
2058 $expectedResult = 'uid' . $uid;
2059
2060 $result = $this->cObj->getData('debug:page');
2061 $cleanedResult = strip_tags($result);
2062 $cleanedResult = str_replace("\r", '', $cleanedResult);
2063 $cleanedResult = str_replace("\n", '', $cleanedResult);
2064 $cleanedResult = str_replace("\t", '', $cleanedResult);
2065 $cleanedResult = str_replace(' ', '', $cleanedResult);
2066
2067 $this->assertEquals($expectedResult, $cleanedResult);
2068 }
2069
2070 /**
2071 * @test
2072 */
2073 public function getTreeListReturnsChildPageUids() {
2074 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2075 $GLOBALS['TSFE']->sys_page
2076 ->expects($this->any())
2077 ->method('getRawRecord')
2078 ->will(
2079 $this->onConsecutiveCalls(
2080 array('uid' => 17),
2081 array('uid' => 321),
2082 array('uid' => 719),
2083 array('uid' => 42)
2084 )
2085 );
2086
2087 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2088 $GLOBALS['TYPO3_DB']
2089 ->expects($this->any())
2090 ->method('exec_SELECTgetRows')
2091 ->will(
2092 $this->onConsecutiveCalls(
2093 array(
2094 array('uid' => 321)
2095 ),
2096 array(
2097 array('uid' => 719)
2098 ),
2099 array(
2100 array('uid' => 42)
2101 )
2102 )
2103 );
2104 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2105 // 17 is positive, we expect 17 NOT to be included in result
2106 $result = $this->cObj->getTreeList(17, 5, 0, TRUE);
2107 $expectedResult = '42,719,321';
2108 $this->assertEquals($expectedResult, $result);
2109 }
2110
2111 /**
2112 * @test
2113 */
2114 public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue() {
2115 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2116 $GLOBALS['TSFE']->sys_page
2117 ->expects($this->any())
2118 ->method('getRawRecord')
2119 ->will(
2120 $this->onConsecutiveCalls(
2121 array('uid' => 17),
2122 array('uid' => 321),
2123 array('uid' => 719),
2124 array('uid' => 42)
2125 )
2126 );
2127
2128 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2129 $GLOBALS['TYPO3_DB']
2130 ->expects($this->any())
2131 ->method('exec_SELECTgetRows')
2132 ->will(
2133 $this->onConsecutiveCalls(
2134 array(
2135 array('uid' => 321)
2136 ),
2137 array(
2138 array('uid' => 719)
2139 ),
2140 array(
2141 array('uid' => 42)
2142 )
2143 )
2144 );
2145 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2146 // 17 is negative, we expect 17 to be included in result
2147 $result = $this->cObj->getTreeList(-17, 5, 0, TRUE);
2148 $expectedResult = '42,719,321,17';
2149 $this->assertEquals($expectedResult, $result);
2150 }
2151
2152 /**
2153 * @test
2154 */
2155 public function aTagParamsHasLeadingSpaceIfNotEmpty() {
2156 $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2157 $this->assertEquals(' data-test="testdata"', $aTagParams );
2158 }
2159
2160 /**
2161 * @test
2162 */
2163 public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams() {
2164 $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
2165 $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2166 $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
2167 }
2168
2169 /**
2170 * @test
2171 */
2172 public function aTagParamsHasNoLeadingSpaceIfEmpty() {
2173 // make sure global ATagParams are empty
2174 $GLOBALS['TSFE']->ATagParams = '';
2175 $aTagParams = $this->cObj->getATagParams(array('ATagParams' => ''));
2176 $this->assertEquals('', $aTagParams);
2177 }
2178
2179 /**
2180 * @return array
2181 */
2182 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider() {
2183 return array(
2184 array(NULL, NULL),
2185 array('', NULL),
2186 array('', array()),
2187 array('fooo', array('foo' => 'bar'))
2188 );
2189 }
2190
2191 /**
2192 * Make sure that the rendering falls back to the classic <img style if nothing else is found
2193 *
2194 * @test
2195 * @dataProvider getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider
2196 * @param string $key
2197 * @param array $configuration
2198 */
2199 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFound($key, $configuration) {
2200 $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
2201 $result = $this->cObj->getImageTagTemplate($key, $configuration);
2202 $this->assertEquals($result, $defaultImgTagTemplate);
2203 }
2204
2205 /**
2206 * @return array
2207 */
2208 public function getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider() {
2209 return array(
2210 array(
2211 'foo',
2212 array(
2213 'layout.' => array(
2214 'foo.' => array(
2215 'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2216 )
2217 )
2218 ),
2219 '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2220 )
2221
2222 );
2223 }
2224
2225 /**
2226 * Assure if a layoutKey and layout is given the selected layout is returned
2227 *
2228 * @test
2229 * @dataProvider getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider
2230 * @param string $key
2231 * @param array $configuration
2232 * @param string $expectation
2233 */
2234 public function getImageTagTemplateReturnTemplateElementIdentifiedByKey($key, $configuration, $expectation) {
2235 $result = $this->cObj->getImageTagTemplate($key, $configuration);
2236 $this->assertEquals($result, $expectation);
2237 }
2238
2239 /**
2240 * @return array
2241 */
2242 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider() {
2243 return array(
2244 array(NULL, NULL, NULL),
2245 array('foo', NULL, NULL),
2246 array('foo', array('sourceCollection.' => 1), 'bar')
2247 );
2248 }
2249
2250 /**
2251 * Make sure the source collection is empty if no valid configuration or source collection is defined
2252 *
2253 * @test
2254 * @dataProvider getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider
2255 * @param string $layoutKey
2256 * @param array $configuration
2257 * @param string $file
2258 */
2259 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefined($layoutKey, $configuration, $file) {
2260 $result = $this->cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2261 $this->assertSame($result, '');
2262 }
2263
2264 /**
2265 * Make sure the generation of subimages calls the generation of the subimages and uses the layout -> source template
2266 *
2267 * @test
2268 */
2269 public function getImageSourceCollectionRendersDefinedSources() {
2270 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2271 $cObj = $this->getMock(
2272 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2273 array('stdWrap','getImgResource')
2274 );
2275 $cObj->start(array(), 'tt_content');
2276
2277 $layoutKey = 'test';
2278
2279 $configuration = array(
2280 'layoutKey' => 'test',
2281 'layout.' => array (
2282 'test.' => array(
2283 'element' => '<img ###SRC### ###SRCCOLLECTION### ###SELFCLOSINGTAGSLASH###>',
2284 'source' => '---###SRC###---'
2285 )
2286 ),
2287 'sourceCollection.' => array(
2288 '1.' => array(
2289 'width' => '200'
2290 )
2291 )
2292 );
2293
2294 $file = 'testImageName';
2295
2296 // Avoid calling of stdWrap
2297 $cObj
2298 ->expects($this->any())
2299 ->method('stdWrap')
2300 ->will($this->returnArgument(0));
2301
2302 // Avoid calling of imgResource
2303 $cObj
2304 ->expects($this->exactly(1))
2305 ->method('getImgResource')
2306 ->with($this->equalTo('testImageName'))
2307 ->will($this->returnValue(array(100, 100, NULL, 'bar')));
2308
2309 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2310
2311 $this->assertEquals('---bar---', $result);
2312 }
2313
2314 /**
2315 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyDefault test
2316 *
2317 * @return array multi-dimensional array with the second level like this:
2318 * @see getImageSourceCollectionRendersDefinedLayoutKeyDefault
2319 */
2320 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider() {
2321 /**
2322 * @see css_styled_content/static/setup.txt
2323 */
2324 $sourceCollectionArray = array(
2325 'small.' => array(
2326 'width' => '200',
2327 'srcsetCandidate' => '600w',
2328 'mediaQuery' => '(max-device-width: 600px)',
2329 'dataKey' => 'small',
2330 ),
2331 'smallRetina.' => array(
2332 'if.directReturn' => 0,
2333 'width' => '200',
2334 'pixelDensity' => '2',
2335 'srcsetCandidate' => '600w 2x',
2336 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2337 'dataKey' => 'smallRetina',
2338 )
2339 );
2340 return array(
2341 array(
2342 'default',
2343 array(
2344 'layoutKey' => 'default',
2345 'layout.' => array (
2346 'default.' => array(
2347 'element' => '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>',
2348 'source' => ''
2349 )
2350 ),
2351 'sourceCollection.' => $sourceCollectionArray
2352 )
2353 ),
2354 );
2355 }
2356
2357 /**
2358 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2359 *
2360 * @test
2361 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider
2362 * @param string $layoutKey
2363 * @param array $configuration
2364 */
2365 public function getImageSourceCollectionRendersDefinedLayoutKeyDefault($layoutKey , $configuration) {
2366 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2367 $cObj = $this->getMock(
2368 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2369 array('stdWrap','getImgResource')
2370 );
2371 $cObj->start(array(), 'tt_content');
2372
2373 $file = 'testImageName';
2374
2375 // Avoid calling of stdWrap
2376 $cObj
2377 ->expects($this->any())
2378 ->method('stdWrap')
2379 ->will($this->returnArgument(0));
2380
2381 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2382
2383 $this->assertEmpty($result);
2384 }
2385
2386 /**
2387 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyData test
2388 *
2389 * @return array multi-dimensional array with the second level like this:
2390 * @see getImageSourceCollectionRendersDefinedLayoutKeyData
2391 */
2392 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider() {
2393 /**
2394 * @see css_styled_content/static/setup.txt
2395 */
2396 $sourceCollectionArray = array(
2397 'small.' => array(
2398 'width' => '200',
2399 'srcsetCandidate' => '600w',
2400 'mediaQuery' => '(max-device-width: 600px)',
2401 'dataKey' => 'small',
2402 ),
2403 'smallRetina.' => array(
2404 'if.directReturn' => 1,
2405 'width' => '200',
2406 'pixelDensity' => '2',
2407 'srcsetCandidate' => '600w 2x',
2408 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2409 'dataKey' => 'smallRetina',
2410 )
2411 );
2412 return array(
2413 array(
2414 'srcset',
2415 array(
2416 'layoutKey' => 'srcset',
2417 'layout.' => array (
2418 'srcset.' => array(
2419 'element' => '<img src="###SRC###" srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2420 'source' => '|*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###'
2421 )
2422 ),
2423 'sourceCollection.' => $sourceCollectionArray
2424 ),
2425 'xhtml_strict',
2426 'bar-file.jpg 600w,bar-file.jpg 600w 2x',
2427 ),
2428 array(
2429 'picture',
2430 array(
2431 'layoutKey' => 'picture',
2432 'layout.' => array (
2433 'picture.' => array(
2434 'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2435 'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2436 )
2437 ),
2438 'sourceCollection.' => $sourceCollectionArray,
2439 ),
2440 'xhtml_strict',
2441 '<source src="bar-file.jpg" media="(max-device-width: 600px)" /><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)" />',
2442 ),
2443 array(
2444 'picture',
2445 array(
2446 'layoutKey' => 'picture',
2447 'layout.' => array (
2448 'picture.' => array(
2449 'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2450 'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2451 )
2452 ),
2453 'sourceCollection.' => $sourceCollectionArray,
2454 ),
2455 '',
2456 '<source src="bar-file.jpg" media="(max-device-width: 600px)"><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)">',
2457 ),
2458 array(
2459 'data',
2460 array(
2461 'layoutKey' => 'data',
2462 'layout.' => array (
2463 'data.' => array(
2464 'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2465 'source' => 'data-###DATAKEY###="###SRC###"'
2466 )
2467 ),
2468 'sourceCollection.' => $sourceCollectionArray
2469 ),
2470 'xhtml_strict',
2471 'data-small="bar-file.jpg"data-smallRetina="bar-file.jpg"',
2472 ),
2473 );
2474 }
2475
2476 /**
2477 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2478 *
2479 * @test
2480 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider
2481 * @param string $layoutKey
2482 * @param array $configuration
2483 * @param string $xhtmlDoctype
2484 * @param string $expectedHtml
2485 */
2486 public function getImageSourceCollectionRendersDefinedLayoutKeyData($layoutKey , $configuration, $xhtmlDoctype, $expectedHtml) {
2487 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2488 $cObj = $this->getMock(
2489 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2490 array('stdWrap','getImgResource')
2491 );
2492 $cObj->start(array(), 'tt_content');
2493
2494 $file = 'testImageName';
2495
2496 $GLOBALS['TSFE']->xhtmlDoctype = $xhtmlDoctype;
2497
2498 // Avoid calling of stdWrap
2499 $cObj
2500 ->expects($this->any())
2501 ->method('stdWrap')
2502 ->will($this->returnArgument(0));
2503
2504 // Avoid calling of imgResource
2505 $cObj
2506 ->expects($this->exactly(2))
2507 ->method('getImgResource')
2508 ->with($this->equalTo('testImageName'))
2509 ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2510
2511 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2512
2513 $this->assertEquals($expectedHtml, $result);
2514 }
2515
2516 /**
2517 * Make sure the hook in get sourceCollection is called
2518 *
2519 * @test
2520 */
2521 public function getImageSourceCollectionHookCalled() {
2522 $this->cObj = $this->getAccessibleMock(
2523 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2524 array('getResourceFactory', 'stdWrap', 'getImgResource')
2525 );
2526 $this->cObj->start(array(), 'tt_content');
2527
2528 // Avoid calling stdwrap and getImgResource
2529 $this->cObj->expects($this->any())
2530 ->method('stdWrap')
2531 ->will($this->returnArgument(0));
2532
2533 $this->cObj->expects($this->any())
2534 ->method('getImgResource')
2535 ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2536
2537 $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array(), array(), '', FALSE);
2538 $this->cObj->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
2539
2540 $className = uniqid('tx_coretest_getImageSourceCollectionHookCalled');
2541 $getImageSourceCollectionHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectOneSourceCollectionHookInterface', array('getOneSourceCollection'), array(), $className);
2542 $GLOBALS['T3_VAR']['getUserObj'][$className] = $getImageSourceCollectionHookMock;
2543 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'][] = $className;
2544
2545 $getImageSourceCollectionHookMock
2546 ->expects($this->exactly(1))
2547 ->method('getOneSourceCollection')
2548 ->will($this->returnCallback(array($this, 'isGetOneSourceCollectionCalledCallback')));
2549
2550 $configuration = array(
2551 'layoutKey' => 'data',
2552 'layout.' => array (
2553 'data.' => array(
2554 'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2555 'source' => 'data-###DATAKEY###="###SRC###"'
2556 )
2557 ),
2558 'sourceCollection.' => array(
2559 'small.' => array(
2560 'width' => '200',
2561 'srcsetCandidate' => '600w',
2562 'mediaQuery' => '(max-device-width: 600px)',
2563 'dataKey' => 'small',
2564 ),
2565 ),
2566 );
2567
2568 $result = $this->cObj->getImageSourceCollection('data', $configuration, uniqid('testImage-'));
2569
2570 $this->assertSame($result, 'isGetOneSourceCollectionCalledCallback');
2571 }
2572
2573 /**
2574 * Handles the arguments that have been sent to the getImgResource hook.
2575 *
2576 * @return string
2577 * @see getImageSourceCollectionHookCalled
2578 */
2579 public function isGetOneSourceCollectionCalledCallback() {
2580 list($sourceRenderConfiguration, $sourceConfiguration, $oneSourceCollection, $parent) = func_get_args();
2581 $this->assertTrue(is_array($sourceRenderConfiguration));
2582 $this->assertTrue(is_array($sourceConfiguration));
2583 return 'isGetOneSourceCollectionCalledCallback';
2584 }
2585
2586 /**
2587 * @param string $expected The expected URL
2588 * @param string $url The URL to parse and manipulate
2589 * @param array $configuration The configuration array
2590 * @test
2591 * @dataProvider forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider
2592 */
2593 public function forceAbsoluteUrlReturnsCorrectAbsoluteUrl($expected, $url, array $configuration) {
2594 // Force hostname
2595 $this->cObj->expects($this->any())->method('getEnvironmentVariable')->will($this->returnValueMap(
2596 array(
2597 array('HTTP_HOST', 'localhost'),
2598 array('TYPO3_SITE_PATH', '/'),
2599 )
2600 ));
2601
2602 $this->assertEquals($expected, $this->cObj->_call('forceAbsoluteUrl', $url, $configuration));
2603 }
2604
2605 /**
2606 * @return array The test data for forceAbsoluteUrlReturnsAbsoluteUrl
2607 */
2608 public function forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider() {
2609 return array(
2610 'Missing forceAbsoluteUrl leaves URL untouched' => array(
2611 'foo',
2612 'foo',
2613 array()
2614 ),
2615 'Absolute URL stays unchanged' => array(
2616 'http://example.org/',
2617 'http://example.org/',
2618 array(
2619 'forceAbsoluteUrl' => '1'
2620 )
2621 ),
2622 'Absolute URL stays unchanged 2' => array(
2623 'http://example.org/resource.html',
2624 'http://example.org/resource.html',
2625 array(
2626 'forceAbsoluteUrl' => '1'
2627 )
2628 ),
2629 'Scheme and host w/o ending slash stays unchanged' => array(
2630 'http://example.org',
2631 'http://example.org',
2632 array(
2633 'forceAbsoluteUrl' => '1'
2634 )
2635 ),
2636 'Scheme can be forced' => array(
2637 'typo3://example.org',
2638 'http://example.org',
2639 array(
2640 'forceAbsoluteUrl' => '1',
2641 'forceAbsoluteUrl.' => array(
2642 'scheme' => 'typo3'
2643 )
2644 )
2645 ),
2646 'Scheme can be forced with relative path' => array(
2647 'typo3://localhost/fileadmin/dummy.txt',
2648 '/fileadmin/dummy.txt', // this leading slash is weird, but we need it to really get an absolute link
2649 array(
2650 'forceAbsoluteUrl' => '1',
2651 'forceAbsoluteUrl.' => array(
2652 'scheme' => 'typo3'
2653 )
2654 )
2655 ),
2656 );
2657 }
2658 }