[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 * @test
1047 */
1048 public function recursiveStdWrapProperlyRendersBasicString() {
1049 $stdWrapConfiguration = array(
1050 'noTrimWrap' => '|| 123|',
1051 'stdWrap.' => array(
1052 'wrap' => '<b>|</b>'
1053 )
1054 );
1055 $this->assertSame(
1056 '<b>Test</b> 123',
1057 $this->cObj->stdWrap('Test', $stdWrapConfiguration)
1058 );
1059 }
1060
1061 /**
1062 * @test
1063 */
1064 public function recursiveStdWrapIsOnlyCalledOnce() {
1065 $stdWrapConfiguration = array(
1066 'append' => 'TEXT',
1067 'append.' => array(
1068 'data' => 'register:Counter'
1069 ),
1070 'stdWrap.' => array(
1071 'append' => 'LOAD_REGISTER',
1072 'append.' => array(
1073 'Counter.' => array(
1074 'prioriCalc' => 'intval',
1075 'cObject' => 'TEXT',
1076 'cObject.' => array(
1077 'data' => 'register:Counter',
1078 'wrap' => '|+1',
1079 )
1080 )
1081 )
1082 )
1083 );
1084 $this->assertSame(
1085 'Counter:1',
1086 $this->cObj->stdWrap('Counter:', $stdWrapConfiguration)
1087 );
1088 }
1089
1090 /**
1091 * Data provider for the numberFormat test
1092 *
1093 * @return array multi-dimensional array with the second level like this:
1094 * @see numberFormat
1095 */
1096 public function numberFormatDataProvider() {
1097 $data = array(
1098 'testing decimals' => array(
1099 0.8,
1100 array(
1101 'decimals' => 2
1102 ),
1103 '0.80'
1104 ),
1105 'testing decimals with input as string' => array(
1106 '0.8',
1107 array(
1108 'decimals' => 2
1109 ),
1110 '0.80'
1111 ),
1112 'testing dec_point' => array(
1113 0.8,
1114 array(
1115 'decimals' => 1,
1116 'dec_point' => ','
1117 ),
1118 '0,8'
1119 ),
1120 'testing thousands_sep' => array(
1121 999.99,
1122 array(
1123 'decimals' => 0,
1124 'thousands_sep.' => array(
1125 'char' => 46
1126 )
1127 ),
1128 '1.000'
1129 ),
1130 'testing mixture' => array(
1131 1281731.45,
1132 array(
1133 'decimals' => 1,
1134 'dec_point.' => array(
1135 'char' => 44
1136 ),
1137 'thousands_sep.' => array(
1138 'char' => 46
1139 )
1140 ),
1141 '1.281.731,5'
1142 )
1143 );
1144 return $data;
1145 }
1146
1147 /**
1148 * Check if stdWrap.numberFormat and all of its properties work properly
1149 *
1150 * @dataProvider numberFormatDataProvider
1151 * @test
1152 */
1153 public function numberFormat($float, $formatConf, $expected) {
1154 $result = $this->cObj->numberFormat($float, $formatConf);
1155 $this->assertEquals($expected, $result);
1156 }
1157
1158 /**
1159 * Data provider for the replacement test
1160 *
1161 * @return array multi-dimensional array with the second level like this:
1162 * @see replacement
1163 */
1164 public function replacementDataProvider() {
1165 $data = array(
1166 'multiple replacements, including regex' => array(
1167 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1168 array(
1169 'replacement.' => array(
1170 '120.' => array(
1171 'search' => 'in da hood',
1172 'replace' => 'around the block'
1173 ),
1174 '20.' => array(
1175 'search' => '_',
1176 'replace.' => array('char' => '32')
1177 ),
1178 '130.' => array(
1179 'search' => '#a (Cat|Dog|Tiger)#i',
1180 'replace' => 'an animal',
1181 'useRegExp' => '1'
1182 )
1183 )
1184 ),
1185 'There is an animal, an animal and an animal around the block! Yeah!'
1186 ),
1187 'replacement with optionSplit, normal pattern' => array(
1188 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1189 array(
1190 'replacement.' => array(
1191 '10.' => array(
1192 'search' => '_',
1193 'replace' => '1 || 2 || 3',
1194 'useOptionSplitReplace' => '1'
1195 ),
1196 )
1197 ),
1198 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1199 ),
1200 'replacement with optionSplit, using regex' => array(
1201 'There is a cat, a dog and a tiger in da hood! Yeah!',
1202 array(
1203 'replacement.' => array(
1204 '10.' => array(
1205 'search' => '#(a) (Cat|Dog|Tiger)#i',
1206 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1207 'useOptionSplitReplace' => '1',
1208 'useRegExp' => '1'
1209 )
1210 )
1211 ),
1212 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1213 ),
1214 );
1215 return $data;
1216 }
1217
1218 /**
1219 * Check if stdWrap.replacement and all of its properties work properly
1220 *
1221 * @dataProvider replacementDataProvider
1222 * @test
1223 */
1224 public function replacement($input, $conf, $expected) {
1225 $result = $this->cObj->stdWrap_replacement($input, $conf);
1226 $this->assertEquals($expected, $result);
1227 }
1228
1229 /**
1230 * Data provider for the getQuery test
1231 *
1232 * @return array multi-dimensional array with the second level like this:
1233 * @see getQuery
1234 */
1235 public function getQueryDataProvider() {
1236 $data = array(
1237 'testing empty conf' => array(
1238 'tt_content',
1239 array(),
1240 array(
1241 'SELECT' => '*'
1242 )
1243 ),
1244 'testing #17284: adding uid/pid for workspaces' => array(
1245 'tt_content',
1246 array(
1247 'selectFields' => 'header,bodytext'
1248 ),
1249 array(
1250 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1251 )
1252 ),
1253 'testing #17284: no need to add' => array(
1254 'tt_content',
1255 array(
1256 'selectFields' => 'tt_content.*'
1257 ),
1258 array(
1259 'SELECT' => 'tt_content.*'
1260 )
1261 ),
1262 'testing #17284: no need to add #2' => array(
1263 'tt_content',
1264 array(
1265 'selectFields' => '*'
1266 ),
1267 array(
1268 'SELECT' => '*'
1269 )
1270 ),
1271 'testing #29783: joined tables, prefix tablename' => array(
1272 'tt_content',
1273 array(
1274 'selectFields' => 'tt_content.header,be_users.username',
1275 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1276 ),
1277 array(
1278 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1279 )
1280 ),
1281 'testing #34152: single count(*), add nothing' => array(
1282 'tt_content',
1283 array(
1284 'selectFields' => 'count(*)'
1285 ),
1286 array(
1287 'SELECT' => 'count(*)'
1288 )
1289 ),
1290 'testing #34152: single max(crdate), add nothing' => array(
1291 'tt_content',
1292 array(
1293 'selectFields' => 'max(crdate)'
1294 ),
1295 array(
1296 'SELECT' => 'max(crdate)'
1297 )
1298 ),
1299 'testing #34152: single min(crdate), add nothing' => array(
1300 'tt_content',
1301 array(
1302 'selectFields' => 'min(crdate)'
1303 ),
1304 array(
1305 'SELECT' => 'min(crdate)'
1306 )
1307 ),
1308 'testing #34152: single sum(is_siteroot), add nothing' => array(
1309 'tt_content',
1310 array(
1311 'selectFields' => 'sum(is_siteroot)'
1312 ),
1313 array(
1314 'SELECT' => 'sum(is_siteroot)'
1315 )
1316 ),
1317 'testing #34152: single avg(crdate), add nothing' => array(
1318 'tt_content',
1319 array(
1320 'selectFields' => 'avg(crdate)'
1321 ),
1322 array(
1323 'SELECT' => 'avg(crdate)'
1324 )
1325 )
1326 );
1327 return $data;
1328 }
1329
1330 /**
1331 * Check if sanitizeSelectPart works as expected
1332 *
1333 * @dataProvider getQueryDataProvider
1334 * @test
1335 */
1336 public function getQuery($table, $conf, $expected) {
1337 $GLOBALS['TCA'] = array(
1338 'pages' => array(
1339 'ctrl' => array(
1340 'enablecolumns' => array(
1341 'disabled' => 'hidden'
1342 )
1343 )
1344 ),
1345 'tt_content' => array(
1346 'ctrl' => array(
1347 'enablecolumns' => array(
1348 'disabled' => 'hidden'
1349 ),
1350 'versioningWS' => 2
1351 )
1352 ),
1353 );
1354 $result = $this->cObj->getQuery($table, $conf, TRUE);
1355 foreach ($expected as $field => $value) {
1356 $this->assertEquals($value, $result[$field]);
1357 }
1358 }
1359
1360 /**
1361 * @test
1362 */
1363 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet() {
1364 $GLOBALS['TCA'] = array(
1365 'pages' => array(
1366 'ctrl' => array(
1367 'enablecolumns' => array(
1368 'disabled' => 'hidden'
1369 )
1370 )
1371 ),
1372 'tt_content' => array(
1373 'ctrl' => array(
1374 'enablecolumns' => array(
1375 'disabled' => 'hidden'
1376 )
1377 )
1378 ),
1379 );
1380 $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
1381 $this->cObj->start(array(), 'tt_content');
1382 $conf = array(
1383 'recursive' => '15',
1384 'pidInList' => '16, -35'
1385 );
1386 $this->cObj->expects($this->at(0))
1387 ->method('getTreeList')
1388 ->with(-16, 15)
1389 ->will($this->returnValue('15,16'));
1390 $this->cObj->expects($this->at(1))
1391 ->method('getTreeList')
1392 ->with(-35, 15)
1393 ->will($this->returnValue('15,35'));
1394 $this->cObj->getQuery('tt_content', $conf, TRUE);
1395 }
1396
1397 /**
1398 * @test
1399 */
1400 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet() {
1401 $GLOBALS['TCA'] = array(
1402 'pages' => array(
1403 'ctrl' => array(
1404 'enablecolumns' => array(
1405 'disabled' => 'hidden'
1406 )
1407 )
1408 ),
1409 'tt_content' => array(
1410 'ctrl' => array(
1411 'enablecolumns' => array(
1412 'disabled' => 'hidden'
1413 )
1414 )
1415 ),
1416 );
1417 $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
1418 $GLOBALS['TSFE']->id = 27;
1419 $this->cObj->start(array(), 'tt_content');
1420 $conf = array(
1421 'pidInList' => 'this',
1422 'recursive' => '4'
1423 );
1424 $this->cObj->expects($this->once())
1425 ->method('getTreeList')
1426 ->with(-27)
1427 ->will($this->returnValue('27'));
1428 $this->cObj->getQuery('tt_content', $conf, TRUE);
1429 }
1430
1431 /**
1432 * Data provider for the stdWrap_strftime test
1433 *
1434 * @return array multi-dimensional array with the second level like this:
1435 * @see stdWrap_strftime
1436 */
1437 public function stdWrap_strftimeReturnsFormattedStringDataProvider() {
1438 $data = array(
1439 'given timestamp' => array(
1440 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1441 array(
1442 'strftime' => '%d-%m-%Y',
1443 ),
1444 ),
1445 'empty string' => array(
1446 '',
1447 array(
1448 'strftime' => '%d-%m-%Y',
1449 ),
1450 ),
1451 'testing null' => array(
1452 NULL,
1453 array(
1454 'strftime' => '%d-%m-%Y',
1455 ),
1456 ),
1457 );
1458 return $data;
1459 }
1460
1461 /**
1462 * @test
1463 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1464 */
1465 public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1466 // Set exec_time to a hard timestamp
1467 $GLOBALS['EXEC_TIME'] = 1346500800;
1468 // Save current timezone and set to UTC to make the system under test behave
1469 // the same in all server timezone settings
1470 $timezoneBackup = date_default_timezone_get();
1471 date_default_timezone_set('UTC');
1472
1473 $result = $this->cObj->stdWrap_strftime($content, $conf);
1474
1475 // Reset timezone
1476 date_default_timezone_set($timezoneBackup);
1477
1478 $this->assertEquals('01-09-2012', $result);
1479 }
1480
1481 /**
1482 * @param string|NULL $content
1483 * @param array $configuration
1484 * @param string $expected
1485 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
1486 * @test
1487 */
1488 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1489 $result = $this->cObj->stdWrap_ifNull($content, $configuration);
1490 $this->assertEquals($expected, $result);
1491 }
1492
1493 /**
1494 * Data provider for stdWrap_ifNullDeterminesNullValues test
1495 *
1496 * @return array
1497 */
1498 public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
1499 return array(
1500 'null value' => array(
1501 NULL,
1502 array(
1503 'ifNull' => '1',
1504 ),
1505 '1',
1506 ),
1507 'zero value' => array(
1508 '0',
1509 array(
1510 'ifNull' => '1',
1511 ),
1512 '0',
1513 ),
1514 );
1515 }
1516
1517 /**
1518 * @param $content
1519 * @param array $configuration
1520 * @param $expected
1521 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
1522 * @test
1523 */
1524 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1525 $result = $this->cObj->stdWrap_noTrimWrap($content, $configuration);
1526 $this->assertEquals($expected, $result);
1527 }
1528
1529 /**
1530 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
1531 *
1532 * @return array
1533 */
1534 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
1535 return array(
1536 'No char given' => array(
1537 'middle',
1538 array(
1539 'noTrimWrap' => '| left | right |',
1540 ),
1541 ' left middle right '
1542 ),
1543 'Zero char given' => array(
1544 'middle',
1545 array(
1546 'noTrimWrap' => '0 left 0 right 0',
1547 'noTrimWrap.' => array('splitChar' => '0'),
1548
1549 ),
1550 ' left middle right '
1551 ),
1552 'Default char given' => array(
1553 'middle',
1554 array(
1555 'noTrimWrap' => '| left | right |',
1556 'noTrimWrap.' => array('splitChar' => '|'),
1557 ),
1558 ' left middle right '
1559 ),
1560 'Split char is a' => array(
1561 'middle',
1562 array(
1563 'noTrimWrap' => 'a left a right a',
1564 'noTrimWrap.' => array('splitChar' => 'a'),
1565 ),
1566 ' left middle right '
1567 ),
1568 'Split char is multi-char (ab)' => array(
1569 'middle',
1570 array(
1571 'noTrimWrap' => 'ab left ab right ab',
1572 'noTrimWrap.' => array('splitChar' => 'ab'),
1573 ),
1574 ' left middle right '
1575 ),
1576 'Split char accepts stdWrap' => array(
1577 'middle',
1578 array(
1579 'noTrimWrap' => 'abc left abc right abc',
1580 'noTrimWrap.' => array(
1581 'splitChar' => 'b',
1582 'splitChar.' => array('wrap' => 'a|c'),
1583 ),
1584 ),
1585 ' left middle right '
1586 ),
1587 );
1588 }
1589
1590 /**
1591 * @param array $expectedTags
1592 * @param array $configuration
1593 * @test
1594 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
1595 */
1596 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
1597 $this->cObj->stdWrap_addPageCacheTags('', $configuration);
1598 $this->assertEquals($expectedTags, $this->tsfe->_get('pageCacheTags'));
1599 }
1600
1601 /**
1602 * @return array
1603 */
1604 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
1605 return array(
1606 'No Tag' => array(
1607 array(),
1608 array('addPageCacheTags' => ''),
1609 ),
1610 'Two expectedTags' => array(
1611 array('tag1', 'tag2'),
1612 array('addPageCacheTags' => 'tag1,tag2'),
1613 ),
1614 'Two expectedTags plus one with stdWrap' => array(
1615 array('tag1', 'tag2', 'tag3'),
1616 array(
1617 'addPageCacheTags' => 'tag1,tag2',
1618 'addPageCacheTags.' => array('wrap' => '|,tag3')
1619 ),
1620 ),
1621 );
1622 }
1623
1624 /**
1625 * Data provider for stdWrap_encodeForJavaScriptValue test
1626 *
1627 * @return array multi-dimensional array with the second level like this:
1628 * @see encodeForJavaScriptValue
1629 */
1630 public function stdWrap_encodeForJavaScriptValueDataProvider() {
1631 return array(
1632 'double quote in string' => array(
1633 'double quote"',
1634 array(),
1635 '\'double\u0020quote\u0022\''
1636 ),
1637 'backslash in string' => array(
1638 'backslash \\',
1639 array(),
1640 '\'backslash\u0020\u005C\''
1641 ),
1642 'exclamation mark' => array(
1643 'exclamation!',
1644 array(),
1645 '\'exclamation\u0021\''
1646 ),
1647 'whitespace tab, newline and carriage return' => array(
1648 "white\tspace\ns\r",
1649 array(),
1650 '\'white\u0009space\u000As\u000D\''
1651 ),
1652 'single quote in string' => array(
1653 'single quote \'',
1654 array(),
1655 '\'single\u0020quote\u0020\u0027\''
1656 ),
1657 'tag' => array(
1658 '<tag>',
1659 array(),
1660 '\'\u003Ctag\u003E\''
1661 ),
1662 'ampersand in string' => array(
1663 'amper&sand',
1664 array(),
1665 '\'amper\u0026sand\''
1666 ),
1667 );
1668 }
1669
1670 /**
1671 * Check if encodeForJavaScriptValue works properly
1672 *
1673 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
1674 * @test
1675 */
1676 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected) {
1677 $result = $this->cObj->stdWrap_encodeForJavaScriptValue($input, $conf);
1678 $this->assertEquals($expected, $result);
1679 }
1680
1681
1682 /////////////////////////////
1683 // Tests concerning getData()
1684 /////////////////////////////
1685
1686 /**
1687 * @return array
1688 */
1689 public function getDataWithTypeGpDataProvider() {
1690 return array(
1691 'Value in get-data' => array('onlyInGet', 'GetValue'),
1692 'Value in post-data' => array('onlyInPost', 'PostValue'),
1693 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
1694 );
1695 }
1696
1697 /**
1698 * Checks if getData() works with type "gp"
1699 *
1700 * @test
1701 * @dataProvider getDataWithTypeGpDataProvider
1702 */
1703 public function getDataWithTypeGp($key, $expectedValue) {
1704 $_GET = array(
1705 'onlyInGet' => 'GetValue',
1706 'inGetAndPost' => 'ValueInGet',
1707 );
1708 $_POST = array(
1709 'onlyInPost' => 'PostValue',
1710 'inGetAndPost' => 'ValueInPost',
1711 );
1712 $this->assertEquals($expectedValue, $this->cObj->getData('gp:' . $key));
1713 }
1714
1715 /**
1716 * Checks if getData() works with type "tsfe"
1717 *
1718 * @test
1719 */
1720 public function getDataWithTypeTsfe() {
1721 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('tsfe:renderCharset'));
1722 }
1723
1724 /**
1725 * Checks if getData() works with type "getenv"
1726 *
1727 * @test
1728 */
1729 public function getDataWithTypeGetenv() {
1730 $envName = uniqid('frontendtest');
1731 $value = uniqid('someValue');
1732 putenv($envName . '=' . $value);
1733 $this->assertEquals($value, $this->cObj->getData('getenv:' . $envName));
1734 }
1735
1736 /**
1737 * Checks if getData() works with type "getindpenv"
1738 *
1739 * @test
1740 */
1741 public function getDataWithTypeGetindpenv() {
1742 $this->cObj->expects($this->once())->method('getEnvironmentVariable')
1743 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
1744 $this->assertEquals('dummyPath', $this->cObj->getData('getindpenv:SCRIPT_FILENAME'));
1745 }
1746
1747 /**
1748 * Checks if getData() works with type "getindpenv"
1749 *
1750 * @test
1751 */
1752 public function getDataWithTypeField() {
1753 $key = 'someKey';
1754 $value = 'someValue';
1755 $field = array($key => $value);
1756
1757 $this->assertEquals($value, $this->cObj->getData('field:' . $key, $field));
1758 }
1759
1760 /**
1761 * Basic check if getData gets the uid of a file object
1762 *
1763 * @test
1764 */
1765 public function getDataWithTypeFileReturnsUidOfFileObject() {
1766 $uid = uniqid();
1767 $file = $this->getMock('TYPO3\\CMS\\Core\\Resource\File', array(), array(), '', FALSE);
1768 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
1769 $this->cObj->setCurrentFile($file);
1770 $this->assertEquals($uid, $this->cObj->getData('file:current:uid'));
1771 }
1772
1773 /**
1774 * Checks if getData() works with type "parameters"
1775 *
1776 * @test
1777 */
1778 public function getDataWithTypeParameters() {
1779 $key = uniqid('someKey');
1780 $value = uniqid('someValue');
1781 $this->cObj->parameters[$key] = $value;
1782
1783 $this->assertEquals($value, $this->cObj->getData('parameters:' . $key));
1784 }
1785
1786 /**
1787 * Checks if getData() works with type "register"
1788 *
1789 * @test
1790 */
1791 public function getDataWithTypeRegister() {
1792 $key = uniqid('someKey');
1793 $value = uniqid('someValue');
1794 $GLOBALS['TSFE']->register[$key] = $value;
1795
1796 $this->assertEquals($value, $this->cObj->getData('register:' . $key));
1797 }
1798
1799 /**
1800 * Checks if getData() works with type "level"
1801 *
1802 * @test
1803 */
1804 public function getDataWithTypeLevel() {
1805 $rootline = array(
1806 0 => array('uid' => 1, 'title' => 'title1'),
1807 1 => array('uid' => 2, 'title' => 'title2'),
1808 2 => array('uid' => 3, 'title' => 'title3'),
1809 );
1810
1811 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1812 $this->assertEquals(2, $this->cObj->getData('level'));
1813 }
1814
1815 /**
1816 * Checks if getData() works with type "global"
1817 *
1818 * @test
1819 */
1820 public function getDataWithTypeGlobal() {
1821 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('global:TSFE|renderCharset'));
1822 }
1823
1824 /**
1825 * Checks if getData() works with type "leveltitle"
1826 *
1827 * @test
1828 */
1829 public function getDataWithTypeLeveltitle() {
1830 $rootline = array(
1831 0 => array('uid' => 1, 'title' => 'title1'),
1832 1 => array('uid' => 2, 'title' => 'title2'),
1833 2 => array('uid' => 3, 'title' => ''),
1834 );
1835
1836 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1837 $this->assertEquals('', $this->cObj->getData('leveltitle:-1'));
1838 // since "title3" is not set, it will slide to "title2"
1839 $this->assertEquals('title2', $this->cObj->getData('leveltitle:-1,slide'));
1840 }
1841
1842 /**
1843 * Checks if getData() works with type "levelmedia"
1844 *
1845 * @test
1846 */
1847 public function getDataWithTypeLevelmedia() {
1848 $rootline = array(
1849 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
1850 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
1851 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
1852 );
1853
1854 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1855 $this->assertEquals('', $this->cObj->getData('levelmedia:-1'));
1856 // since "title3" is not set, it will slide to "title2"
1857 $this->assertEquals('media2', $this->cObj->getData('levelmedia:-1,slide'));
1858 }
1859
1860 /**
1861 * Checks if getData() works with type "leveluid"
1862 *
1863 * @test
1864 */
1865 public function getDataWithTypeLeveluid() {
1866 $rootline = array(
1867 0 => array('uid' => 1, 'title' => 'title1'),
1868 1 => array('uid' => 2, 'title' => 'title2'),
1869 2 => array('uid' => 3, 'title' => 'title3'),
1870 );
1871
1872 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1873 $this->assertEquals(3, $this->cObj->getData('leveluid:-1'));
1874 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
1875 $this->assertEquals(3, $this->cObj->getData('leveluid:-1,slide'));
1876 }
1877
1878 /**
1879 * Checks if getData() works with type "levelfield"
1880 *
1881 * @test
1882 */
1883 public function getDataWithTypeLevelfield() {
1884 $rootline = array(
1885 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1886 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1887 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
1888 );
1889
1890 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1891 $this->assertEquals('', $this->cObj->getData('levelfield:-1,testfield'));
1892 $this->assertEquals('field2', $this->cObj->getData('levelfield:-1,testfield,slide'));
1893 }
1894
1895 /**
1896 * Checks if getData() works with type "fullrootline"
1897 *
1898 * @test
1899 */
1900 public function getDataWithTypeFullrootline() {
1901 $rootline1 = array(
1902 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1903 );
1904 $rootline2 = array(
1905 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1906 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1907 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
1908 );
1909
1910 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
1911 $GLOBALS['TSFE']->rootLine = $rootline2;
1912 $this->assertEquals('field2', $this->cObj->getData('fullrootline:-1,testfield'));
1913 }
1914
1915 /**
1916 * Checks if getData() works with type "date"
1917 *
1918 * @test
1919 */
1920 public function getDataWithTypeDate() {
1921 $format = 'Y-M-D';
1922 $defaultFormat = 'd/m Y';
1923
1924 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date:' . $format));
1925 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date'));
1926 }
1927
1928 /**
1929 * Checks if getData() works with type "page"
1930 *
1931 * @test
1932 */
1933 public function getDataWithTypePage() {
1934 $uid = rand();
1935 $GLOBALS['TSFE']->page['uid'] = $uid;
1936 $this->assertEquals($uid, $this->cObj->getData('page:uid'));
1937 }
1938
1939 /**
1940 * Checks if getData() works with type "current"
1941 *
1942 * @test
1943 */
1944 public function getDataWithTypeCurrent() {
1945 $key = uniqid('someKey');
1946 $value = uniqid('someValue');
1947 $this->cObj->data[$key] = $value;
1948 $this->cObj->currentValKey = $key;
1949 $this->assertEquals($value, $this->cObj->getData('current'));
1950 }
1951
1952 /**
1953 * Checks if getData() works with type "db"
1954 *
1955 * @test
1956 */
1957 public function getDataWithTypeDb() {
1958 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
1959
1960 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
1961 $this->assertEquals($dummyRecord['title'], $this->cObj->getData('db:tt_content:106:title'));
1962 }
1963
1964 /**
1965 * Checks if getData() works with type "lll"
1966 *
1967 * @test
1968 */
1969 public function getDataWithTypeLll() {
1970 $key = uniqid('someKey');
1971 $value = uniqid('someValue');
1972 $language = uniqid('someLanguage');
1973 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
1974 $GLOBALS['TSFE']->lang = $language;
1975
1976 $this->assertEquals($value, $this->cObj->getData('lll:' . $key));
1977 }
1978
1979 /**
1980 * Checks if getData() works with type "path"
1981 *
1982 * @test
1983 */
1984 public function getDataWithTypePath() {
1985 $filenameIn = uniqid('someValue');
1986 $filenameOut = uniqid('someValue');
1987 $this->template->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
1988 $this->assertEquals($filenameOut, $this->cObj->getData('path:' . $filenameIn));
1989 }
1990
1991 /**
1992 * Checks if getData() works with type "parentRecordNumber"
1993 *
1994 * @test
1995 */
1996 public function getDataWithTypeParentRecordNumber() {
1997 $recordNumber = rand();
1998 $this->cObj->parentRecordNumber = $recordNumber;
1999 $this->assertEquals($recordNumber, $this->cObj->getData('cobj:parentRecordNumber'));
2000 }
2001
2002 /**
2003 * Checks if getData() works with type "debug:rootLine"
2004 *
2005 * @test
2006 */
2007 public function getDataWithTypeDebugRootline() {
2008 $rootline = array(
2009 0 => array('uid' => 1, 'title' => 'title1'),
2010 1 => array('uid' => 2, 'title' => 'title2'),
2011 2 => array('uid' => 3, 'title' => ''),
2012 );
2013 $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
2014 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2015
2016 $result = $this->cObj->getData('debug:rootLine');
2017 $cleanedResult = strip_tags($result);
2018 $cleanedResult = str_replace("\r", '', $cleanedResult);
2019 $cleanedResult = str_replace("\n", '', $cleanedResult);
2020 $cleanedResult = str_replace("\t", '', $cleanedResult);
2021 $cleanedResult = str_replace(' ', '', $cleanedResult);
2022
2023 $this->assertEquals($expectedResult, $cleanedResult);
2024 }
2025
2026 /**
2027 * Checks if getData() works with type "debug:fullRootLine"
2028 *
2029 * @test
2030 */
2031 public function getDataWithTypeDebugFullRootline() {
2032 $rootline = array(
2033 0 => array('uid' => 1, 'title' => 'title1'),
2034 1 => array('uid' => 2, 'title' => 'title2'),
2035 2 => array('uid' => 3, 'title' => ''),
2036 );
2037 $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
2038 $GLOBALS['TSFE']->rootLine = $rootline;
2039
2040 $result = $this->cObj->getData('debug:fullRootLine');
2041 $cleanedResult = strip_tags($result);
2042 $cleanedResult = str_replace("\r", '', $cleanedResult);
2043 $cleanedResult = str_replace("\n", '', $cleanedResult);
2044 $cleanedResult = str_replace("\t", '', $cleanedResult);
2045 $cleanedResult = str_replace(' ', '', $cleanedResult);
2046
2047 $this->assertEquals($expectedResult, $cleanedResult);
2048 }
2049
2050 /**
2051 * Checks if getData() works with type "debug:data"
2052 *
2053 * @test
2054 */
2055 public function getDataWithTypeDebugData() {
2056 $key = uniqid('someKey');
2057 $value = uniqid('someValue');
2058 $this->cObj->data = array($key => $value);
2059
2060 $expectedResult = $key . $value;
2061
2062 $result = $this->cObj->getData('debug:data');
2063 $cleanedResult = strip_tags($result);
2064 $cleanedResult = str_replace("\r", '', $cleanedResult);
2065 $cleanedResult = str_replace("\n", '', $cleanedResult);
2066 $cleanedResult = str_replace("\t", '', $cleanedResult);
2067 $cleanedResult = str_replace(' ', '', $cleanedResult);
2068
2069 $this->assertEquals($expectedResult, $cleanedResult);
2070 }
2071
2072 /**
2073 * Checks if getData() works with type "debug:register"
2074 *
2075 * @test
2076 */
2077 public function getDataWithTypeDebugRegister() {
2078 $key = uniqid('someKey');
2079 $value = uniqid('someValue');
2080 $GLOBALS['TSFE']->register = array($key => $value);
2081
2082 $expectedResult = $key . $value;
2083
2084 $result = $this->cObj->getData('debug:register');
2085 $cleanedResult = strip_tags($result);
2086 $cleanedResult = str_replace("\r", '', $cleanedResult);
2087 $cleanedResult = str_replace("\n", '', $cleanedResult);
2088 $cleanedResult = str_replace("\t", '', $cleanedResult);
2089 $cleanedResult = str_replace(' ', '', $cleanedResult);
2090
2091 $this->assertEquals($expectedResult, $cleanedResult);
2092 }
2093
2094 /**
2095 * Checks if getData() works with type "data:page"
2096 *
2097 * @test
2098 */
2099 public function getDataWithTypeDebugPage() {
2100 $uid = rand();
2101 $GLOBALS['TSFE']->page = array('uid' => $uid);
2102
2103 $expectedResult = 'uid' . $uid;
2104
2105 $result = $this->cObj->getData('debug:page');
2106 $cleanedResult = strip_tags($result);
2107 $cleanedResult = str_replace("\r", '', $cleanedResult);
2108 $cleanedResult = str_replace("\n", '', $cleanedResult);
2109 $cleanedResult = str_replace("\t", '', $cleanedResult);
2110 $cleanedResult = str_replace(' ', '', $cleanedResult);
2111
2112 $this->assertEquals($expectedResult, $cleanedResult);
2113 }
2114
2115 /**
2116 * @test
2117 */
2118 public function getTreeListReturnsChildPageUids() {
2119 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2120 $GLOBALS['TSFE']->sys_page
2121 ->expects($this->any())
2122 ->method('getRawRecord')
2123 ->will(
2124 $this->onConsecutiveCalls(
2125 array('uid' => 17),
2126 array('uid' => 321),
2127 array('uid' => 719),
2128 array('uid' => 42)
2129 )
2130 );
2131
2132 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2133 $GLOBALS['TYPO3_DB']
2134 ->expects($this->any())
2135 ->method('exec_SELECTgetRows')
2136 ->will(
2137 $this->onConsecutiveCalls(
2138 array(
2139 array('uid' => 321)
2140 ),
2141 array(
2142 array('uid' => 719)
2143 ),
2144 array(
2145 array('uid' => 42)
2146 )
2147 )
2148 );
2149 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2150 // 17 is positive, we expect 17 NOT to be included in result
2151 $result = $this->cObj->getTreeList(17, 5, 0, TRUE);
2152 $expectedResult = '42,719,321';
2153 $this->assertEquals($expectedResult, $result);
2154 }
2155
2156 /**
2157 * @test
2158 */
2159 public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue() {
2160 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2161 $GLOBALS['TSFE']->sys_page
2162 ->expects($this->any())
2163 ->method('getRawRecord')
2164 ->will(
2165 $this->onConsecutiveCalls(
2166 array('uid' => 17),
2167 array('uid' => 321),
2168 array('uid' => 719),
2169 array('uid' => 42)
2170 )
2171 );
2172
2173 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2174 $GLOBALS['TYPO3_DB']
2175 ->expects($this->any())
2176 ->method('exec_SELECTgetRows')
2177 ->will(
2178 $this->onConsecutiveCalls(
2179 array(
2180 array('uid' => 321)
2181 ),
2182 array(
2183 array('uid' => 719)
2184 ),
2185 array(
2186 array('uid' => 42)
2187 )
2188 )
2189 );
2190 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2191 // 17 is negative, we expect 17 to be included in result
2192 $result = $this->cObj->getTreeList(-17, 5, 0, TRUE);
2193 $expectedResult = '42,719,321,17';
2194 $this->assertEquals($expectedResult, $result);
2195 }
2196
2197 /**
2198 * @test
2199 */
2200 public function aTagParamsHasLeadingSpaceIfNotEmpty() {
2201 $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2202 $this->assertEquals(' data-test="testdata"', $aTagParams );
2203 }
2204
2205 /**
2206 * @test
2207 */
2208 public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams() {
2209 $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
2210 $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2211 $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
2212 }
2213
2214 /**
2215 * @test
2216 */
2217 public function aTagParamsHasNoLeadingSpaceIfEmpty() {
2218 // make sure global ATagParams are empty
2219 $GLOBALS['TSFE']->ATagParams = '';
2220 $aTagParams = $this->cObj->getATagParams(array('ATagParams' => ''));
2221 $this->assertEquals('', $aTagParams);
2222 }
2223
2224 /**
2225 * @return array
2226 */
2227 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider() {
2228 return array(
2229 array(NULL, NULL),
2230 array('', NULL),
2231 array('', array()),
2232 array('fooo', array('foo' => 'bar'))
2233 );
2234 }
2235
2236 /**
2237 * Make sure that the rendering falls back to the classic <img style if nothing else is found
2238 *
2239 * @test
2240 * @dataProvider getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider
2241 * @param string $key
2242 * @param array $configuration
2243 */
2244 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFound($key, $configuration) {
2245 $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
2246 $result = $this->cObj->getImageTagTemplate($key, $configuration);
2247 $this->assertEquals($result, $defaultImgTagTemplate);
2248 }
2249
2250 /**
2251 * @return array
2252 */
2253 public function getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider() {
2254 return array(
2255 array(
2256 'foo',
2257 array(
2258 'layout.' => array(
2259 'foo.' => array(
2260 'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2261 )
2262 )
2263 ),
2264 '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2265 )
2266
2267 );
2268 }
2269
2270 /**
2271 * Assure if a layoutKey and layout is given the selected layout is returned
2272 *
2273 * @test
2274 * @dataProvider getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider
2275 * @param string $key
2276 * @param array $configuration
2277 * @param string $expectation
2278 */
2279 public function getImageTagTemplateReturnTemplateElementIdentifiedByKey($key, $configuration, $expectation) {
2280 $result = $this->cObj->getImageTagTemplate($key, $configuration);
2281 $this->assertEquals($result, $expectation);
2282 }
2283
2284 /**
2285 * @return array
2286 */
2287 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider() {
2288 return array(
2289 array(NULL, NULL, NULL),
2290 array('foo', NULL, NULL),
2291 array('foo', array('sourceCollection.' => 1), 'bar')
2292 );
2293 }
2294
2295 /**
2296 * Make sure the source collection is empty if no valid configuration or source collection is defined
2297 *
2298 * @test
2299 * @dataProvider getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider
2300 * @param string $layoutKey
2301 * @param array $configuration
2302 * @param string $file
2303 */
2304 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefined($layoutKey, $configuration, $file) {
2305 $result = $this->cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2306 $this->assertSame($result, '');
2307 }
2308
2309 /**
2310 * Make sure the generation of subimages calls the generation of the subimages and uses the layout -> source template
2311 *
2312 * @test
2313 */
2314 public function getImageSourceCollectionRendersDefinedSources() {
2315 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2316 $cObj = $this->getMock(
2317 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2318 array('stdWrap','getImgResource')
2319 );
2320 $cObj->start(array(), 'tt_content');
2321
2322 $layoutKey = 'test';
2323
2324 $configuration = array(
2325 'layoutKey' => 'test',
2326 'layout.' => array (
2327 'test.' => array(
2328 'element' => '<img ###SRC### ###SRCCOLLECTION### ###SELFCLOSINGTAGSLASH###>',
2329 'source' => '---###SRC###---'
2330 )
2331 ),
2332 'sourceCollection.' => array(
2333 '1.' => array(
2334 'width' => '200'
2335 )
2336 )
2337 );
2338
2339 $file = 'testImageName';
2340
2341 // Avoid calling of stdWrap
2342 $cObj
2343 ->expects($this->any())
2344 ->method('stdWrap')
2345 ->will($this->returnArgument(0));
2346
2347 // Avoid calling of imgResource
2348 $cObj
2349 ->expects($this->exactly(1))
2350 ->method('getImgResource')
2351 ->with($this->equalTo('testImageName'))
2352 ->will($this->returnValue(array(100, 100, NULL, 'bar')));
2353
2354 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2355
2356 $this->assertEquals('---bar---', $result);
2357 }
2358
2359 /**
2360 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyDefault test
2361 *
2362 * @return array multi-dimensional array with the second level like this:
2363 * @see getImageSourceCollectionRendersDefinedLayoutKeyDefault
2364 */
2365 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider() {
2366 /**
2367 * @see css_styled_content/static/setup.txt
2368 */
2369 $sourceCollectionArray = array(
2370 'small.' => array(
2371 'width' => '200',
2372 'srcsetCandidate' => '600w',
2373 'mediaQuery' => '(max-device-width: 600px)',
2374 'dataKey' => 'small',
2375 ),
2376 'smallRetina.' => array(
2377 'if.directReturn' => 0,
2378 'width' => '200',
2379 'pixelDensity' => '2',
2380 'srcsetCandidate' => '600w 2x',
2381 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2382 'dataKey' => 'smallRetina',
2383 )
2384 );
2385 return array(
2386 array(
2387 'default',
2388 array(
2389 'layoutKey' => 'default',
2390 'layout.' => array (
2391 'default.' => array(
2392 'element' => '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>',
2393 'source' => ''
2394 )
2395 ),
2396 'sourceCollection.' => $sourceCollectionArray
2397 )
2398 ),
2399 );
2400 }
2401
2402 /**
2403 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2404 *
2405 * @test
2406 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider
2407 * @param string $layoutKey
2408 * @param array $configuration
2409 */
2410 public function getImageSourceCollectionRendersDefinedLayoutKeyDefault($layoutKey , $configuration) {
2411 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2412 $cObj = $this->getMock(
2413 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2414 array('stdWrap','getImgResource')
2415 );
2416 $cObj->start(array(), 'tt_content');
2417
2418 $file = 'testImageName';
2419
2420 // Avoid calling of stdWrap
2421 $cObj
2422 ->expects($this->any())
2423 ->method('stdWrap')
2424 ->will($this->returnArgument(0));
2425
2426 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2427
2428 $this->assertEmpty($result);
2429 }
2430
2431 /**
2432 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyData test
2433 *
2434 * @return array multi-dimensional array with the second level like this:
2435 * @see getImageSourceCollectionRendersDefinedLayoutKeyData
2436 */
2437 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider() {
2438 /**
2439 * @see css_styled_content/static/setup.txt
2440 */
2441 $sourceCollectionArray = array(
2442 'small.' => array(
2443 'width' => '200',
2444 'srcsetCandidate' => '600w',
2445 'mediaQuery' => '(max-device-width: 600px)',
2446 'dataKey' => 'small',
2447 ),
2448 'smallRetina.' => array(
2449 'if.directReturn' => 1,
2450 'width' => '200',
2451 'pixelDensity' => '2',
2452 'srcsetCandidate' => '600w 2x',
2453 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2454 'dataKey' => 'smallRetina',
2455 )
2456 );
2457 return array(
2458 array(
2459 'srcset',
2460 array(
2461 'layoutKey' => 'srcset',
2462 'layout.' => array (
2463 'srcset.' => array(
2464 'element' => '<img src="###SRC###" srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2465 'source' => '|*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###'
2466 )
2467 ),
2468 'sourceCollection.' => $sourceCollectionArray
2469 ),
2470 'xhtml_strict',
2471 'bar-file.jpg 600w,bar-file.jpg 600w 2x',
2472 ),
2473 array(
2474 'picture',
2475 array(
2476 'layoutKey' => 'picture',
2477 'layout.' => array (
2478 'picture.' => array(
2479 'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2480 'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2481 )
2482 ),
2483 'sourceCollection.' => $sourceCollectionArray,
2484 ),
2485 'xhtml_strict',
2486 '<source src="bar-file.jpg" media="(max-device-width: 600px)" /><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)" />',
2487 ),
2488 array(
2489 'picture',
2490 array(
2491 'layoutKey' => 'picture',
2492 'layout.' => array (
2493 'picture.' => array(
2494 'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2495 'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2496 )
2497 ),
2498 'sourceCollection.' => $sourceCollectionArray,
2499 ),
2500 '',
2501 '<source src="bar-file.jpg" media="(max-device-width: 600px)"><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)">',
2502 ),
2503 array(
2504 'data',
2505 array(
2506 'layoutKey' => 'data',
2507 'layout.' => array (
2508 'data.' => array(
2509 'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2510 'source' => 'data-###DATAKEY###="###SRC###"'
2511 )
2512 ),
2513 'sourceCollection.' => $sourceCollectionArray
2514 ),
2515 'xhtml_strict',
2516 'data-small="bar-file.jpg"data-smallRetina="bar-file.jpg"',
2517 ),
2518 );
2519 }
2520
2521 /**
2522 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2523 *
2524 * @test
2525 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider
2526 * @param string $layoutKey
2527 * @param array $configuration
2528 * @param string $xhtmlDoctype
2529 * @param string $expectedHtml
2530 */
2531 public function getImageSourceCollectionRendersDefinedLayoutKeyData($layoutKey , $configuration, $xhtmlDoctype, $expectedHtml) {
2532 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2533 $cObj = $this->getMock(
2534 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2535 array('stdWrap','getImgResource')
2536 );
2537 $cObj->start(array(), 'tt_content');
2538
2539 $file = 'testImageName';
2540
2541 $GLOBALS['TSFE']->xhtmlDoctype = $xhtmlDoctype;
2542
2543 // Avoid calling of stdWrap
2544 $cObj
2545 ->expects($this->any())
2546 ->method('stdWrap')
2547 ->will($this->returnArgument(0));
2548
2549 // Avoid calling of imgResource
2550 $cObj
2551 ->expects($this->exactly(2))
2552 ->method('getImgResource')
2553 ->with($this->equalTo('testImageName'))
2554 ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2555
2556 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2557
2558 $this->assertEquals($expectedHtml, $result);
2559 }
2560
2561 /**
2562 * Make sure the hook in get sourceCollection is called
2563 *
2564 * @test
2565 */
2566 public function getImageSourceCollectionHookCalled() {
2567 $this->cObj = $this->getAccessibleMock(
2568 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2569 array('getResourceFactory', 'stdWrap', 'getImgResource')
2570 );
2571 $this->cObj->start(array(), 'tt_content');
2572
2573 // Avoid calling stdwrap and getImgResource
2574 $this->cObj->expects($this->any())
2575 ->method('stdWrap')
2576 ->will($this->returnArgument(0));
2577
2578 $this->cObj->expects($this->any())
2579 ->method('getImgResource')
2580 ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2581
2582 $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array(), array(), '', FALSE);
2583 $this->cObj->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
2584
2585 $className = uniqid('tx_coretest_getImageSourceCollectionHookCalled');
2586 $getImageSourceCollectionHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectOneSourceCollectionHookInterface', array('getOneSourceCollection'), array(), $className);
2587 $GLOBALS['T3_VAR']['getUserObj'][$className] = $getImageSourceCollectionHookMock;
2588 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'][] = $className;
2589
2590 $getImageSourceCollectionHookMock
2591 ->expects($this->exactly(1))
2592 ->method('getOneSourceCollection')
2593 ->will($this->returnCallback(array($this, 'isGetOneSourceCollectionCalledCallback')));
2594
2595 $configuration = array(
2596 'layoutKey' => 'data',
2597 'layout.' => array (
2598 'data.' => array(
2599 'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2600 'source' => 'data-###DATAKEY###="###SRC###"'
2601 )
2602 ),
2603 'sourceCollection.' => array(
2604 'small.' => array(
2605 'width' => '200',
2606 'srcsetCandidate' => '600w',
2607 'mediaQuery' => '(max-device-width: 600px)',
2608 'dataKey' => 'small',
2609 ),
2610 ),
2611 );
2612
2613 $result = $this->cObj->getImageSourceCollection('data', $configuration, uniqid('testImage-'));
2614
2615 $this->assertSame($result, 'isGetOneSourceCollectionCalledCallback');
2616 }
2617
2618 /**
2619 * Handles the arguments that have been sent to the getImgResource hook.
2620 *
2621 * @return string
2622 * @see getImageSourceCollectionHookCalled
2623 */
2624 public function isGetOneSourceCollectionCalledCallback() {
2625 list($sourceRenderConfiguration, $sourceConfiguration, $oneSourceCollection, $parent) = func_get_args();
2626 $this->assertTrue(is_array($sourceRenderConfiguration));
2627 $this->assertTrue(is_array($sourceConfiguration));
2628 return 'isGetOneSourceCollectionCalledCallback';
2629 }
2630
2631 /**
2632 * @param string $expected The expected URL
2633 * @param string $url The URL to parse and manipulate
2634 * @param array $configuration The configuration array
2635 * @test
2636 * @dataProvider forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider
2637 */
2638 public function forceAbsoluteUrlReturnsCorrectAbsoluteUrl($expected, $url, array $configuration) {
2639 // Force hostname
2640 $this->cObj->expects($this->any())->method('getEnvironmentVariable')->will($this->returnValueMap(
2641 array(
2642 array('HTTP_HOST', 'localhost'),
2643 array('TYPO3_SITE_PATH', '/'),
2644 )
2645 ));
2646
2647 $this->assertEquals($expected, $this->cObj->_call('forceAbsoluteUrl', $url, $configuration));
2648 }
2649
2650 /**
2651 * @return array The test data for forceAbsoluteUrlReturnsAbsoluteUrl
2652 */
2653 public function forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider() {
2654 return array(
2655 'Missing forceAbsoluteUrl leaves URL untouched' => array(
2656 'foo',
2657 'foo',
2658 array()
2659 ),
2660 'Absolute URL stays unchanged' => array(
2661 'http://example.org/',
2662 'http://example.org/',
2663 array(
2664 'forceAbsoluteUrl' => '1'
2665 )
2666 ),
2667 'Absolute URL stays unchanged 2' => array(
2668 'http://example.org/resource.html',
2669 'http://example.org/resource.html',
2670 array(
2671 'forceAbsoluteUrl' => '1'
2672 )
2673 ),
2674 'Scheme and host w/o ending slash stays unchanged' => array(
2675 'http://example.org',
2676 'http://example.org',
2677 array(
2678 'forceAbsoluteUrl' => '1'
2679 )
2680 ),
2681 'Scheme can be forced' => array(
2682 'typo3://example.org',
2683 'http://example.org',
2684 array(
2685 'forceAbsoluteUrl' => '1',
2686 'forceAbsoluteUrl.' => array(
2687 'scheme' => 'typo3'
2688 )
2689 )
2690 ),
2691 'Scheme can be forced with relative path' => array(
2692 'typo3://localhost/fileadmin/dummy.txt',
2693 '/fileadmin/dummy.txt', // this leading slash is weird, but we need it to really get an absolute link
2694 array(
2695 'forceAbsoluteUrl' => '1',
2696 'forceAbsoluteUrl.' => array(
2697 'scheme' => 'typo3'
2698 )
2699 )
2700 ),
2701 );
2702 }
2703 }