TYPO3 CMS  TYPO3_6-2
ContentObjectRendererTest.php
Go to the documentation of this file.
1 <?php
3 
18 
26 
30  protected $cObj = NULL;
31 
35  protected $tsfe = NULL;
36 
40  protected $template = NULL;
41 
45  public function setUp() {
46  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array());
47  $this->template = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('getFileName', 'linkData'));
48  $this->tsfe = $this->getAccessibleMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
49  $this->tsfe->tmpl = $this->template;
50  $this->tsfe->config = array();
51  $this->tsfe->page = array();
52  $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Tests\\Unit\\ContentObject\\Fixtures\\PageRepositoryFixture', array('getRawRecord'));
53  $this->tsfe->sys_page = $sysPageMock;
54  $GLOBALS['TSFE'] = $this->tsfe;
55  $GLOBALS['TT'] = new NullTimeTracker();
56  $GLOBALS['TSFE']->csConvObj = new \TYPO3\CMS\Core\Charset\CharsetConverter();
57  $GLOBALS['TSFE']->renderCharset = 'utf-8';
58  $GLOBALS['TYPO3_CONF_VARS']['SYS']['TYPO3\\CMS\\Core\\Charset\\CharsetConverter_utils'] = 'mbstring';
59  $this->cObj = $this->getAccessibleMock(
60  'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
61  array('getResourceFactory', 'getEnvironmentVariable')
62  );
63  $this->cObj->start(array(), 'tt_content');
64  }
65 
67  // Utitility functions
69 
76  protected function handleCharset($charset, &$subject, &$expected) {
77  $GLOBALS['TSFE']->renderCharset = $charset;
78  $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset);
79  $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset);
80  }
81 
83  // Tests concerning the getImgResource hook
85 
89  $this->template
90  ->expects($this->atLeastOnce())
91  ->method('getFileName')
92  ->with('typo3/clear.gif')
93  ->will($this->returnValue('typo3/clear.gif'));
94 
95  $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array(), array(), '', FALSE);
96  $this->cObj->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
97 
98  $className = $this->getUniqueId('tx_coretest');
99  $getImgResourceHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectGetImageResourceHookInterface', array('getImgResourcePostProcess'), array(), $className);
100  $getImgResourceHookMock
101  ->expects($this->once())
102  ->method('getImgResourcePostProcess')
103  ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
104  $getImgResourceHookObjects = array($getImgResourceHookMock);
105  $this->cObj->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
106  $this->cObj->getImgResource('typo3/clear.gif', array());
107  }
108 
116  list($file, $fileArray, $imageResource, $parent) = func_get_args();
117  $this->assertEquals('typo3/clear.gif', $file);
118  $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
119  $this->assertTrue(is_array($fileArray));
120  $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer);
121  return $imageResource;
122  }
123 
124 
125  /*************************
126  * Tests concerning getContentObject
127  ************************/
129  return array(
130  array('TEXT', 'Text'),
131  array('CASE', 'Case'),
132  array('CLEARGIF', 'ClearGif'),
133  array('COBJ_ARRAY', 'ContentObjectArray'),
134  array('COA', 'ContentObjectArray'),
135  array('COA_INT', 'ContentObjectArrayInternal'),
136  array('USER', 'User'),
137  array('USER_INT', 'UserInternal'),
138  array('FILE', 'File'),
139  array('FILES', 'Files'),
140  array('IMAGE', 'Image'),
141  array('IMG_RESOURCE', 'ImageResource'),
142  array('IMGTEXT', 'ImageText'),
143  array('CONTENT', 'Content'),
144  array('RECORDS', 'Records'),
145  array('HMENU', 'HierarchicalMenu'),
146  array('CTABLE', 'ContentTable'),
147  array('OTABLE', 'OffsetTable'),
148  array('COLUMNS', 'Columns'),
149  array('HRULER', 'HorizontalRuler'),
150  array('CASEFUNC', 'Case'),
151  array('LOAD_REGISTER', 'LoadRegister'),
152  array('RESTORE_REGISTER', 'RestoreRegister'),
153  array('FORM', 'Form'),
154  array('SEARCHRESULT', 'SearchResult'),
155  array('TEMPLATE', 'Template'),
156  array('FLUIDTEMPLATE', 'FluidTemplate'),
157  array('MULTIMEDIA', 'Multimedia'),
158  array('MEDIA', 'Media'),
159  array('SWFOBJECT', 'ShockwaveFlashObject'),
160  array('FLOWPLAYER', 'FlowPlayer'),
161  array('QTOBJECT', 'QuicktimeObject'),
162  array('SVG', 'ScalableVectorGraphics'),
163  array('EDITPANEL', 'EditPanel'),
164  );
165  }
166 
174  $fullClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $className . 'ContentObject';
175  $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', FALSE);
176  \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($fullClassName, $contentObjectInstance);
177  $this->assertSame($contentObjectInstance, $this->cObj->getContentObject($name));
178  }
179 
181  // Tests concerning FORM
183 
187  $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = TRUE;
188  $this->assertNotContains('name="recipient', $this->cObj->FORM(array('recipient' => 'foo@bar.com', 'recipient.' => array()), array()));
189  }
190 
195  $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = FALSE;
196  $this->assertContains('name="recipient', $this->cObj->FORM(array('recipient' => 'foo@bar.com', 'recipient.' => array()), array()));
197  }
198 
200  // Tests concerning getQueryArguments()
202 
206  $this->cObj->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
207  $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
208  );
209  $getQueryArgumentsConfiguration = array();
210  $getQueryArgumentsConfiguration['exclude'] = array();
211  $getQueryArgumentsConfiguration['exclude'][] = 'key1';
212  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
213  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
214  $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
215  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
216  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
217  $this->assertEquals($expectedResult, $actualResult);
218  }
219 
224  $_GET = array(
225  'key1' => 'value1',
226  'key2' => 'value2',
227  'key3' => array(
228  'key31' => 'value31',
229  'key32' => array(
230  'key321' => 'value321',
231  'key322' => 'value322'
232  )
233  )
234  );
235  $getQueryArgumentsConfiguration = array();
236  $getQueryArgumentsConfiguration['method'] = 'GET';
237  $getQueryArgumentsConfiguration['exclude'] = array();
238  $getQueryArgumentsConfiguration['exclude'][] = 'key1';
239  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
240  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
241  $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
242  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
243  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
244  $this->assertEquals($expectedResult, $actualResult);
245  }
246 
251  $this->cObj->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
252  $this->returnValue('key1=value1')
253  );
254  $getQueryArgumentsConfiguration = array();
255  $overruleArguments = array(
256  // Should be overridden
257  'key1' => 'value1Overruled',
258  // Shouldn't be set: Parameter doesn't exist in source array and is not forced
259  'key2' => 'value2Overruled'
260  );
261  $expectedResult = '&key1=value1Overruled';
262  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
263  $this->assertEquals($expectedResult, $actualResult);
264  }
265 
270  $_POST = array(
271  'key1' => 'value1',
272  'key2' => 'value2',
273  'key3' => array(
274  'key31' => 'value31',
275  'key32' => array(
276  'key321' => 'value321',
277  'key322' => 'value322'
278  )
279  )
280  );
281  $getQueryArgumentsConfiguration = array();
282  $getQueryArgumentsConfiguration['method'] = 'POST';
283  $getQueryArgumentsConfiguration['exclude'] = array();
284  $getQueryArgumentsConfiguration['exclude'][] = 'key1';
285  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
286  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
287  $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
288  $overruleArguments = array(
289  // Should be overriden
290  'key2' => 'value2Overruled',
291  'key3' => array(
292  'key32' => array(
293  // Shouldn't be set: Parameter is excluded and not forced
294  'key321' => 'value321Overruled',
295  // Should be overriden: Parameter is not excluded
296  'key322' => 'value322Overruled',
297  // Shouldn't be set: Parameter doesn't exist in source array and is not forced
298  'key323' => 'value323Overruled'
299  )
300  )
301  );
302  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
303  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
304  $this->assertEquals($expectedResult, $actualResult);
305  }
306 
311  $this->cObj->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
312  $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
313  );
314  $_POST = array(
315  'key1' => 'value1',
316  'key2' => 'value2',
317  'key3' => array(
318  'key31' => 'value31',
319  'key32' => array(
320  'key321' => 'value321',
321  'key322' => 'value322'
322  )
323  )
324  );
325  $getQueryArgumentsConfiguration = array();
326  $getQueryArgumentsConfiguration['exclude'] = array();
327  $getQueryArgumentsConfiguration['exclude'][] = 'key1';
328  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
329  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
330  $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
331  $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
332  $overruleArguments = array(
333  // Should be overriden
334  'key2' => 'value2Overruled',
335  'key3' => array(
336  'key32' => array(
337  // Should be set: Parameter is excluded but forced
338  'key321' => 'value321Overruled',
339  // Should be set: Parameter doesn't exist in source array but is forced
340  'key323' => 'value323Overruled'
341  )
342  )
343  );
344  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
345  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
346  $this->assertEquals($expectedResult, $actualResult);
347  $getQueryArgumentsConfiguration['method'] = 'POST';
348  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
349  $this->assertEquals($expectedResult, $actualResult);
350  }
351 
356  $_POST = array(
357  'key1' => 'POST1',
358  'key2' => 'POST2',
359  'key3' => array(
360  'key31' => 'POST31',
361  'key32' => 'POST32',
362  'key33' => array(
363  'key331' => 'POST331',
364  'key332' => 'POST332',
365  )
366  )
367  );
368  $_GET = array(
369  'key2' => 'GET2',
370  'key3' => array(
371  'key32' => 'GET32',
372  'key33' => array(
373  'key331' => 'GET331',
374  )
375  )
376  );
377  $getQueryArgumentsConfiguration = array();
378  $getQueryArgumentsConfiguration['method'] = 'POST,GET';
379  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
380  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
381  $this->assertEquals($expectedResult, $actualResult);
382  }
383 
388  $_GET = array(
389  'key1' => 'GET1',
390  'key2' => 'GET2',
391  'key3' => array(
392  'key31' => 'GET31',
393  'key32' => 'GET32',
394  'key33' => array(
395  'key331' => 'GET331',
396  'key332' => 'GET332',
397  )
398  )
399  );
400  $_POST = array(
401  'key2' => 'POST2',
402  'key3' => array(
403  'key32' => 'POST32',
404  'key33' => array(
405  'key331' => 'POST331',
406  )
407  )
408  );
409  $getQueryArgumentsConfiguration = array();
410  $getQueryArgumentsConfiguration['method'] = 'GET,POST';
411  $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
412  $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
413  $this->assertEquals($expectedResult, $actualResult);
414  }
415 
422  private function rawUrlEncodeSquareBracketsInUrl($string) {
423  return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
424  }
425 
427  // Tests concerning crop
429 
432  public function cropIsMultibyteSafe() {
433  $this->assertEquals('бла', $this->cObj->crop('бла', '3|...'));
434  }
435 
437  // Tests concerning cropHTML
439 
446  public function cropHtmlDataProvider() {
447  $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
448  $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.';
449  $textWithEntities = 'Kasper Sk&aring;rh&oslash;j implemented the; original ' . 'version of the crop function.';
450  $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
451  $data = array();
452  foreach ($charsets as $charset) {
453  $data = array_merge($data, array(
454  $charset . ' plain text; 11|...' => array(
455  '11|...',
456  $plainText,
457  'Kasper Sk' . chr(229) . 'r...',
458  $charset
459  ),
460  $charset . ' plain text; -58|...' => array(
461  '-58|...',
462  $plainText,
463  '...h' . chr(248) . 'j implemented the original version of the crop function.',
464  $charset
465  ),
466  $charset . ' plain text; 4|...|1' => array(
467  '4|...|1',
468  $plainText,
469  'Kasp...',
470  $charset
471  ),
472  $charset . ' plain text; 20|...|1' => array(
473  '20|...|1',
474  $plainText,
475  'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...',
476  $charset
477  ),
478  $charset . ' plain text; -5|...|1' => array(
479  '-5|...|1',
480  $plainText,
481  '...tion.',
482  $charset
483  ),
484  $charset . ' plain text; -49|...|1' => array(
485  '-49|...|1',
486  $plainText,
487  '...the original version of the crop function.',
488  $charset
489  ),
490  $charset . ' text with markup; 11|...' => array(
491  '11|...',
492  $textWithMarkup,
493  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>',
494  $charset
495  ),
496  $charset . ' text with markup; 13|...' => array(
497  '13|...',
498  $textWithMarkup,
499  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>',
500  $charset
501  ),
502  $charset . ' text with markup; 14|...' => array(
503  '14|...',
504  $textWithMarkup,
505  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
506  $charset
507  ),
508  $charset . ' text with markup; 15|...' => array(
509  '15|...',
510  $textWithMarkup,
511  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>',
512  $charset
513  ),
514  $charset . ' text with markup; 29|...' => array(
515  '29|...',
516  $textWithMarkup,
517  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...',
518  $charset
519  ),
520  $charset . ' text with markup; -58|...' => array(
521  '-58|...',
522  $textWithMarkup,
523  '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
524  $charset
525  ),
526  $charset . ' text with markup 4|...|1' => array(
527  '4|...|1',
528  $textWithMarkup,
529  '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>',
530  $charset
531  ),
532  $charset . ' text with markup; 11|...|1' => array(
533  '11|...|1',
534  $textWithMarkup,
535  '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
536  $charset
537  ),
538  $charset . ' text with markup; 13|...|1' => array(
539  '13|...|1',
540  $textWithMarkup,
541  '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
542  $charset
543  ),
544  $charset . ' text with markup; 14|...|1' => array(
545  '14|...|1',
546  $textWithMarkup,
547  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
548  $charset
549  ),
550  $charset . ' text with markup; 15|...|1' => array(
551  '15|...|1',
552  $textWithMarkup,
553  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
554  $charset
555  ),
556  $charset . ' text with markup; 29|...|1' => array(
557  '29|...|1',
558  $textWithMarkup,
559  '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...',
560  $charset
561  ),
562  $charset . ' text with markup; -66|...|1' => array(
563  '-66|...|1',
564  $textWithMarkup,
565  '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
566  $charset
567  ),
568  $charset . ' text with entities 9|...' => array(
569  '9|...',
570  $textWithEntities,
571  'Kasper Sk...',
572  $charset
573  ),
574  $charset . ' text with entities 10|...' => array(
575  '10|...',
576  $textWithEntities,
577  'Kasper Sk&aring;...',
578  $charset
579  ),
580  $charset . ' text with entities 11|...' => array(
581  '11|...',
582  $textWithEntities,
583  'Kasper Sk&aring;r...',
584  $charset
585  ),
586  $charset . ' text with entities 13|...' => array(
587  '13|...',
588  $textWithEntities,
589  'Kasper Sk&aring;rh&oslash;...',
590  $charset
591  ),
592  $charset . ' text with entities 14|...' => array(
593  '14|...',
594  $textWithEntities,
595  'Kasper Sk&aring;rh&oslash;j...',
596  $charset
597  ),
598  $charset . ' text with entities 15|...' => array(
599  '15|...',
600  $textWithEntities,
601  'Kasper Sk&aring;rh&oslash;j ...',
602  $charset
603  ),
604  $charset . ' text with entities 16|...' => array(
605  '16|...',
606  $textWithEntities,
607  'Kasper Sk&aring;rh&oslash;j i...',
608  $charset
609  ),
610  $charset . ' text with entities -57|...' => array(
611  '-57|...',
612  $textWithEntities,
613  '...j implemented the; original version of the crop function.',
614  $charset
615  ),
616  $charset . ' text with entities -58|...' => array(
617  '-58|...',
618  $textWithEntities,
619  '...&oslash;j implemented the; original version of the crop function.',
620  $charset
621  ),
622  $charset . ' text with entities -59|...' => array(
623  '-59|...',
624  $textWithEntities,
625  '...h&oslash;j implemented the; original version of the crop function.',
626  $charset
627  ),
628  $charset . ' text with entities 4|...|1' => array(
629  '4|...|1',
630  $textWithEntities,
631  'Kasp...',
632  $charset
633  ),
634  $charset . ' text with entities 9|...|1' => array(
635  '9|...|1',
636  $textWithEntities,
637  'Kasper...',
638  $charset
639  ),
640  $charset . ' text with entities 10|...|1' => array(
641  '10|...|1',
642  $textWithEntities,
643  'Kasper...',
644  $charset
645  ),
646  $charset . ' text with entities 11|...|1' => array(
647  '11|...|1',
648  $textWithEntities,
649  'Kasper...',
650  $charset
651  ),
652  $charset . ' text with entities 13|...|1' => array(
653  '13|...|1',
654  $textWithEntities,
655  'Kasper...',
656  $charset
657  ),
658  $charset . ' text with entities 14|...|1' => array(
659  '14|...|1',
660  $textWithEntities,
661  'Kasper Sk&aring;rh&oslash;j...',
662  $charset
663  ),
664  $charset . ' text with entities 15|...|1' => array(
665  '15|...|1',
666  $textWithEntities,
667  'Kasper Sk&aring;rh&oslash;j...',
668  $charset
669  ),
670  $charset . ' text with entities 16|...|1' => array(
671  '16|...|1',
672  $textWithEntities,
673  'Kasper Sk&aring;rh&oslash;j...',
674  $charset
675  ),
676  $charset . ' text with entities -57|...|1' => array(
677  '-57|...|1',
678  $textWithEntities,
679  '...implemented the; original version of the crop function.',
680  $charset
681  ),
682  $charset . ' text with entities -58|...|1' => array(
683  '-58|...|1',
684  $textWithEntities,
685  '...implemented the; original version of the crop function.',
686  $charset
687  ),
688  $charset . ' text with entities -59|...|1' => array(
689  '-59|...|1',
690  $textWithEntities,
691  '...implemented the; original version of the crop function.',
692  $charset
693  ),
694  $charset . ' text with dash in html-element 28|...|1' => array(
695  '28|...|1',
696  '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',
697  'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>',
698  $charset
699  ),
700  $charset . ' html elements with dashes in attributes' => array(
701  '9',
702  '<em data-foo="x">foobar</em>foobaz',
703  '<em data-foo="x">foobar</em>foo',
704  $charset
705  ),
706  $charset . ' html elements with iframe embedded 24|...|1' => array(
707  '24|...|1',
708  'Text with iframe <iframe src="//what.ever/"></iframe> and text after it',
709  'Text with iframe <iframe src="//what.ever/"></iframe> and...',
710  $charset
711  ),
712  $charset . ' html elements with script tag embedded 24|...|1' => array(
713  '24|...|1',
714  'Text with script <script>alert(\'foo\');</script> and text after it',
715  'Text with script <script>alert(\'foo\');</script> and...',
716  $charset
717  ),
718  ));
719  }
720  return $data;
721  }
722 
733  public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
734  $this->handleCharset($charset, $subject, $expected);
735  $this->assertEquals($expected, $this->cObj->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"');
736  }
737 
745  $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
746 
747  $subject = '
748 <h1>Blog Example</h1>
749 <hr>
750 <div class="csc-header csc-header-n1">
751  <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
752 </div>
753 <p class="bodytext">
754  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>.
755 </p>
756 <div class="tx-blogexample-list-container">
757  <p class="bodytext">
758  Below are the most recent posts:
759  </p>
760  <ul>
761  <li data-element="someId">
762  <h3>
763  <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>
764  </h3>
765  <p class="bodytext">
766  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
767  </p>
768  <p class="metadata">
769  Published on 26.08.2009 by Jochen Rau
770  </p>
771  <p>
772  Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>
773  <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>
774  <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>
775  </p>
776  </li>
777  </ul>
778  <p>
779  <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>
780  </p>
781 </div>
782 <hr>
783 <p>
784  ? TYPO3 Association
785 </p>
786 ';
787  $result = $this->cObj->cropHTML($subject, '300');
788  $expected = '
789 <h1>Blog Example</h1>
790 <hr>
791 <div class="csc-header csc-header-n1">
792  <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
793 </div>
794 <p class="bodytext">
795  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>.
796 </p>
797 <div class="tx-blogexample-list-container">
798  <p class="bodytext">
799  Below are the most recent posts:
800  </p>
801  <ul>
802  <li data-element="someId">
803  <h3>
804  <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>';
805  $this->assertEquals($expected, $result);
806  $result = $this->cObj->cropHTML($subject, '-100');
807  $expected = '<div class="tx-blogexample-list-container"><ul><li data-element="someId"><p>Design]&nbsp;<br>
808  <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>
809  <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>
810  </p>
811  </li>
812  </ul>
813  <p>
814  <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>
815  </p>
816 </div>
817 <hr>
818 <p>
819  ? TYPO3 Association
820 </p>
821 ';
822  $this->assertEquals($expected, $result);
823  }
824 
828  public function stdWrap_roundDataProvider() {
829  return array(
830  'rounding off without any configuration' => array(
831  1.123456789,
832  array(),
833  1
834  ),
835  'rounding up without any configuration' => array(
836  1.523456789,
837  array(),
838  2
839  ),
840  'regular rounding (off) to two decimals' => array(
841  0.123456789,
842  array(
843  'decimals' => 2
844  ),
845  0.12
846  ),
847  'regular rounding (up) to two decimals' => array(
848  0.1256789,
849  array(
850  'decimals' => 2
851  ),
852  0.13
853  ),
854  'rounding up to integer with type ceil' => array(
855  0.123456789,
856  array(
857  'roundType' => 'ceil'
858  ),
859  1
860  ),
861  'rounding down to integer with type floor' => array(
862  2.3481,
863  array(
864  'roundType' => 'floor'
865  ),
866  2
867  )
868  );
869  }
870 
876  public function cropHtmlWorksWithLinebreaks() {
877  $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
878  $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
879  $result = $this->cObj->cropHTML($subject, '121');
880  $this->assertEquals($expected, $result);
881  }
882 
893  public function stdWrap_round($float, $conf, $expected) {
894  $conf = array(
895  'round.' => $conf
896  );
897  $result = $this->cObj->stdWrap_round($float, $conf);
898  $this->assertEquals($expected, $result);
899  }
900 
904  public function stdWrap_strPadDataProvider() {
905  return array(
906  'pad string with default settings and length 10' => array(
907  'Alien',
908  array(
909  'length' => '10',
910  ),
911  'Alien ',
912  ),
913  'pad string with padWith -= and type left and length 10' => array(
914  'Alien',
915  array(
916  'length' => '10',
917  'padWith' => '-=',
918  'type' => 'left',
919  ),
920  '-=-=-Alien',
921  ),
922  'pad string with padWith _ and type both and length 10' => array(
923  'Alien',
924  array(
925  'length' => '10',
926  'padWith' => '_',
927  'type' => 'both',
928  ),
929  '__Alien___',
930  ),
931  'pad string with padWith 0 and type both and length 10' => array(
932  'Alien',
933  array(
934  'length' => '10',
935  'padWith' => '0',
936  'type' => 'both',
937  ),
938  '00Alien000',
939  ),
940  'pad string with padWith ___ and type both and length 6' => array(
941  'Alien',
942  array(
943  'length' => '6',
944  'padWith' => '___',
945  'type' => 'both',
946  ),
947  'Alien_',
948  ),
949  'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
950  'Alien',
951  array(
952  'length' => '1',
953  'length.' => array(
954  'wrap' => '|2',
955  ),
956  'padWith' => '_',
957  'type' => 'both',
958  ),
959  '___Alien____',
960  ),
961  'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
962  'Alien',
963  array(
964  'length' => '12',
965  'padWith' => '_',
966  'padWith.' => array(
967  'wrap' => '-|=',
968  ),
969  'type' => 'both',
970  ),
971  '-_=Alien-_=-',
972  ),
973  'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
974  'Alien',
975  array(
976  'length' => '12',
977  'padWith' => '_',
978  'type' => 'both',
979  // make type become "left"
980  'type.' => array(
981  'substring' => '2,1',
982  'wrap' => 'lef|',
983  ),
984  ),
985  '_______Alien',
986  ),
987  );
988  }
989 
1000  public function stdWrap_strPad($content, $conf, $expected) {
1001  $conf = array(
1002  'strPad.' => $conf
1003  );
1004  $result = $this->cObj->stdWrap_strPad($content, $conf);
1005  $this->assertEquals($expected, $result);
1006  }
1007 
1014  public function hashDataProvider() {
1015  $data = array(
1016  'testing md5' => array(
1017  'joh316',
1018  array(
1019  'hash' => 'md5'
1020  ),
1021  'bacb98acf97e0b6112b1d1b650b84971'
1022  ),
1023  'testing sha1' => array(
1024  'joh316',
1025  array(
1026  'hash' => 'sha1'
1027  ),
1028  '063b3d108bed9f88fa618c6046de0dccadcf3158'
1029  ),
1030  'testing non-existing hashing algorithm' => array(
1031  'joh316',
1032  array(
1033  'hash' => 'non-existing'
1034  ),
1035  ''
1036  ),
1037  'testing stdWrap capability' => array(
1038  'joh316',
1039  array(
1040  'hash.' => array(
1041  'cObject' => 'TEXT',
1042  'cObject.' => array(
1043  'value' => 'md5'
1044  )
1045  )
1046  ),
1047  'bacb98acf97e0b6112b1d1b650b84971'
1048  )
1049  );
1050  return $data;
1051  }
1052 
1063  public function stdWrap_hash($text, array $conf, $expected) {
1064  $result = $this->cObj->stdWrap_hash($text, $conf);
1065  $this->assertEquals($expected, $result);
1066  }
1067 
1074  public function numberFormatDataProvider() {
1075  $data = array(
1076  'testing decimals' => array(
1077  0.8,
1078  array(
1079  'decimals' => 2
1080  ),
1081  '0.80'
1082  ),
1083  'testing decimals with input as string' => array(
1084  '0.8',
1085  array(
1086  'decimals' => 2
1087  ),
1088  '0.80'
1089  ),
1090  'testing dec_point' => array(
1091  0.8,
1092  array(
1093  'decimals' => 1,
1094  'dec_point' => ','
1095  ),
1096  '0,8'
1097  ),
1098  'testing thousands_sep' => array(
1099  999.99,
1100  array(
1101  'decimals' => 0,
1102  'thousands_sep.' => array(
1103  'char' => 46
1104  )
1105  ),
1106  '1.000'
1107  ),
1108  'testing mixture' => array(
1109  1281731.45,
1110  array(
1111  'decimals' => 1,
1112  'dec_point.' => array(
1113  'char' => 44
1114  ),
1115  'thousands_sep.' => array(
1116  'char' => 46
1117  )
1118  ),
1119  '1.281.731,5'
1120  )
1121  );
1122  return $data;
1123  }
1124 
1131  public function numberFormat($float, $formatConf, $expected) {
1132  $result = $this->cObj->numberFormat($float, $formatConf);
1133  $this->assertEquals($expected, $result);
1134  }
1135 
1142  public function replacementDataProvider() {
1143  $data = array(
1144  'multiple replacements, including regex' => array(
1145  'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1146  array(
1147  'replacement.' => array(
1148  '120.' => array(
1149  'search' => 'in da hood',
1150  'replace' => 'around the block'
1151  ),
1152  '20.' => array(
1153  'search' => '_',
1154  'replace.' => array('char' => '32')
1155  ),
1156  '130.' => array(
1157  'search' => '#a (Cat|Dog|Tiger)#i',
1158  'replace' => 'an animal',
1159  'useRegExp' => '1'
1160  )
1161  )
1162  ),
1163  'There is an animal, an animal and an animal around the block! Yeah!'
1164  ),
1165  'replacement with optionSplit, normal pattern' => array(
1166  'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1167  array(
1168  'replacement.' => array(
1169  '10.' => array(
1170  'search' => '_',
1171  'replace' => '1 || 2 || 3',
1172  'useOptionSplitReplace' => '1'
1173  ),
1174  )
1175  ),
1176  'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1177  ),
1178  'replacement with optionSplit, using regex' => array(
1179  'There is a cat, a dog and a tiger in da hood! Yeah!',
1180  array(
1181  'replacement.' => array(
1182  '10.' => array(
1183  'search' => '#(a) (Cat|Dog|Tiger)#i',
1184  'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1185  'useOptionSplitReplace' => '1',
1186  'useRegExp' => '1'
1187  )
1188  )
1189  ),
1190  'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1191  ),
1192  );
1193  return $data;
1194  }
1195 
1202  public function replacement($input, $conf, $expected) {
1203  $result = $this->cObj->stdWrap_replacement($input, $conf);
1204  $this->assertEquals($expected, $result);
1205  }
1206 
1213  public function getQueryDataProvider() {
1214  $data = array(
1215  'testing empty conf' => array(
1216  'tt_content',
1217  array(),
1218  array(
1219  'SELECT' => '*'
1220  )
1221  ),
1222  'testing #17284: adding uid/pid for workspaces' => array(
1223  'tt_content',
1224  array(
1225  'selectFields' => 'header,bodytext'
1226  ),
1227  array(
1228  'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1229  )
1230  ),
1231  'testing #17284: no need to add' => array(
1232  'tt_content',
1233  array(
1234  'selectFields' => 'tt_content.*'
1235  ),
1236  array(
1237  'SELECT' => 'tt_content.*'
1238  )
1239  ),
1240  'testing #17284: no need to add #2' => array(
1241  'tt_content',
1242  array(
1243  'selectFields' => '*'
1244  ),
1245  array(
1246  'SELECT' => '*'
1247  )
1248  ),
1249  'testing #29783: joined tables, prefix tablename' => array(
1250  'tt_content',
1251  array(
1252  'selectFields' => 'tt_content.header,be_users.username',
1253  'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1254  ),
1255  array(
1256  'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1257  )
1258  ),
1259  'testing #34152: single count(*), add nothing' => array(
1260  'tt_content',
1261  array(
1262  'selectFields' => 'count(*)'
1263  ),
1264  array(
1265  'SELECT' => 'count(*)'
1266  )
1267  ),
1268  'testing #34152: single max(crdate), add nothing' => array(
1269  'tt_content',
1270  array(
1271  'selectFields' => 'max(crdate)'
1272  ),
1273  array(
1274  'SELECT' => 'max(crdate)'
1275  )
1276  ),
1277  'testing #34152: single min(crdate), add nothing' => array(
1278  'tt_content',
1279  array(
1280  'selectFields' => 'min(crdate)'
1281  ),
1282  array(
1283  'SELECT' => 'min(crdate)'
1284  )
1285  ),
1286  'testing #34152: single sum(is_siteroot), add nothing' => array(
1287  'tt_content',
1288  array(
1289  'selectFields' => 'sum(is_siteroot)'
1290  ),
1291  array(
1292  'SELECT' => 'sum(is_siteroot)'
1293  )
1294  ),
1295  'testing #34152: single avg(crdate), add nothing' => array(
1296  'tt_content',
1297  array(
1298  'selectFields' => 'avg(crdate)'
1299  ),
1300  array(
1301  'SELECT' => 'avg(crdate)'
1302  )
1303  )
1304  );
1305  return $data;
1306  }
1307 
1314  public function getQuery($table, $conf, $expected) {
1315  $GLOBALS['TCA'] = array(
1316  'pages' => array(
1317  'ctrl' => array(
1318  'enablecolumns' => array(
1319  'disabled' => 'hidden'
1320  )
1321  )
1322  ),
1323  'tt_content' => array(
1324  'ctrl' => array(
1325  'enablecolumns' => array(
1326  'disabled' => 'hidden'
1327  ),
1328  'versioningWS' => 2
1329  )
1330  ),
1331  );
1332  $result = $this->cObj->getQuery($table, $conf, TRUE);
1333  foreach ($expected as $field => $value) {
1334  $this->assertEquals($value, $result[$field]);
1335  }
1336  }
1337 
1342  $GLOBALS['TCA'] = array(
1343  'pages' => array(
1344  'ctrl' => array(
1345  'enablecolumns' => array(
1346  'disabled' => 'hidden'
1347  )
1348  )
1349  ),
1350  'tt_content' => array(
1351  'ctrl' => array(
1352  'enablecolumns' => array(
1353  'disabled' => 'hidden'
1354  )
1355  )
1356  ),
1357  );
1358  $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
1359  $this->cObj->start(array(), 'tt_content');
1360  $conf = array(
1361  'recursive' => '15',
1362  'pidInList' => '16, -35'
1363  );
1364  $this->cObj->expects($this->at(0))
1365  ->method('getTreeList')
1366  ->with(-16, 15)
1367  ->will($this->returnValue('15,16'));
1368  $this->cObj->expects($this->at(1))
1369  ->method('getTreeList')
1370  ->with(-35, 15)
1371  ->will($this->returnValue('15,35'));
1372  $this->cObj->getQuery('tt_content', $conf, TRUE);
1373  }
1374 
1379  $GLOBALS['TCA'] = array(
1380  'pages' => array(
1381  'ctrl' => array(
1382  'enablecolumns' => array(
1383  'disabled' => 'hidden'
1384  )
1385  )
1386  ),
1387  'tt_content' => array(
1388  'ctrl' => array(
1389  'enablecolumns' => array(
1390  'disabled' => 'hidden'
1391  )
1392  )
1393  ),
1394  );
1395  $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('getTreeList'));
1396  $GLOBALS['TSFE']->id = 27;
1397  $this->cObj->start(array(), 'tt_content');
1398  $conf = array(
1399  'pidInList' => 'this',
1400  'recursive' => '4'
1401  );
1402  $this->cObj->expects($this->once())
1403  ->method('getTreeList')
1404  ->with(-27)
1405  ->will($this->returnValue('27'));
1406  $this->cObj->getQuery('tt_content', $conf, TRUE);
1407  }
1408 
1416  $data = array(
1417  'given timestamp' => array(
1418  1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1419  array(
1420  'strftime' => '%d-%m-%Y',
1421  ),
1422  ),
1423  'empty string' => array(
1424  '',
1425  array(
1426  'strftime' => '%d-%m-%Y',
1427  ),
1428  ),
1429  'testing null' => array(
1430  NULL,
1431  array(
1432  'strftime' => '%d-%m-%Y',
1433  ),
1434  ),
1435  );
1436  return $data;
1437  }
1438 
1443  public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1444  // Set exec_time to a hard timestamp
1445  $GLOBALS['EXEC_TIME'] = 1346500800;
1446  // Save current timezone and set to UTC to make the system under test behave
1447  // the same in all server timezone settings
1448  $timezoneBackup = date_default_timezone_get();
1449  date_default_timezone_set('UTC');
1450 
1451  $result = $this->cObj->stdWrap_strftime($content, $conf);
1452 
1453  // Reset timezone
1454  date_default_timezone_set($timezoneBackup);
1455 
1456  $this->assertEquals('01-09-2012', $result);
1457  }
1458 
1466  public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1467  $result = $this->cObj->stdWrap_ifNull($content, $configuration);
1468  $this->assertEquals($expected, $result);
1469  }
1470 
1477  return array(
1478  'null value' => array(
1479  NULL,
1480  array(
1481  'ifNull' => '1',
1482  ),
1483  '1',
1484  ),
1485  'zero value' => array(
1486  '0',
1487  array(
1488  'ifNull' => '1',
1489  ),
1490  '0',
1491  ),
1492  );
1493  }
1494 
1502  public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1503  $result = $this->cObj->stdWrap_noTrimWrap($content, $configuration);
1504  $this->assertEquals($expected, $result);
1505  }
1506 
1513  return array(
1514  'No char given' => array(
1515  'middle',
1516  array(
1517  'noTrimWrap' => '| left | right |',
1518  ),
1519  ' left middle right '
1520  ),
1521  'Zero char given' => array(
1522  'middle',
1523  array(
1524  'noTrimWrap' => '0 left 0 right 0',
1525  'noTrimWrap.' => array('splitChar' => '0'),
1526 
1527  ),
1528  ' left middle right '
1529  ),
1530  'Default char given' => array(
1531  'middle',
1532  array(
1533  'noTrimWrap' => '| left | right |',
1534  'noTrimWrap.' => array('splitChar' => '|'),
1535  ),
1536  ' left middle right '
1537  ),
1538  'Split char is a' => array(
1539  'middle',
1540  array(
1541  'noTrimWrap' => 'a left a right a',
1542  'noTrimWrap.' => array('splitChar' => 'a'),
1543  ),
1544  ' left middle right '
1545  ),
1546  'Split char is multi-char (ab)' => array(
1547  'middle',
1548  array(
1549  'noTrimWrap' => 'ab left ab right ab',
1550  'noTrimWrap.' => array('splitChar' => 'ab'),
1551  ),
1552  ' left middle right '
1553  ),
1554  'Split char accepts stdWrap' => array(
1555  'middle',
1556  array(
1557  'noTrimWrap' => 'abc left abc right abc',
1558  'noTrimWrap.' => array(
1559  'splitChar' => 'b',
1560  'splitChar.' => array('wrap' => 'a|c'),
1561  ),
1562  ),
1563  ' left middle right '
1564  ),
1565  );
1566  }
1567 
1574  public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
1575  $this->cObj->stdWrap_addPageCacheTags('', $configuration);
1576  $this->assertEquals($expectedTags, $this->tsfe->_get('pageCacheTags'));
1577  }
1578 
1583  return array(
1584  'No Tag' => array(
1585  array(),
1586  array('addPageCacheTags' => ''),
1587  ),
1588  'Two expectedTags' => array(
1589  array('tag1', 'tag2'),
1590  array('addPageCacheTags' => 'tag1,tag2'),
1591  ),
1592  'Two expectedTags plus one with stdWrap' => array(
1593  array('tag1', 'tag2', 'tag3'),
1594  array(
1595  'addPageCacheTags' => 'tag1,tag2',
1596  'addPageCacheTags.' => array('wrap' => '|,tag3')
1597  ),
1598  ),
1599  );
1600  }
1601 
1609  return array(
1610  'double quote in string' => array(
1611  'double quote"',
1612  array(),
1613  '\'double\u0020quote\u0022\''
1614  ),
1615  'backslash in string' => array(
1616  'backslash \\',
1617  array(),
1618  '\'backslash\u0020\u005C\''
1619  ),
1620  'exclamation mark' => array(
1621  'exclamation!',
1622  array(),
1623  '\'exclamation\u0021\''
1624  ),
1625  'whitespace tab, newline and carriage return' => array(
1626  "white\tspace\ns\r",
1627  array(),
1628  '\'white\u0009space\u000As\u000D\''
1629  ),
1630  'single quote in string' => array(
1631  'single quote \'',
1632  array(),
1633  '\'single\u0020quote\u0020\u0027\''
1634  ),
1635  'tag' => array(
1636  '<tag>',
1637  array(),
1638  '\'\u003Ctag\u003E\''
1639  ),
1640  'ampersand in string' => array(
1641  'amper&sand',
1642  array(),
1643  '\'amper\u0026sand\''
1644  ),
1645  );
1646  }
1647 
1654  public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected) {
1655  $result = $this->cObj->stdWrap_encodeForJavaScriptValue($input, $conf);
1656  $this->assertEquals($expected, $result);
1657  }
1658 
1659 
1661  // Tests concerning getData()
1663 
1667  public function getDataWithTypeGpDataProvider() {
1668  return array(
1669  'Value in get-data' => array('onlyInGet', 'GetValue'),
1670  'Value in post-data' => array('onlyInPost', 'PostValue'),
1671  'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
1672  );
1673  }
1674 
1681  public function getDataWithTypeGp($key, $expectedValue) {
1682  $_GET = array(
1683  'onlyInGet' => 'GetValue',
1684  'inGetAndPost' => 'ValueInGet',
1685  );
1686  $_POST = array(
1687  'onlyInPost' => 'PostValue',
1688  'inGetAndPost' => 'ValueInPost',
1689  );
1690  $this->assertEquals($expectedValue, $this->cObj->getData('gp:' . $key));
1691  }
1692 
1698  public function getDataWithTypeTsfe() {
1699  $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('tsfe:renderCharset'));
1700  }
1701 
1707  public function getDataWithTypeGetenv() {
1708  $envName = $this->getUniqueId('frontendtest');
1709  $value = $this->getUniqueId('someValue');
1710  putenv($envName . '=' . $value);
1711  $this->assertEquals($value, $this->cObj->getData('getenv:' . $envName));
1712  }
1713 
1719  public function getDataWithTypeGetindpenv() {
1720  $this->cObj->expects($this->once())->method('getEnvironmentVariable')
1721  ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
1722  $this->assertEquals('dummyPath', $this->cObj->getData('getindpenv:SCRIPT_FILENAME'));
1723  }
1724 
1730  public function getDataWithTypeField() {
1731  $key = 'someKey';
1732  $value = 'someValue';
1733  $field = array($key => $value);
1734 
1735  $this->assertEquals($value, $this->cObj->getData('field:' . $key, $field));
1736  }
1737 
1744  $uid = $this->getUniqueId();
1745  $file = $this->getMock('TYPO3\\CMS\\Core\\Resource\File', array(), array(), '', FALSE);
1746  $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
1747  $this->cObj->setCurrentFile($file);
1748  $this->assertEquals($uid, $this->cObj->getData('file:current:uid'));
1749  }
1750 
1756  public function getDataWithTypeParameters() {
1757  $key = $this->getUniqueId('someKey');
1758  $value = $this->getUniqueId('someValue');
1759  $this->cObj->parameters[$key] = $value;
1760 
1761  $this->assertEquals($value, $this->cObj->getData('parameters:' . $key));
1762  }
1763 
1769  public function getDataWithTypeRegister() {
1770  $key = $this->getUniqueId('someKey');
1771  $value = $this->getUniqueId('someValue');
1772  $GLOBALS['TSFE']->register[$key] = $value;
1773 
1774  $this->assertEquals($value, $this->cObj->getData('register:' . $key));
1775  }
1776 
1782  public function getDataWithTypeLevel() {
1783  $rootline = array(
1784  0 => array('uid' => 1, 'title' => 'title1'),
1785  1 => array('uid' => 2, 'title' => 'title2'),
1786  2 => array('uid' => 3, 'title' => 'title3'),
1787  );
1788 
1789  $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1790  $this->assertEquals(2, $this->cObj->getData('level'));
1791  }
1792 
1798  public function getDataWithTypeGlobal() {
1799  $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('global:TSFE|renderCharset'));
1800  }
1801 
1807  public function getDataWithTypeLeveltitle() {
1808  $rootline = array(
1809  0 => array('uid' => 1, 'title' => 'title1'),
1810  1 => array('uid' => 2, 'title' => 'title2'),
1811  2 => array('uid' => 3, 'title' => ''),
1812  );
1813 
1814  $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1815  $this->assertEquals('', $this->cObj->getData('leveltitle:-1'));
1816  // since "title3" is not set, it will slide to "title2"
1817  $this->assertEquals('title2', $this->cObj->getData('leveltitle:-1,slide'));
1818  }
1819 
1825  public function getDataWithTypeLevelmedia() {
1826  $rootline = array(
1827  0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
1828  1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
1829  2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
1830  );
1831 
1832  $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1833  $this->assertEquals('', $this->cObj->getData('levelmedia:-1'));
1834  // since "title3" is not set, it will slide to "title2"
1835  $this->assertEquals('media2', $this->cObj->getData('levelmedia:-1,slide'));
1836  }
1837 
1843  public function getDataWithTypeLeveluid() {
1844  $rootline = array(
1845  0 => array('uid' => 1, 'title' => 'title1'),
1846  1 => array('uid' => 2, 'title' => 'title2'),
1847  2 => array('uid' => 3, 'title' => 'title3'),
1848  );
1849 
1850  $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1851  $this->assertEquals(3, $this->cObj->getData('leveluid:-1'));
1852  // every element will have a uid - so adding slide doesn't really make sense, just for completeness
1853  $this->assertEquals(3, $this->cObj->getData('leveluid:-1,slide'));
1854  }
1855 
1861  public function getDataWithTypeLevelfield() {
1862  $rootline = array(
1863  0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1864  1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1865  2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
1866  );
1867 
1868  $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1869  $this->assertEquals('', $this->cObj->getData('levelfield:-1,testfield'));
1870  $this->assertEquals('field2', $this->cObj->getData('levelfield:-1,testfield,slide'));
1871  }
1872 
1878  public function getDataWithTypeFullrootline() {
1879  $rootline1 = array(
1880  0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1881  );
1882  $rootline2 = array(
1883  0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1884  1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1885  2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
1886  );
1887 
1888  $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
1889  $GLOBALS['TSFE']->rootLine = $rootline2;
1890  $this->assertEquals('field2', $this->cObj->getData('fullrootline:-1,testfield'));
1891  }
1892 
1898  public function getDataWithTypeDate() {
1899  $format = 'Y-M-D';
1900  $defaultFormat = 'd/m Y';
1901 
1902  $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date:' . $format));
1903  $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date'));
1904  }
1905 
1911  public function getDataWithTypePage() {
1912  $uid = rand();
1913  $GLOBALS['TSFE']->page['uid'] = $uid;
1914  $this->assertEquals($uid, $this->cObj->getData('page:uid'));
1915  }
1916 
1922  public function getDataWithTypeCurrent() {
1923  $key = $this->getUniqueId('someKey');
1924  $value = $this->getUniqueId('someValue');
1925  $this->cObj->data[$key] = $value;
1926  $this->cObj->currentValKey = $key;
1927  $this->assertEquals($value, $this->cObj->getData('current'));
1928  }
1929 
1935  public function getDataWithTypeDb() {
1936  $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
1937 
1938  $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
1939  $this->assertEquals($dummyRecord['title'], $this->cObj->getData('db:tt_content:106:title'));
1940  }
1941 
1947  public function getDataWithTypeLll() {
1948  $key = $this->getUniqueId('someKey');
1949  $value = $this->getUniqueId('someValue');
1950  $language = $this->getUniqueId('someLanguage');
1951  $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
1952  $GLOBALS['TSFE']->lang = $language;
1953 
1954  $this->assertEquals($value, $this->cObj->getData('lll:' . $key));
1955  }
1956 
1962  public function getDataWithTypePath() {
1963  $filenameIn = $this->getUniqueId('someValue');
1964  $filenameOut = $this->getUniqueId('someValue');
1965  $this->template->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
1966  $this->assertEquals($filenameOut, $this->cObj->getData('path:' . $filenameIn));
1967  }
1968 
1975  $recordNumber = rand();
1976  $this->cObj->parentRecordNumber = $recordNumber;
1977  $this->assertEquals($recordNumber, $this->cObj->getData('cobj:parentRecordNumber'));
1978  }
1979 
1985  public function getDataWithTypeDebugRootline() {
1986  $rootline = array(
1987  0 => array('uid' => 1, 'title' => 'title1'),
1988  1 => array('uid' => 2, 'title' => 'title2'),
1989  2 => array('uid' => 3, 'title' => ''),
1990  );
1991  $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
1992  $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1993 
1994  $result = $this->cObj->getData('debug:rootLine');
1995  $cleanedResult = strip_tags($result);
1996  $cleanedResult = str_replace("\r", '', $cleanedResult);
1997  $cleanedResult = str_replace("\n", '', $cleanedResult);
1998  $cleanedResult = str_replace("\t", '', $cleanedResult);
1999  $cleanedResult = str_replace(' ', '', $cleanedResult);
2000 
2001  $this->assertEquals($expectedResult, $cleanedResult);
2002  }
2003 
2010  $rootline = array(
2011  0 => array('uid' => 1, 'title' => 'title1'),
2012  1 => array('uid' => 2, 'title' => 'title2'),
2013  2 => array('uid' => 3, 'title' => ''),
2014  );
2015  $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
2016  $GLOBALS['TSFE']->rootLine = $rootline;
2017 
2018  $result = $this->cObj->getData('debug:fullRootLine');
2019  $cleanedResult = strip_tags($result);
2020  $cleanedResult = str_replace("\r", '', $cleanedResult);
2021  $cleanedResult = str_replace("\n", '', $cleanedResult);
2022  $cleanedResult = str_replace("\t", '', $cleanedResult);
2023  $cleanedResult = str_replace(' ', '', $cleanedResult);
2024 
2025  $this->assertEquals($expectedResult, $cleanedResult);
2026  }
2027 
2033  public function getDataWithTypeDebugData() {
2034  $key = $this->getUniqueId('someKey');
2035  $value = $this->getUniqueId('someValue');
2036  $this->cObj->data = array($key => $value);
2037 
2038  $expectedResult = $key . $value;
2039 
2040  $result = $this->cObj->getData('debug:data');
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 
2055  public function getDataWithTypeDebugRegister() {
2056  $key = $this->getUniqueId('someKey');
2057  $value = $this->getUniqueId('someValue');
2058  $GLOBALS['TSFE']->register = array($key => $value);
2059 
2060  $expectedResult = $key . $value;
2061 
2062  $result = $this->cObj->getData('debug:register');
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 
2077  public function getDataWithTypeDebugPage() {
2078  $uid = rand();
2079  $GLOBALS['TSFE']->page = array('uid' => $uid);
2080 
2081  $expectedResult = 'uid' . $uid;
2082 
2083  $result = $this->cObj->getData('debug:page');
2084  $cleanedResult = strip_tags($result);
2085  $cleanedResult = str_replace("\r", '', $cleanedResult);
2086  $cleanedResult = str_replace("\n", '', $cleanedResult);
2087  $cleanedResult = str_replace("\t", '', $cleanedResult);
2088  $cleanedResult = str_replace(' ', '', $cleanedResult);
2089 
2090  $this->assertEquals($expectedResult, $cleanedResult);
2091  }
2092 
2097  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2098  $GLOBALS['TSFE']->sys_page
2099  ->expects($this->any())
2100  ->method('getRawRecord')
2101  ->will(
2102  $this->onConsecutiveCalls(
2103  array('uid' => 17),
2104  array('uid' => 321),
2105  array('uid' => 719),
2106  array('uid' => 42)
2107  )
2108  );
2109 
2110  $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2111  $GLOBALS['TYPO3_DB']
2112  ->expects($this->any())
2113  ->method('exec_SELECTgetRows')
2114  ->will(
2115  $this->onConsecutiveCalls(
2116  array(
2117  array('uid' => 321)
2118  ),
2119  array(
2120  array('uid' => 719)
2121  ),
2122  array(
2123  array('uid' => 42)
2124  )
2125  )
2126  );
2127  // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2128  // 17 is positive, we expect 17 NOT to be included in result
2129  $result = $this->cObj->getTreeList(17, 5, 0, TRUE);
2130  $expectedResult = '42,719,321';
2131  $this->assertEquals($expectedResult, $result);
2132  }
2133 
2138  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2139  $GLOBALS['TSFE']->sys_page
2140  ->expects($this->any())
2141  ->method('getRawRecord')
2142  ->will(
2143  $this->onConsecutiveCalls(
2144  array('uid' => 17),
2145  array('uid' => 321),
2146  array('uid' => 719),
2147  array('uid' => 42)
2148  )
2149  );
2150 
2151  $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2152  $GLOBALS['TYPO3_DB']
2153  ->expects($this->any())
2154  ->method('exec_SELECTgetRows')
2155  ->will(
2156  $this->onConsecutiveCalls(
2157  array(
2158  array('uid' => 321)
2159  ),
2160  array(
2161  array('uid' => 719)
2162  ),
2163  array(
2164  array('uid' => 42)
2165  )
2166  )
2167  );
2168  // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2169  // 17 is negative, we expect 17 to be included in result
2170  $result = $this->cObj->getTreeList(-17, 5, 0, TRUE);
2171  $expectedResult = '42,719,321,17';
2172  $this->assertEquals($expectedResult, $result);
2173  }
2174 
2179  $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2180  $this->assertEquals(' data-test="testdata"', $aTagParams );
2181  }
2182 
2187  $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
2188  $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2189  $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
2190  }
2191 
2196  // make sure global ATagParams are empty
2197  $GLOBALS['TSFE']->ATagParams = '';
2198  $aTagParams = $this->cObj->getATagParams(array('ATagParams' => ''));
2199  $this->assertEquals('', $aTagParams);
2200  }
2201 
2206  return array(
2207  array(NULL, NULL),
2208  array('', NULL),
2209  array('', array()),
2210  array('fooo', array('foo' => 'bar'))
2211  );
2212  }
2213 
2223  $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
2224  $result = $this->cObj->getImageTagTemplate($key, $configuration);
2225  $this->assertEquals($result, $defaultImgTagTemplate);
2226  }
2227 
2232  return array(
2233  array(
2234  'foo',
2235  array(
2236  'layout.' => array(
2237  'foo.' => array(
2238  'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2239  )
2240  )
2241  ),
2242  '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2243  )
2244 
2245  );
2246  }
2247 
2257  public function getImageTagTemplateReturnTemplateElementIdentifiedByKey($key, $configuration, $expectation) {
2258  $result = $this->cObj->getImageTagTemplate($key, $configuration);
2259  $this->assertEquals($result, $expectation);
2260  }
2261 
2266  return array(
2267  array(NULL, NULL, NULL),
2268  array('foo', NULL, NULL),
2269  array('foo', array('sourceCollection.' => 1), 'bar')
2270  );
2271  }
2272 
2282  public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefined($layoutKey, $configuration, $file) {
2283  $result = $this->cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2284  $this->assertSame($result, '');
2285  }
2286 
2292  public function getImageSourceCollectionRendersDefinedSources() {
2294  $cObj = $this->getMock(
2295  'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2296  array('stdWrap','getImgResource')
2297  );
2298  $cObj->start(array(), 'tt_content');
2299 
2300  $layoutKey = 'test';
2301 
2302  $configuration = array(
2303  'layoutKey' => 'test',
2304  'layout.' => array (
2305  'test.' => array(
2306  'element' => '<img ###SRC### ###SRCCOLLECTION### ###SELFCLOSINGTAGSLASH###>',
2307  'source' => '---###SRC###---'
2308  )
2309  ),
2310  'sourceCollection.' => array(
2311  '1.' => array(
2312  'width' => '200'
2313  )
2314  )
2315  );
2316 
2317  $file = 'testImageName';
2318 
2319  // Avoid calling of stdWrap
2320  $cObj
2321  ->expects($this->any())
2322  ->method('stdWrap')
2323  ->will($this->returnArgument(0));
2324 
2325  // Avoid calling of imgResource
2326  $cObj
2327  ->expects($this->exactly(1))
2328  ->method('getImgResource')
2329  ->with($this->equalTo('testImageName'))
2330  ->will($this->returnValue(array(100, 100, NULL, 'bar')));
2331 
2332  $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2333 
2334  $this->assertEquals('---bar---', $result);
2335  }
2336 
2347  $sourceCollectionArray = array(
2348  'small.' => array(
2349  'width' => '200',
2350  'srcsetCandidate' => '600w',
2351  'mediaQuery' => '(max-device-width: 600px)',
2352  'dataKey' => 'small',
2353  ),
2354  'smallRetina.' => array(
2355  'if.directReturn' => 0,
2356  'width' => '200',
2357  'pixelDensity' => '2',
2358  'srcsetCandidate' => '600w 2x',
2359  'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2360  'dataKey' => 'smallRetina',
2361  )
2362  );
2363  return array(
2364  array(
2365  'default',
2366  array(
2367  'layoutKey' => 'default',
2368  'layout.' => array (
2369  'default.' => array(
2370  'element' => '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>',
2371  'source' => ''
2372  )
2373  ),
2374  'sourceCollection.' => $sourceCollectionArray
2375  )
2376  ),
2377  );
2378  }
2379 
2388  public function getImageSourceCollectionRendersDefinedLayoutKeyDefault($layoutKey , $configuration) {
2390  $cObj = $this->getMock(
2391  'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2392  array('stdWrap','getImgResource')
2393  );
2394  $cObj->start(array(), 'tt_content');
2395 
2396  $file = 'testImageName';
2397 
2398  // Avoid calling of stdWrap
2399  $cObj
2400  ->expects($this->any())
2401  ->method('stdWrap')
2402  ->will($this->returnArgument(0));
2403 
2404  $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2405 
2406  $this->assertEmpty($result);
2407  }
2408 
2419  $sourceCollectionArray = array(
2420  'small.' => array(
2421  'width' => '200',
2422  'srcsetCandidate' => '600w',
2423  'mediaQuery' => '(max-device-width: 600px)',
2424  'dataKey' => 'small',
2425  ),
2426  'smallRetina.' => array(
2427  'if.directReturn' => 1,
2428  'width' => '200',
2429  'pixelDensity' => '2',
2430  'srcsetCandidate' => '600w 2x',
2431  'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2432  'dataKey' => 'smallRetina',
2433  )
2434  );
2435  return array(
2436  array(
2437  'srcset',
2438  array(
2439  'layoutKey' => 'srcset',
2440  'layout.' => array (
2441  'srcset.' => array(
2442  'element' => '<img src="###SRC###" srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2443  'source' => '|*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###'
2444  )
2445  ),
2446  'sourceCollection.' => $sourceCollectionArray
2447  ),
2448  'xhtml_strict',
2449  'bar-file.jpg 600w,bar-file.jpg 600w 2x',
2450  ),
2451  array(
2452  'picture',
2453  array(
2454  'layoutKey' => 'picture',
2455  'layout.' => array (
2456  'picture.' => array(
2457  'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2458  'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2459  )
2460  ),
2461  'sourceCollection.' => $sourceCollectionArray,
2462  ),
2463  'xhtml_strict',
2464  '<source src="bar-file.jpg" media="(max-device-width: 600px)" /><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)" />',
2465  ),
2466  array(
2467  'picture',
2468  array(
2469  'layoutKey' => 'picture',
2470  'layout.' => array (
2471  'picture.' => array(
2472  'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2473  'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2474  )
2475  ),
2476  'sourceCollection.' => $sourceCollectionArray,
2477  ),
2478  '',
2479  '<source src="bar-file.jpg" media="(max-device-width: 600px)"><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)">',
2480  ),
2481  array(
2482  'data',
2483  array(
2484  'layoutKey' => 'data',
2485  'layout.' => array (
2486  'data.' => array(
2487  'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2488  'source' => 'data-###DATAKEY###="###SRC###"'
2489  )
2490  ),
2491  'sourceCollection.' => $sourceCollectionArray
2492  ),
2493  'xhtml_strict',
2494  'data-small="bar-file.jpg"data-smallRetina="bar-file.jpg"',
2495  ),
2496  );
2497  }
2498 
2509  public function getImageSourceCollectionRendersDefinedLayoutKeyData($layoutKey , $configuration, $xhtmlDoctype, $expectedHtml) {
2511  $cObj = $this->getMock(
2512  'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2513  array('stdWrap','getImgResource')
2514  );
2515  $cObj->start(array(), 'tt_content');
2516 
2517  $file = 'testImageName';
2518 
2519  $GLOBALS['TSFE']->xhtmlDoctype = $xhtmlDoctype;
2520 
2521  // Avoid calling of stdWrap
2522  $cObj
2523  ->expects($this->any())
2524  ->method('stdWrap')
2525  ->will($this->returnArgument(0));
2526 
2527  // Avoid calling of imgResource
2528  $cObj
2529  ->expects($this->exactly(2))
2530  ->method('getImgResource')
2531  ->with($this->equalTo('testImageName'))
2532  ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2533 
2534  $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2535 
2536  $this->assertEquals($expectedHtml, $result);
2537  }
2538 
2545  $this->cObj = $this->getAccessibleMock(
2546  'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer',
2547  array('getResourceFactory', 'stdWrap', 'getImgResource')
2548  );
2549  $this->cObj->start(array(), 'tt_content');
2550 
2551  // Avoid calling stdwrap and getImgResource
2552  $this->cObj->expects($this->any())
2553  ->method('stdWrap')
2554  ->will($this->returnArgument(0));
2555 
2556  $this->cObj->expects($this->any())
2557  ->method('getImgResource')
2558  ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2559 
2560  $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array(), array(), '', FALSE);
2561  $this->cObj->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
2562 
2563  $className = $this->getUniqueId('tx_coretest_getImageSourceCollectionHookCalled');
2564  $getImageSourceCollectionHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectOneSourceCollectionHookInterface', array('getOneSourceCollection'), array(), $className);
2565  $GLOBALS['T3_VAR']['getUserObj'][$className] = $getImageSourceCollectionHookMock;
2566  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'][] = $className;
2567 
2568  $getImageSourceCollectionHookMock
2569  ->expects($this->exactly(1))
2570  ->method('getOneSourceCollection')
2571  ->will($this->returnCallback(array($this, 'isGetOneSourceCollectionCalledCallback')));
2572 
2573  $configuration = array(
2574  'layoutKey' => 'data',
2575  'layout.' => array (
2576  'data.' => array(
2577  'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2578  'source' => 'data-###DATAKEY###="###SRC###"'
2579  )
2580  ),
2581  'sourceCollection.' => array(
2582  'small.' => array(
2583  'width' => '200',
2584  'srcsetCandidate' => '600w',
2585  'mediaQuery' => '(max-device-width: 600px)',
2586  'dataKey' => 'small',
2587  ),
2588  ),
2589  );
2590 
2591  $result = $this->cObj->getImageSourceCollection('data', $configuration, $this->getUniqueId('testImage-'));
2592 
2593  $this->assertSame($result, 'isGetOneSourceCollectionCalledCallback');
2594  }
2595 
2603  list($sourceRenderConfiguration, $sourceConfiguration, $oneSourceCollection, $parent) = func_get_args();
2604  $this->assertTrue(is_array($sourceRenderConfiguration));
2605  $this->assertTrue(is_array($sourceConfiguration));
2606  return 'isGetOneSourceCollectionCalledCallback';
2607  }
2608 
2616  public function forceAbsoluteUrlReturnsCorrectAbsoluteUrl($expected, $url, array $configuration) {
2617  // Force hostname
2618  $this->cObj->expects($this->any())->method('getEnvironmentVariable')->will($this->returnValueMap(
2619  array(
2620  array('HTTP_HOST', 'localhost'),
2621  array('TYPO3_SITE_PATH', '/'),
2622  )
2623  ));
2624  $GLOBALS['TSFE']->absRefPrefix = '';
2625 
2626  $this->assertEquals($expected, $this->cObj->_call('forceAbsoluteUrl', $url, $configuration));
2627  }
2628 
2633  return array(
2634  'Missing forceAbsoluteUrl leaves URL untouched' => array(
2635  'foo',
2636  'foo',
2637  array()
2638  ),
2639  'Absolute URL stays unchanged' => array(
2640  'http://example.org/',
2641  'http://example.org/',
2642  array(
2643  'forceAbsoluteUrl' => '1'
2644  )
2645  ),
2646  'Absolute URL stays unchanged 2' => array(
2647  'http://example.org/resource.html',
2648  'http://example.org/resource.html',
2649  array(
2650  'forceAbsoluteUrl' => '1'
2651  )
2652  ),
2653  'Scheme and host w/o ending slash stays unchanged' => array(
2654  'http://example.org',
2655  'http://example.org',
2656  array(
2657  'forceAbsoluteUrl' => '1'
2658  )
2659  ),
2660  'Scheme can be forced' => array(
2661  'typo3://example.org',
2662  'http://example.org',
2663  array(
2664  'forceAbsoluteUrl' => '1',
2665  'forceAbsoluteUrl.' => array(
2666  'scheme' => 'typo3'
2667  )
2668  )
2669  ),
2670  'Relative path old-style' => array(
2671  'http://localhost/fileadmin/dummy.txt',
2672  '/fileadmin/dummy.txt',
2673  array(
2674  'forceAbsoluteUrl' => '1',
2675  )
2676  ),
2677  'Relative path' => array(
2678  'http://localhost/fileadmin/dummy.txt',
2679  'fileadmin/dummy.txt',
2680  array(
2681  'forceAbsoluteUrl' => '1',
2682  )
2683  ),
2684  'Scheme can be forced with pseudo-relative path' => array(
2685  'typo3://localhost/fileadmin/dummy.txt',
2686  '/fileadmin/dummy.txt',
2687  array(
2688  'forceAbsoluteUrl' => '1',
2689  'forceAbsoluteUrl.' => array(
2690  'scheme' => 'typo3'
2691  )
2692  )
2693  ),
2694  'Hostname only is not treated as valid absolute URL' => array(
2695  'http://localhost/example.org',
2696  'example.org',
2697  array(
2698  'forceAbsoluteUrl' => '1'
2699  )
2700  ),
2701  'Scheme and host is added to local file path' => array(
2702  'typo3://localhost/fileadmin/my.pdf',
2703  'fileadmin/my.pdf',
2704  array(
2705  'forceAbsoluteUrl' => '1',
2706  'forceAbsoluteUrl.' => array(
2707  'scheme' => 'typo3'
2708  )
2709  )
2710  )
2711  );
2712  }
2713 
2718  // Force hostname and subfolder
2719  $this->cObj->expects($this->any())->method('getEnvironmentVariable')->will($this->returnValueMap(
2720  array(
2721  array('HTTP_HOST', 'localhost'),
2722  array('TYPO3_SITE_PATH', '/subfolder/'),
2723  )
2724  ));
2725 
2726  $expected = 'http://localhost/subfolder/fileadmin/my.pdf';
2727  $url = 'fileadmin/my.pdf';
2728  $configuration = array(
2729  'forceAbsoluteUrl' => '1'
2730  );
2731 
2732  $this->assertEquals($expected, $this->cObj->_call('forceAbsoluteUrl', $url, $configuration));
2733  }
2734 
2738  protected function getLibParseTarget() {
2739  return array(
2740  'override' => '',
2741  'override.' => array(
2742  'if.' => array(
2743  'isTrue.' => array(
2744  'data' => 'TSFE:dtdAllowsFrames',
2745  ),
2746  ),
2747  ),
2748  );
2749  }
2750 
2754  protected function getLibParseFunc() {
2755  return array(
2756  'makelinks' => '1',
2757  'makelinks.' => array(
2758  'http.' => array(
2759  'keep' => '{$styles.content.links.keep}',
2760  'extTarget' => '',
2761  'extTarget.' => $this->getLibParseTarget(),
2762  'mailto.' => array(
2763  'keep' => 'path',
2764  ),
2765  ),
2766  ),
2767  'tags' => array(
2768  'link' => 'TEXT',
2769  'link.' => array(
2770  'current' => '1',
2771  'typolink.' => array(
2772  'parameter.' => array(
2773  'data' => 'parameters : allParams',
2774  ),
2775  'extTarget.' => $this->getLibParseTarget(),
2776  'target.' => $this->getLibParseTarget(),
2777  ),
2778  'parseFunc.' => array(
2779  'constants' => '1',
2780  ),
2781  ),
2782  ),
2783 
2784  'allowTags' => 'a, abbr, acronym, address, article, aside, b, bdo, big, blockquote, br, caption, center, cite, code, col, colgroup, dd, del, dfn, dl, div, dt, em, font, footer, header, h1, h2, h3, h4, h5, h6, hr, i, img, ins, kbd, label, li, link, meta, nav, ol, p, pre, q, samp, sdfield, section, small, span, strike, strong, style, sub, sup, table, thead, tbody, tfoot, td, th, tr, title, tt, u, ul, var',
2785  'denyTags' => '*',
2786  'sword' => '<span class="csc-sword">|</span>',
2787  'constants' => '1',
2788  'nonTypoTagStdWrap.' => array(
2789  'HTMLparser' => '1',
2790  'HTMLparser.' => array(
2791  'keepNonMatchedTags' => '1',
2792  'htmlSpecialChars' => '2',
2793  ),
2794  ),
2795  );
2796  }
2797 
2801  protected function getLibParseFunc_RTE() {
2802  return array(
2803  'parseFunc' => '',
2804  'parseFunc.' => array(
2805  'allowTags' => 'a, abbr, acronym, address, article, aside, b, bdo, big, blockquote, br, caption, center, cite, code, col, colgroup, dd, del, dfn, dl, div, dt, em, font, footer, header, h1, h2, h3, h4, h5, h6, hr, i, img, ins, kbd, label, li, link, meta, nav, ol, p, pre, q, samp, sdfield, section, small, span, strike, strong, style, sub, sup, table, thead, tbody, tfoot, td, th, tr, title, tt, u, ul, var',
2806  'constants' => '1',
2807  'denyTags' => '*',
2808  'externalBlocks' => 'article, aside, blockquote, div, dd, dl, footer, header, nav, ol, section, table, ul',
2809  'externalBlocks.' => array(
2810  'article.' => array(
2811  'callRecursive' => '1',
2812  'stripNL' => '1',
2813  ),
2814  'aside.' => array(
2815  'callRecursive' => '1',
2816  'stripNL' => '1',
2817  ),
2818  'blockquote.' => array(
2819  'callRecursive' => '1',
2820  'stripNL' => '1',
2821  ),
2822  'dd.' => array(
2823  'callRecursive' => '1',
2824  'stripNL' => '1',
2825  ),
2826  'div.' => array(
2827  'callRecursive' => '1',
2828  'stripNL' => '1',
2829  ),
2830  'dl.' => array(
2831  'callRecursive' => '1',
2832  'stripNL' => '1',
2833  ),
2834  'footer.' => array(
2835  'callRecursive' => '1',
2836  'stripNL' => '1',
2837  ),
2838  'header.' => array(
2839  'callRecursive' => '1',
2840  'stripNL' => '1',
2841  ),
2842  'nav.' => array(
2843  'callRecursive' => '1',
2844  'stripNL' => '1',
2845  ),
2846  'ol.' => array(
2847  'callRecursive' => '1',
2848  'stripNL' => '1',
2849  ),
2850  'section.' => array(
2851  'callRecursive' => '1',
2852  'stripNL' => '1',
2853  ),
2854  'table.' => array(
2855  'HTMLtableCells' => '1',
2856  'HTMLtableCells.' => array(
2857  'addChr10BetweenParagraphs' => '1',
2858  'default.' => array(
2859  'stdWrap.' => array(
2860  'parseFunc' => '=< lib.parseFunc_RTE',
2861  'parseFunc.' => array(
2862  'nonTypoTagStdWrap.' => array(
2863  'encapsLines.' => array(
2864  'nonWrappedTag' => '',
2865  ),
2866  ),
2867  ),
2868  ),
2869  ),
2870  ),
2871  'stdWrap.' => array(
2872  'HTMLparser' => '1',
2873  'HTMLparser.' => array(
2874  'keepNonMatchedTags' => '1',
2875  'tags.' => array(
2876  'table.' => array(
2877  'fixAttrib.' => array(
2878  'class.' => array(
2879  'always' => '1',
2880  'default' => 'contenttable',
2881  'list' => 'contenttable',
2882  ),
2883  ),
2884  ),
2885  ),
2886  ),
2887  ),
2888  'stripNL' => '1',
2889  ),
2890  'ul.' => array(
2891  'callRecursive' => '1',
2892  'stripNL' => '1',
2893  ),
2894  ),
2895  'makelinks' => '1',
2896  'makelinks.' => array(
2897  'http.' => array(
2898  'extTarget.' => array(
2899  'override' => '_blank',
2900  'override.' => array(
2901  'if.' => array(
2902  'isTrue.' => array(
2903  'data' => 'TSFE:dtdAllowsFrames',
2904  ),
2905  ),
2906  ),
2907  ),
2908  'keep' => 'path',
2909  ),
2910  ),
2911  'nonTypoTagStdWrap.' => array(
2912  'encapsLines.' => array(
2913  'addAttributes.' => array(
2914  'P.' => array(
2915  'class' => 'bodytext',
2916  'class.' => array(
2917  'setOnly' => 'blank',
2918  ),
2919  ),
2920  ),
2921  'encapsTagList' => 'p,pre,h1,h2,h3,h4,h5,h6,hr,dt,li',
2922  'innerStdWrap_all.' => array(
2923  'ifBlank' => '&nbsp;',
2924  ),
2925  'nonWrappedTag' => 'P',
2926  'remapTag.' => array(
2927  'DIV' => 'P',
2928  ),
2929  ),
2930  'HTMLparser' => '1',
2931  'HTMLparser.' => array(
2932  'htmlSpecialChars' => '2',
2933  'keepNonMatchedTags' => '1',
2934  ),
2935  ),
2936  'sword' => '<span class="csc-sword">|</span>',
2937  'tags.' => array(
2938  'link' => 'TEXT',
2939  'link.' => array(
2940  'current' => '1',
2941  'parseFunc.' => array(
2942  'constants' => '1',
2943  ),
2944  'typolink.' => array(
2945  'extTarget.' => array(
2946  'override' => '',
2947  'override.' => array(
2948  'if.' => array(
2949  'isTrue.' => array(
2950  'data' => 'TSFE:dtdAllowsFrames',
2951  ),
2952  ),
2953  ),
2954  ),
2955  'parameter.' => array(
2956  'data' => 'parameters : allParams',
2957  ),
2958  'target.' => array(
2959  'override' => '',
2960  'override.' => array(
2961  'if.' => array(
2962  'isTrue.' => array(
2963  'data' => 'TSFE:dtdAllowsFrames',
2964  ),
2965  ),
2966  ),
2967  ),
2968  ),
2969  ),
2970  ),
2971  ),
2972  );
2973  }
2974 
2979  return array(
2980  'Text without tag is wrapped with <p> tag' => array(
2981  'Text without tag',
2982  $this->getLibParseFunc_RTE(),
2983  '<p class="bodytext">Text without tag</p>',
2984  ),
2985  'Text wrapped with <p> tag remains the same' => array(
2986  '<p class="myclass">Text with &lt;p&gt; tag</p>',
2987  $this->getLibParseFunc_RTE(),
2988  '<p class="myclass">Text with &lt;p&gt; tag</p>',
2989  ),
2990  'Text with absolute external link' => array(
2991  'Text with <link http://example.com/foo/>external link</link>',
2992  $this->getLibParseFunc_RTE(),
2993  '<p class="bodytext">Text with <a href="http://example.com/foo/">external link</a></p>',
2994  ),
2995  );
2996  }
2997 
3005  public function stdWrap_parseFuncReturnsParsedHtml($value, $configuration, $expectedResult) {
3006  $this->assertEquals($expectedResult, $this->cObj->stdWrap_parseFunc($value, $configuration));
3007  }
3008 
3017  public function typoLinkEncodesMailAddressForSpamProtection(array $settings, $linkText, $mailAddress, $expected) {
3018  $this->getFrontendController()->spamProtectEmailAddresses = $settings['spamProtectEmailAddresses'];
3019  $this->getFrontendController()->config['config'] = $settings;
3020  $typoScript = array('parameter' => $mailAddress);
3021 
3022  $this->assertEquals($expected, $this->cObj->typoLink($linkText, $typoScript));
3023  }
3024 
3029  return array(
3030  'plain mail without mailto scheme' => array(
3031  array(
3032  'spamProtectEmailAddresses' => '',
3033  'spamProtectEmailAddresses_atSubst' => '',
3034  'spamProtectEmailAddresses_lastDotSubst' => '',
3035  ),
3036  'some.body@test.typo3.org',
3037  'some.body@test.typo3.org',
3038  '<a href="mailto:some.body@test.typo3.org">some.body@test.typo3.org</a>',
3039  ),
3040  'plain mail with mailto scheme' => array(
3041  array(
3042  'spamProtectEmailAddresses' => '',
3043  'spamProtectEmailAddresses_atSubst' => '',
3044  'spamProtectEmailAddresses_lastDotSubst' => '',
3045  ),
3046  'some.body@test.typo3.org',
3047  'mailto:some.body@test.typo3.org',
3048  '<a href="mailto:some.body@test.typo3.org">some.body@test.typo3.org</a>',
3049  ),
3050  'plain with at and dot substitution' => array(
3051  array(
3052  'spamProtectEmailAddresses' => '0',
3053  'spamProtectEmailAddresses_atSubst' => '(at)',
3054  'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
3055  ),
3056  'some.body@test.typo3.org',
3057  'mailto:some.body@test.typo3.org',
3058  '<a href="mailto:some.body@test.typo3.org">some.body@test.typo3.org</a>',
3059  ),
3060  'mono-alphabetic substitution offset +1' => array(
3061  array(
3062  'spamProtectEmailAddresses' => '1',
3063  'spamProtectEmailAddresses_atSubst' => '',
3064  'spamProtectEmailAddresses_lastDotSubst' => '',
3065  ),
3066  'some.body@test.typo3.org',
3067  'mailto:some.body@test.typo3.org',
3068  '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnf/cpezAuftu/uzqp4/psh\');">some.body(at)test.typo3.org</a>',
3069  ),
3070  'mono-alphabetic substitution offset +1 with at substitution' => array(
3071  array(
3072  'spamProtectEmailAddresses' => '1',
3073  'spamProtectEmailAddresses_atSubst' => '@',
3074  'spamProtectEmailAddresses_lastDotSubst' => '',
3075  ),
3076  'some.body@test.typo3.org',
3077  'mailto:some.body@test.typo3.org',
3078  '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnf/cpezAuftu/uzqp4/psh\');">some.body@test.typo3.org</a>',
3079  ),
3080  'mono-alphabetic substitution offset +1 with at and dot substitution' => array(
3081  array(
3082  'spamProtectEmailAddresses' => '1',
3083  'spamProtectEmailAddresses_atSubst' => '(at)',
3084  'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
3085  ),
3086  'some.body@test.typo3.org',
3087  'mailto:some.body@test.typo3.org',
3088  '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnf/cpezAuftu/uzqp4/psh\');">some.body(at)test.typo3(dot)org</a>',
3089  ),
3090  'mono-alphabetic substitution offset -1 with at and dot substitution' => array(
3091  array(
3092  'spamProtectEmailAddresses' => '-1',
3093  'spamProtectEmailAddresses_atSubst' => '(at)',
3094  'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
3095  ),
3096  'some.body@test.typo3.org',
3097  'mailto:some.body@test.typo3.org',
3098  '<a href="javascript:linkTo_UnCryptMailto(\'lzhksn9rnld-ancxZsdrs-sxon2-nqf\');">some.body(at)test.typo3(dot)org</a>',
3099  ),
3100  'entity substitution with at and dot substitution' => array(
3101  array(
3102  'spamProtectEmailAddresses' => 'ascii',
3103  'spamProtectEmailAddresses_atSubst' => '',
3104  'spamProtectEmailAddresses_lastDotSubst' => '',
3105  ),
3106  'some.body@test.typo3.org',
3107  'mailto:some.body@test.typo3.org',
3108  '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#111;&#109;&#101;&#46;&#98;&#111;&#100;&#121;&#64;&#116;&#101;&#115;&#116;&#46;&#116;&#121;&#112;&#111;&#51;&#46;&#111;&#114;&#103;">some.body(at)test.typo3.org</a>',
3109  ),
3110  'entity substitution with at and dot substitution with at and dot substitution' => array(
3111  array(
3112  'spamProtectEmailAddresses' => 'ascii',
3113  'spamProtectEmailAddresses_atSubst' => '(at)',
3114  'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
3115  ),
3116  'some.body@test.typo3.org',
3117  'mailto:some.body@test.typo3.org',
3118  '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#111;&#109;&#101;&#46;&#98;&#111;&#100;&#121;&#64;&#116;&#101;&#115;&#116;&#46;&#116;&#121;&#112;&#111;&#51;&#46;&#111;&#114;&#103;">some.body(at)test.typo3(dot)org</a>',
3119  ),
3120  );
3121  }
3122 
3123 
3128  return array(
3129  'Link to url' => array(
3130  'TYPO3',
3131  array(
3132  'parameter' => 'http://typo3.org',
3133  ),
3134  '<a href="http://typo3.org">TYPO3</a>',
3135  ),
3136  'Link to url without link text' => array(
3137  '',
3138  array(
3139  'parameter' => 'http://typo3.org',
3140  ),
3141  '<a href="http://typo3.org">http://typo3.org</a>',
3142  ),
3143  'Link to url with attributes' => array(
3144  'TYPO3',
3145  array(
3146  'parameter' => 'http://typo3.org',
3147  'ATagParams' => 'class="url-class"',
3148  'extTarget' => '_blank',
3149  'title' => 'Open new window',
3150  ),
3151  '<a href="http://typo3.org" title="Open new window" target="_blank" class="url-class">TYPO3</a>',
3152  ),
3153  'Link to url with attributes in parameter' => array(
3154  'TYPO3',
3155  array(
3156  'parameter' => 'http://typo3.org _blank url-class "Open new window"',
3157  ),
3158  '<a href="http://typo3.org" title="Open new window" target="_blank" class="url-class">TYPO3</a>',
3159  ),
3160  'Link to url with script tag' => array(
3161  '',
3162  array(
3163  'parameter' => 'http://typo3.org<script>alert(123)</script>',
3164  ),
3165  '<a href="http://typo3.org&lt;script&gt;alert(123)&lt;/script&gt;">http://typo3.org&lt;script&gt;alert(123)&lt;/script&gt;</a>',
3166  ),
3167  'Link to email address' => array(
3168  'Email address',
3169  array(
3170  'parameter' => 'foo@bar.org',
3171  ),
3172  '<a href="mailto:foo@bar.org">Email address</a>',
3173  ),
3174  'Link to email address without link text' => array(
3175  '',
3176  array(
3177  'parameter' => 'foo@bar.org',
3178  ),
3179  '<a href="mailto:foo@bar.org">foo@bar.org</a>',
3180  ),
3181  'Link to email with attributes' => array(
3182  'Email address',
3183  array(
3184  'parameter' => 'foo@bar.org',
3185  'ATagParams' => 'class="email-class"',
3186  'title' => 'Write an email',
3187  ),
3188  '<a href="mailto:foo@bar.org" title="Write an email" class="email-class">Email address</a>',
3189  ),
3190  'Link to email with attributes in parameter' => array(
3191  'Email address',
3192  array(
3193  'parameter' => 'foo@bar.org - email-class "Write an email"',
3194  ),
3195  '<a href="mailto:foo@bar.org" title="Write an email" class="email-class">Email address</a>',
3196  ),
3197  );
3198  }
3199 
3207  public function typolinkReturnsCorrectLinksForEmailsAndUrls($linkText, $configuration, $expectedResult) {
3208  $templateServiceObjectMock = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
3209  $templateServiceObjectMock->setup = array(
3210  'lib.' => array(
3211  'parseFunc.' => $this->getLibParseFunc(),
3212  ),
3213  );
3214  $typoScriptFrontendControllerMockObject = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
3215  $typoScriptFrontendControllerMockObject->config = array(
3216  'config' => array(),
3217  'mainScript' => 'index.php',
3218  );
3219  $typoScriptFrontendControllerMockObject->tmpl = $templateServiceObjectMock;
3220  $GLOBALS['TSFE'] = $typoScriptFrontendControllerMockObject;
3221 
3222  $this->assertEquals($expectedResult, $this->cObj->typoLink($linkText, $configuration));
3223  }
3224 
3229  return array(
3230  'Link to page' => array(
3231  'My page',
3232  array(
3233  'parameter' => 42,
3234  ),
3235  array(
3236  'uid' => 42,
3237  'title' => 'Page title',
3238  ),
3239  '<a href="index.php?id=42">My page</a>',
3240  ),
3241  'Link to page without link text' => array(
3242  '',
3243  array(
3244  'parameter' => 42,
3245  ),
3246  array(
3247  'uid' => 42,
3248  'title' => 'Page title',
3249  ),
3250  '<a href="index.php?id=42">Page title</a>',
3251  ),
3252  'Link to page with attributes' => array(
3253  'My page',
3254  array(
3255  'parameter' => '42',
3256  'ATagParams' => 'class="page-class"',
3257  'target' => '_self',
3258  'title' => 'Link to internal page',
3259  ),
3260  array(
3261  'uid' => 42,
3262  'title' => 'Page title',
3263  ),
3264  '<a href="index.php?id=42" title="Link to internal page" target="_self" class="page-class">My page</a>',
3265  ),
3266  'Link to page with attributes in parameter' => array(
3267  'My page',
3268  array(
3269  'parameter' => '42 _self page-class "Link to internal page"',
3270  ),
3271  array(
3272  'uid' => 42,
3273  'title' => 'Page title',
3274  ),
3275  '<a href="index.php?id=42" title="Link to internal page" target="_self" class="page-class">My page</a>',
3276  ),
3277  'Link to page with bold tag in title' => array(
3278  '',
3279  array(
3280  'parameter' => 42,
3281  ),
3282  array(
3283  'uid' => 42,
3284  'title' => 'Page <b>title</b>',
3285  ),
3286  '<a href="index.php?id=42">Page <b>title</b></a>',
3287  ),
3288  'Link to page with script tag in title' => array(
3289  '',
3290  array(
3291  'parameter' => 42,
3292  ),
3293  array(
3294  'uid' => 42,
3295  'title' => '<script>alert(123)</script>Page title',
3296  ),
3297  '<a href="index.php?id=42">&lt;script&gt;alert(123)&lt;/script&gt;Page title</a>',
3298  ),
3299  );
3300  }
3301 
3310  public function typolinkReturnsCorrectLinksForPages($linkText, $configuration, $pageArray, $expectedResult) {
3311  $pageRepositoryMockObject = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('getPage'));
3312  $pageRepositoryMockObject->expects($this->any())->method('getPage')->willReturn($pageArray);
3313  $templateServiceObjectMock = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
3314  $templateServiceObjectMock->setup = array(
3315  'lib.' => array(
3316  'parseFunc.' => $this->getLibParseFunc(),
3317  ),
3318  );
3319  $typoScriptFrontendControllerMockObject = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
3320  $typoScriptFrontendControllerMockObject->config = array(
3321  'config' => array(),
3322  'mainScript' => 'index.php',
3323  );
3324  $typoScriptFrontendControllerMockObject->sys_page = $pageRepositoryMockObject;
3325  $typoScriptFrontendControllerMockObject->tmpl = $templateServiceObjectMock;
3326  $GLOBALS['TSFE'] = $typoScriptFrontendControllerMockObject;
3327 
3328  $this->assertEquals($expectedResult, $this->cObj->typoLink($linkText, $configuration));
3329  }
3330 
3335  return array(
3336  'Link to file' => array(
3337  'My file',
3338  array(
3339  'parameter' => 'fileadmin/foo.bar',
3340  ),
3341  '<a href="fileadmin/foo.bar">My file</a>',
3342  ),
3343  'Link to file without link text' => array(
3344  '',
3345  array(
3346  'parameter' => 'fileadmin/foo.bar',
3347  ),
3348  '<a href="fileadmin/foo.bar">fileadmin/foo.bar</a>',
3349  ),
3350  'Link to file with attributes' => array(
3351  'My file',
3352  array(
3353  'parameter' => 'fileadmin/foo.bar',
3354  'ATagParams' => 'class="file-class"',
3355  'fileTarget' => '_blank',
3356  'title' => 'Title of the file',
3357  ),
3358  '<a href="fileadmin/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>',
3359  ),
3360  'Link to file with attributes in parameter' => array(
3361  'My file',
3362  array(
3363  'parameter' => 'fileadmin/foo.bar _blank file-class "Title of the file"',
3364  ),
3365  '<a href="fileadmin/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>',
3366  ),
3367  'Link to file with script tag in name' => array(
3368  '',
3369  array(
3370  'parameter' => 'fileadmin/<script>alert(123)</script>',
3371  ),
3372  '<a href="fileadmin/&lt;script&gt;alert(123)&lt;/script&gt;">fileadmin/&lt;script&gt;alert(123)&lt;/script&gt;</a>',
3373  ),
3374  );
3375  }
3376 
3384  public function typolinkReturnsCorrectLinksFiles($linkText, $configuration, $expectedResult) {
3385  $templateServiceObjectMock = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('dummy'));
3386  $templateServiceObjectMock->setup = array(
3387  'lib.' => array(
3388  'parseFunc.' => $this->getLibParseFunc(),
3389  ),
3390  );
3391  $typoScriptFrontendControllerMockObject = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
3392  $typoScriptFrontendControllerMockObject->config = array(
3393  'config' => array(),
3394  'mainScript' => 'index.php',
3395  );
3396  $typoScriptFrontendControllerMockObject->tmpl = $templateServiceObjectMock;
3397  $GLOBALS['TSFE'] = $typoScriptFrontendControllerMockObject;
3398 
3399  $this->assertEquals($expectedResult, $this->cObj->typoLink($linkText, $configuration));
3400  }
3401 
3406  return array(
3407  'no markers defined' => array(
3408  'dummy content with ###UNREPLACED### marker',
3409  array(),
3410  array(),
3411  array(),
3412  'dummy content with ###UNREPLACED### marker',
3413  false,
3414  false
3415  ),
3416  'no markers used' => array(
3417  'dummy content with no marker',
3418  array(
3419  '###REPLACED###' => '_replaced_'
3420  ),
3421  array(),
3422  array(),
3423  'dummy content with no marker',
3424  true,
3425  false
3426  ),
3427  'one marker' => array(
3428  'dummy content with ###REPLACED### marker',
3429  array(
3430  '###REPLACED###' => '_replaced_'
3431  ),
3432  array(),
3433  array(),
3434  'dummy content with _replaced_ marker'
3435  ),
3436  'one marker with lots of chars' => array(
3437  'dummy content with ###RE.:##-=_()LACED### marker',
3438  array(
3439  '###RE.:##-=_()LACED###' => '_replaced_'
3440  ),
3441  array(),
3442  array(),
3443  'dummy content with _replaced_ marker'
3444  ),
3445  'markers which are special' => array(
3446  'dummy ###aa##.#######A### ######',
3447  array(
3448  '###aa##.###' => 'content ',
3449  '###A###' => 'is',
3450  '######' => '-is not considered-'
3451  ),
3452  array(),
3453  array(),
3454  'dummy content #is ######'
3455  ),
3456  'two markers in content, but more defined' => array(
3457  'dummy ###CONTENT### with ###REPLACED### marker',
3458  array(
3459  '###REPLACED###' => '_replaced_',
3460  '###CONTENT###' => 'content',
3461  '###NEVERUSED###' => 'bar'
3462  ),
3463  array(),
3464  array(),
3465  'dummy content with _replaced_ marker'
3466  ),
3467  'one subpart' => array(
3468  'dummy content with ###ASUBPART### around some text###ASUBPART###.',
3469  array(),
3470  array(
3471  '###ASUBPART###' => 'some other text'
3472  ),
3473  array(),
3474  'dummy content with some other text.'
3475  ),
3476  'one wrapped subpart' => array(
3477  'dummy content with ###AWRAPPEDSUBPART### around some text###AWRAPPEDSUBPART###.',
3478  array(),
3479  array(),
3480  array(
3481  '###AWRAPPEDSUBPART###' => array(
3482  'more content',
3483  'content'
3484  )
3485  ),
3486  'dummy content with more content around some textcontent.'
3487  ),
3488  'one subpart with markers, not replaced recursively' => array(
3489  'dummy ###CONTENT### with ###ASUBPART### around ###SOME### text###ASUBPART###.',
3490  array(
3491  '###CONTENT###' => 'content',
3492  '###SOME###' => '-this should never make it into output-',
3493  '###OTHER_NOT_REPLACED###' => '-this should never make it into output-'
3494  ),
3495  array(
3496  '###ASUBPART###' => 'some ###OTHER_NOT_REPLACED### text'
3497  ),
3498  array(),
3499  'dummy content with some ###OTHER_NOT_REPLACED### text.'
3500  ),
3501  );
3502  }
3503 
3516  public function substituteMarkerArrayCachedReturnsExpectedContent($content, array $markContentArray, array $subpartContentArray, array $wrappedSubpartContentArray, $expectedContent, $shouldQueryCache = true, $shouldStoreCache = true) {
3518  $pageRepo = $this->tsfe->sys_page;
3519  $pageRepo->resetCallCount();
3520 
3521  $resultContent = $this->cObj->substituteMarkerArrayCached($content, $markContentArray, $subpartContentArray, $wrappedSubpartContentArray);
3522 
3523  $this->assertSame((int)$shouldQueryCache, $pageRepo::$getHashCallCount, 'getHash call count mismatch');
3524  $this->assertSame((int)$shouldStoreCache, $pageRepo::$storeHashCallCount, 'storeHash call count mismatch');
3525  $this->assertSame($expectedContent, $resultContent);
3526  }
3527 
3531  public function substituteMarkerArrayCachedRetrievesCachedValueFromRuntimeCache() {
3533  $pageRepo = $this->tsfe->sys_page;
3534  $pageRepo->resetCallCount();
3535 
3536  $content = 'Please tell me this ###FOO###.';
3537  $markContentArray = array(
3538  '###FOO###' => 'foo',
3539  '###NOTUSED###' => 'blub'
3540  );
3541  $storeKey = md5('substituteMarkerArrayCached_storeKey:' . serialize(array($content, array_keys($markContentArray))));
3542  $this->cObj->substMarkerCache[$storeKey] = array(
3543  'c' => array(
3544  'Please tell me this ',
3545  '.'
3546  ),
3547  'k' => array(
3548  '###FOO###'
3549  ),
3550  );
3551  $resultContent = $this->cObj->substituteMarkerArrayCached($content, $markContentArray);
3552  $this->assertSame(0, $pageRepo::$getHashCallCount);
3553  $this->assertSame('Please tell me this foo.', $resultContent);
3554  }
3555 
3559  public function substituteMarkerArrayCachedRetrievesCachedValueFromDbCache() {
3561  $pageRepo = $this->tsfe->sys_page;
3562  $pageRepo->resetCallCount();
3563 
3564  $content = 'Please tell me this ###FOO###.';
3565  $markContentArray = array(
3566  '###FOO###' => 'foo',
3567  '###NOTUSED###' => 'blub'
3568  );
3569  $pageRepo::$dbCacheContent = array(
3570  'c' => array(
3571  'Please tell me this ',
3572  '.'
3573  ),
3574  'k' => array(
3575  '###FOO###'
3576  ),
3577  );
3578  $resultContent = $this->cObj->substituteMarkerArrayCached($content, $markContentArray);
3579  $this->assertSame(1, $pageRepo::$getHashCallCount, 'getHash call count mismatch');
3580  $this->assertSame(0, $pageRepo::$storeHashCallCount, 'storeHash call count mismatch');
3581  $this->assertSame('Please tell me this foo.', $resultContent);
3582  }
3583 
3587  public function substituteMarkerArrayCachedStoresResultInCaches() {
3589  $pageRepo = $this->tsfe->sys_page;
3590  $pageRepo->resetCallCount();
3591 
3592  $content = 'Please tell me this ###FOO###.';
3593  $markContentArray = array(
3594  '###FOO###' => 'foo',
3595  '###NOTUSED###' => 'blub'
3596  );
3597  $resultContent = $this->cObj->substituteMarkerArrayCached($content, $markContentArray);
3598 
3599  $storeKey = md5('substituteMarkerArrayCached_storeKey:' . serialize(array($content, array_keys($markContentArray))));
3600  $storeArr = array(
3601  'c' => array(
3602  'Please tell me this ',
3603  '.'
3604  ),
3605  'k' => array(
3606  '###FOO###'
3607  ),
3608  );
3609  $this->assertSame(1, $pageRepo::$getHashCallCount);
3610  $this->assertSame('Please tell me this foo.', $resultContent);
3611  $this->assertSame($storeArr, $this->cObj->substMarkerCache[$storeKey]);
3612  $this->assertSame(1, $pageRepo::$storeHashCallCount);
3613  }
3614 
3618  protected function getFrontendController() {
3619  return $GLOBALS['TSFE'];
3620  }
3621 
3622 }
static addInstance($className, $instance)
typolinkReturnsCorrectLinksForPages($linkText, $configuration, $pageArray, $expectedResult)
$uid
Definition: server.php:36
typoLinkEncodesMailAddressForSpamProtection(array $settings, $linkText, $mailAddress, $expected)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
typolinkReturnsCorrectLinksForEmailsAndUrls($linkText, $configuration, $expectedResult)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]