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