13b6727d7a9a8ffdef31ff21dae91b5d9b416bb6
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / ContentObject / ContentObjectRendererTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Oliver Hader <oliver@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
28 *
29 * @author Oliver Hader <oliver@typo3.org>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 */
32 class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
36 */
37 protected $cObj = NULL;
38
39 /**
40 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
41 */
42 protected $tsfe = NULL;
43
44 /**
45 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\TypoScript\TemplateService
46 */
47 protected $template = NULL;
48
49 /**
50 * Set up
51 */
52 public function setUp() {
53 $this->template = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('getFileName', 'linkData'));
54 $this->tsfe = $this->getAccessibleMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
55 $this->tsfe->tmpl = $this->template;
56 $this->tsfe->config = array();
57 $this->tsfe->page = array();
58 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('getRawRecord'));
59 $this->tsfe->sys_page = $sysPageMock;
60 $GLOBALS['TSFE'] = $this->tsfe;
61 $GLOBALS['TSFE']->csConvObj = new \TYPO3\CMS\Core\Charset\CharsetConverter();
62 $GLOBALS['TSFE']->renderCharset = 'utf-8';
63 $GLOBALS['TYPO3_CONF_VARS']['SYS']['TYPO3\\CMS\\Core\\Charset\\CharsetConverter_utils'] = 'mbstring';
64 $this->cObj = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('dummy'));
65 $this->cObj->start(array(), 'tt_content');
66 }
67
68 ////////////////////////
69 // Utitility functions
70 ////////////////////////
71 /**
72 * Converts the subject and the expected result into the target charset.
73 *
74 * @param string $charset the target charset
75 * @param string $subject the subject, will be modified
76 * @param string $expected the expected result, will be modified
77 */
78 protected function handleCharset($charset, &$subject, &$expected) {
79 $GLOBALS['TSFE']->renderCharset = $charset;
80 $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset);
81 $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset);
82 }
83
84 /////////////////////////////////////////////
85 // Tests concerning the getImgResource hook
86 /////////////////////////////////////////////
87 /**
88 * @test
89 */
90 public function getImgResourceHookGetsCalled() {
91 $this->template->expects($this->atLeastOnce())->method('getFileName')->with('typo3/clear.gif')->will($this->returnValue('typo3/clear.gif'));
92 $className = uniqid('tx_coretest');
93 $getImgResourceHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectGetImageResourceHookInterface', array('getImgResourcePostProcess'), array(), $className);
94 $getImgResourceHookMock->expects($this->once())->method('getImgResourcePostProcess')->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
95 $getImgResourceHookObjects = array($getImgResourceHookMock);
96 $this->cObj->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
97 $this->cObj->IMAGE(array('file' => 'typo3/clear.gif'));
98 }
99
100 /**
101 * Handles the arguments that have been sent to the getImgResource hook.
102 *
103 * @return array
104 * @see getImgResourceHookGetsCalled
105 */
106 public function isGetImgResourceHookCalledCallback() {
107 list($file, $fileArray, $imageResource, $parent) = func_get_args();
108 $this->assertEquals('typo3/clear.gif', $file);
109 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
110 $this->assertTrue(is_array($fileArray));
111 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer);
112 return $imageResource;
113 }
114
115
116 /*************************
117 * Tests concerning getContentObject
118 ************************/
119 public function getContentObjectValidContentObjectsDataProvider() {
120 return array(
121 array('TEXT', 'Text'),
122 array('CASE', 'Case'),
123 array('CLEARGIF', 'ClearGif'),
124 array('COBJ_ARRAY', 'ContentObjectArray'),
125 array('COA', 'ContentObjectArray'),
126 array('COA_INT', 'ContentObjectArrayInternal'),
127 array('USER', 'User'),
128 array('USER_INT', 'UserInternal'),
129 array('FILE', 'File'),
130 array('FILES', 'Files'),
131 array('IMAGE', 'Image'),
132 array('IMG_RESOURCE', 'ImageResource'),
133 array('IMGTEXT', 'ImageText'),
134 array('CONTENT', 'Content'),
135 array('RECORDS', 'Records'),
136 array('HMENU', 'HierarchicalMenu'),
137 array('CTABLE', 'ContentTable'),
138 array('OTABLE', 'OffsetTable'),
139 array('COLUMNS', 'Columns'),
140 array('HRULER', 'HorizontalRuler'),
141 array('CASEFUNC', 'Case'),
142 array('LOAD_REGISTER', 'LoadRegister'),
143 array('RESTORE_REGISTER', 'RestoreRegister'),
144 array('FORM', 'Form'),
145 array('SEARCHRESULT', 'SearchResult'),
146 array('TEMPLATE', 'Template'),
147 array('FLUIDTEMPLATE', 'FluidTemplate'),
148 array('MULTIMEDIA', 'Multimedia'),
149 array('MEDIA', 'Media'),
150 array('SWFOBJECT', 'ShockwaveFlashObject'),
151 array('FLOWPLAYER', 'FlowPlayer'),
152 array('QTOBJECT', 'QuicktimeObject'),
153 array('SVG', 'ScalableVectorGraphics'),
154 array('EDITPANEL', 'EditPanel'),
155 );
156 }
157
158 /**
159 * @test
160 * @dataProvider getContentObjectValidContentObjectsDataProvider
161 * @param string $name TypoScript name of content object
162 * @param string $className Expected class name
163 */
164 public function getContentObjectUsesExistingInstanceOfRequestedObjectType($name, $className) {
165 $fullClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $className . 'ContentObject';
166 $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', FALSE);
167 $this->cObj->_set('contentObjects', array($className => $contentObjectInstance));
168 $this->assertSame($contentObjectInstance, $this->cObj->getContentObject($name));
169 }
170
171 /**
172 * @test
173 * @dataProvider getContentObjectValidContentObjectsDataProvider
174 * @param string $name TypoScript name of content object
175 * @param string $className Expected class name
176 */
177 public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $className) {
178 $fullClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $className . 'ContentObject';
179 $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', FALSE);
180 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($fullClassName, $contentObjectInstance);
181 $this->assertSame($contentObjectInstance, $this->cObj->getContentObject($name));
182 }
183
184 //////////////////////////
185 // Tests concerning FORM
186 //////////////////////////
187 /**
188 * @test
189 */
190 public function formWithSecureFormMailEnabledDoesNotContainRecipientField() {
191 $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = TRUE;
192 $this->assertNotContains('name="recipient', $this->cObj->FORM(array('recipient' => 'foo@bar.com', 'recipient.' => array()), array()));
193 }
194
195 /**
196 * @test
197 */
198 public function formWithSecureFormMailDisabledDoesNotContainRecipientField() {
199 $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = FALSE;
200 $this->assertContains('name="recipient', $this->cObj->FORM(array('recipient' => 'foo@bar.com', 'recipient.' => array()), array()));
201 }
202
203 /////////////////////////////////////////
204 // Tests concerning getQueryArguments()
205 /////////////////////////////////////////
206 /**
207 * @test
208 */
209 public function getQueryArgumentsExcludesParameters() {
210 $_SERVER['QUERY_STRING'] = 'key1=value1' . '&key2=value2' . '&key3[key31]=value31' . '&key3[key32][key321]=value321' . '&key3[key32][key322]=value322';
211 $getQueryArgumentsConfiguration = array();
212 $getQueryArgumentsConfiguration['exclude'] = array();
213 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
214 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
215 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
216 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
217 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
218 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
219 $this->assertEquals($expectedResult, $actualResult);
220 }
221
222 /**
223 * @test
224 */
225 public function getQueryArgumentsExcludesGetParameters() {
226 $_GET = array(
227 'key1' => 'value1',
228 'key2' => 'value2',
229 'key3' => array(
230 'key31' => 'value31',
231 'key32' => array(
232 'key321' => 'value321',
233 'key322' => 'value322'
234 )
235 )
236 );
237 $getQueryArgumentsConfiguration = array();
238 $getQueryArgumentsConfiguration['method'] = 'GET';
239 $getQueryArgumentsConfiguration['exclude'] = array();
240 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
241 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
242 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
243 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
244 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
245 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
246 $this->assertEquals($expectedResult, $actualResult);
247 }
248
249 /**
250 * @test
251 */
252 public function getQueryArgumentsOverrulesSingleParameter() {
253 $_SERVER['QUERY_STRING'] = 'key1=value1';
254 $getQueryArgumentsConfiguration = array();
255 $overruleArguments = array(
256 // Should be overriden
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
266 /**
267 * @test
268 */
269 public function getQueryArgumentsOverrulesMultiDimensionalParameters() {
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
307 /**
308 * @test
309 */
310 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters() {
311 $_SERVER['QUERY_STRING'] = 'key1=value1' . '&key2=value2' . '&key3[key31]=value31' . '&key3[key32][key321]=value321' . '&key3[key32][key322]=value322';
312 $_POST = array(
313 'key1' => 'value1',
314 'key2' => 'value2',
315 'key3' => array(
316 'key31' => 'value31',
317 'key32' => array(
318 'key321' => 'value321',
319 'key322' => 'value322'
320 )
321 )
322 );
323 $getQueryArgumentsConfiguration = array();
324 $getQueryArgumentsConfiguration['exclude'] = array();
325 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
326 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
327 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
328 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
329 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
330 $overruleArguments = array(
331 // Should be overriden
332 'key2' => 'value2Overruled',
333 'key3' => array(
334 'key32' => array(
335 // Should be set: Parameter is excluded but forced
336 'key321' => 'value321Overruled',
337 // Should be set: Parameter doesn't exist in source array but is forced
338 'key323' => 'value323Overruled'
339 )
340 )
341 );
342 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
343 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
344 $this->assertEquals($expectedResult, $actualResult);
345 $getQueryArgumentsConfiguration['method'] = 'POST';
346 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
347 $this->assertEquals($expectedResult, $actualResult);
348 }
349
350 /**
351 * Encodes square brackets in URL.
352 *
353 * @param string $string
354 * @return string
355 */
356 private function rawUrlEncodeSquareBracketsInUrl($string) {
357 return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
358 }
359
360 //////////////////////////////
361 // Tests concerning crop
362 //////////////////////////////
363 /**
364 * @test
365 */
366 public function cropIsMultibyteSafe() {
367 $this->assertEquals('бла', $this->cObj->crop('бла', '3|...'));
368 }
369
370 //////////////////////////////
371 // Tests concerning cropHTML
372 //////////////////////////////
373 /**
374 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
375 * of charset, text type, and configuration options to be tested.
376 *
377 * @return array two-dimensional array with the second level like this:
378 * @see cropHtmlWithDataProvider
379 */
380 public function cropHtmlDataProvider() {
381 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
382 $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.';
383 $textWithEntities = 'Kasper Sk&aring;rh&oslash;j implemented the; original ' . 'version of the crop function.';
384 $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
385 $data = array();
386 foreach ($charsets as $charset) {
387 $data = array_merge($data, array(
388 $charset . ' plain text; 11|...' => array(
389 '11|...',
390 $plainText,
391 'Kasper Sk' . chr(229) . 'r...',
392 $charset
393 ),
394 $charset . ' plain text; -58|...' => array(
395 '-58|...',
396 $plainText,
397 '...h' . chr(248) . 'j implemented the original version of the crop function.',
398 $charset
399 ),
400 $charset . ' plain text; 4|...|1' => array(
401 '4|...|1',
402 $plainText,
403 'Kasp...',
404 $charset
405 ),
406 $charset . ' plain text; 20|...|1' => array(
407 '20|...|1',
408 $plainText,
409 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...',
410 $charset
411 ),
412 $charset . ' plain text; -5|...|1' => array(
413 '-5|...|1',
414 $plainText,
415 '...tion.',
416 $charset
417 ),
418 $charset . ' plain text; -49|...|1' => array(
419 '-49|...|1',
420 $plainText,
421 '...the original version of the crop function.',
422 $charset
423 ),
424 $charset . ' text with markup; 11|...' => array(
425 '11|...',
426 $textWithMarkup,
427 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>',
428 $charset
429 ),
430 $charset . ' text with markup; 13|...' => array(
431 '13|...',
432 $textWithMarkup,
433 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>',
434 $charset
435 ),
436 $charset . ' text with markup; 14|...' => array(
437 '14|...',
438 $textWithMarkup,
439 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
440 $charset
441 ),
442 $charset . ' text with markup; 15|...' => array(
443 '15|...',
444 $textWithMarkup,
445 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>',
446 $charset
447 ),
448 $charset . ' text with markup; 29|...' => array(
449 '29|...',
450 $textWithMarkup,
451 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...',
452 $charset
453 ),
454 $charset . ' text with markup; -58|...' => array(
455 '-58|...',
456 $textWithMarkup,
457 '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
458 $charset
459 ),
460 $charset . ' text with markup 4|...|1' => array(
461 '4|...|1',
462 $textWithMarkup,
463 '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>',
464 $charset
465 ),
466 $charset . ' text with markup; 11|...|1' => array(
467 '11|...|1',
468 $textWithMarkup,
469 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
470 $charset
471 ),
472 $charset . ' text with markup; 13|...|1' => array(
473 '13|...|1',
474 $textWithMarkup,
475 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
476 $charset
477 ),
478 $charset . ' text with markup; 14|...|1' => array(
479 '14|...|1',
480 $textWithMarkup,
481 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
482 $charset
483 ),
484 $charset . ' text with markup; 15|...|1' => array(
485 '15|...|1',
486 $textWithMarkup,
487 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
488 $charset
489 ),
490 $charset . ' text with markup; 29|...|1' => array(
491 '29|...|1',
492 $textWithMarkup,
493 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...',
494 $charset
495 ),
496 $charset . ' text with markup; -66|...|1' => array(
497 '-66|...|1',
498 $textWithMarkup,
499 '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
500 $charset
501 ),
502 $charset . ' text with entities 9|...' => array(
503 '9|...',
504 $textWithEntities,
505 'Kasper Sk...',
506 $charset
507 ),
508 $charset . ' text with entities 10|...' => array(
509 '10|...',
510 $textWithEntities,
511 'Kasper Sk&aring;...',
512 $charset
513 ),
514 $charset . ' text with entities 11|...' => array(
515 '11|...',
516 $textWithEntities,
517 'Kasper Sk&aring;r...',
518 $charset
519 ),
520 $charset . ' text with entities 13|...' => array(
521 '13|...',
522 $textWithEntities,
523 'Kasper Sk&aring;rh&oslash;...',
524 $charset
525 ),
526 $charset . ' text with entities 14|...' => array(
527 '14|...',
528 $textWithEntities,
529 'Kasper Sk&aring;rh&oslash;j...',
530 $charset
531 ),
532 $charset . ' text with entities 15|...' => array(
533 '15|...',
534 $textWithEntities,
535 'Kasper Sk&aring;rh&oslash;j ...',
536 $charset
537 ),
538 $charset . ' text with entities 16|...' => array(
539 '16|...',
540 $textWithEntities,
541 'Kasper Sk&aring;rh&oslash;j i...',
542 $charset
543 ),
544 $charset . ' text with entities -57|...' => array(
545 '-57|...',
546 $textWithEntities,
547 '...j implemented the; original version of the crop function.',
548 $charset
549 ),
550 $charset . ' text with entities -58|...' => array(
551 '-58|...',
552 $textWithEntities,
553 '...&oslash;j implemented the; original version of the crop function.',
554 $charset
555 ),
556 $charset . ' text with entities -59|...' => array(
557 '-59|...',
558 $textWithEntities,
559 '...h&oslash;j implemented the; original version of the crop function.',
560 $charset
561 ),
562 $charset . ' text with entities 4|...|1' => array(
563 '4|...|1',
564 $textWithEntities,
565 'Kasp...',
566 $charset
567 ),
568 $charset . ' text with entities 9|...|1' => array(
569 '9|...|1',
570 $textWithEntities,
571 'Kasper...',
572 $charset
573 ),
574 $charset . ' text with entities 10|...|1' => array(
575 '10|...|1',
576 $textWithEntities,
577 'Kasper...',
578 $charset
579 ),
580 $charset . ' text with entities 11|...|1' => array(
581 '11|...|1',
582 $textWithEntities,
583 'Kasper...',
584 $charset
585 ),
586 $charset . ' text with entities 13|...|1' => array(
587 '13|...|1',
588 $textWithEntities,
589 'Kasper...',
590 $charset
591 ),
592 $charset . ' text with entities 14|...|1' => array(
593 '14|...|1',
594 $textWithEntities,
595 'Kasper Sk&aring;rh&oslash;j...',
596 $charset
597 ),
598 $charset . ' text with entities 15|...|1' => array(
599 '15|...|1',
600 $textWithEntities,
601 'Kasper Sk&aring;rh&oslash;j...',
602 $charset
603 ),
604 $charset . ' text with entities 16|...|1' => array(
605 '16|...|1',
606 $textWithEntities,
607 'Kasper Sk&aring;rh&oslash;j...',
608 $charset
609 ),
610 $charset . ' text with entities -57|...|1' => array(
611 '-57|...|1',
612 $textWithEntities,
613 '...implemented the; original version of the crop function.',
614 $charset
615 ),
616 $charset . ' text with entities -58|...|1' => array(
617 '-58|...|1',
618 $textWithEntities,
619 '...implemented the; original version of the crop function.',
620 $charset
621 ),
622 $charset . ' text with entities -59|...|1' => array(
623 '-59|...|1',
624 $textWithEntities,
625 '...implemented the; original version of the crop function.',
626 $charset
627 ),
628 $charset . ' text with dash in html-element 28|...|1' => array(
629 '28|...|1',
630 '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',
631 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>',
632 $charset
633 )
634 ));
635 }
636 return $data;
637 }
638
639 /**
640 * Checks if stdWrap.cropHTML works with plain text cropping from left
641 *
642 * @test
643 * @dataProvider cropHtmlDataProvider
644 * @param string $settings
645 * @param string $subject the string to crop
646 * @param string $expected the expected cropped result
647 * @param string $charset the charset that will be set as renderCharset
648 */
649 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
650 $this->handleCharset($charset, $subject, $expected);
651 $this->assertEquals($expected, $this->cObj->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"');
652 }
653
654 /**
655 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
656 * counts multiple invisible characters not as one (as the browser will output the content).
657 *
658 * @test
659 */
660 public function cropHtmlWorksWithComplexContent() {
661 $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
662 $subject = '
663 <h1>Blog Example</h1>
664 <hr>
665 <div class="csc-header csc-header-n1">
666 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
667 </div>
668 <p class="bodytext">
669 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>.
670 </p>
671 <div class="tx-blogexample-list-container">
672 <p class="bodytext">
673 Below are the most recent posts:
674 </p>
675 <ul>
676 <li>
677 <h3>
678 <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>
679 </h3>
680 <p class="bodytext">
681 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
682 </p>
683 <p class="metadata">
684 Published on 26.08.2009 by Jochen Rau
685 </p>
686 <p>
687 Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>
688 <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>
689 <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>
690 </p>
691 </li>
692 </ul>
693 <p>
694 <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>
695 </p>
696 </div>
697 <hr>
698 <p>
699 ? TYPO3 Association
700 </p>
701 ';
702 $result = $this->cObj->cropHTML($subject, '300');
703 $expected = '
704 <h1>Blog Example</h1>
705 <hr>
706 <div class="csc-header csc-header-n1">
707 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
708 </div>
709 <p class="bodytext">
710 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>.
711 </p>
712 <div class="tx-blogexample-list-container">
713 <p class="bodytext">
714 Below are the most recent posts:
715 </p>
716 <ul>
717 <li>
718 <h3>
719 <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>';
720 $this->assertEquals($expected, $result);
721 $result = $this->cObj->cropHTML($subject, '-100');
722 $expected = '<div class="tx-blogexample-list-container"><ul><li><p>Design]&nbsp;<br>
723 <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>
724 <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>
725 </p>
726 </li>
727 </ul>
728 <p>
729 <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>
730 </p>
731 </div>
732 <hr>
733 <p>
734 ? TYPO3 Association
735 </p>
736 ';
737 $this->assertEquals($expected, $result);
738 }
739
740 /**
741 * @return array
742 */
743 public function stdWrap_roundDataProvider() {
744 return array(
745 'rounding off without any configuration' => array(
746 1.123456789,
747 array(),
748 1
749 ),
750 'rounding up without any configuration' => array(
751 1.523456789,
752 array(),
753 2
754 ),
755 'regular rounding (off) to two decimals' => array(
756 0.123456789,
757 array(
758 'decimals' => 2
759 ),
760 0.12
761 ),
762 'regular rounding (up) to two decimals' => array(
763 0.1256789,
764 array(
765 'decimals' => 2
766 ),
767 0.13
768 ),
769 'rounding up to integer with type ceil' => array(
770 0.123456789,
771 array(
772 'roundType' => 'ceil'
773 ),
774 1
775 ),
776 'rounding down to integer with type floor' => array(
777 2.3481,
778 array(
779 'roundType' => 'floor'
780 ),
781 2
782 )
783 );
784 }
785
786 /**
787 * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
788 *
789 * @test
790 */
791 public function cropHtmlWorksWithLinebreaks() {
792 $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
793 $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
794 $result = $this->cObj->cropHTML($subject, '121');
795 $this->assertEquals($expected, $result);
796 }
797
798 /**
799 * Test for the stdWrap function "round"
800 *
801 * @param float $float
802 * @param array $conf
803 * @param float $expected
804 * @return void
805 * @dataProvider stdWrap_roundDataProvider
806 * @test
807 */
808 public function stdWrap_round($float, $conf, $expected) {
809 $conf = array(
810 'round.' => $conf
811 );
812 $result = $this->cObj->stdWrap_round($float, $conf);
813 $this->assertEquals($expected, $result);
814 }
815
816 /**
817 * @return array
818 */
819 public function stdWrap_strPadDataProvider() {
820 return array(
821 'pad string with default settings and length 10' => array(
822 'Alien',
823 array(
824 'length' => '10',
825 ),
826 'Alien ',
827 ),
828 'pad string with padWith -= and type left and length 10' => array(
829 'Alien',
830 array(
831 'length' => '10',
832 'padWith' => '-=',
833 'type' => 'left',
834 ),
835 '-=-=-Alien',
836 ),
837 'pad string with padWith _ and type both and length 10' => array(
838 'Alien',
839 array(
840 'length' => '10',
841 'padWith' => '_',
842 'type' => 'both',
843 ),
844 '__Alien___',
845 ),
846 'pad string with padWith ___ and type both and length 6' => array(
847 'Alien',
848 array(
849 'length' => '6',
850 'padWith' => '___',
851 'type' => 'both',
852 ),
853 'Alien_',
854 ),
855 'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
856 'Alien',
857 array(
858 'length' => '1',
859 'length.' => array(
860 'wrap' => '|2',
861 ),
862 'padWith' => '_',
863 'type' => 'both',
864 ),
865 '___Alien____',
866 ),
867 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
868 'Alien',
869 array(
870 'length' => '12',
871 'padWith' => '_',
872 'padWith.' => array(
873 'wrap' => '-|=',
874 ),
875 'type' => 'both',
876 ),
877 '-_=Alien-_=-',
878 ),
879 'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
880 'Alien',
881 array(
882 'length' => '12',
883 'padWith' => '_',
884 'type' => 'both',
885 // make type become "left"
886 'type.' => array(
887 'substring' => '2,1',
888 'wrap' => 'lef|',
889 ),
890 ),
891 '_______Alien',
892 ),
893 );
894 }
895
896 /**
897 * Test for the stdWrap function "strPad"
898 *
899 * @param string $content
900 * @param array $conf
901 * @param string $expected
902 *
903 * @dataProvider stdWrap_strPadDataProvider
904 * @test
905 */
906 public function stdWrap_strPad($content, $conf, $expected) {
907 $conf = array(
908 'strPad.' => $conf
909 );
910 $result = $this->cObj->stdWrap_strPad($content, $conf);
911 $this->assertEquals($expected, $result);
912 }
913
914 /**
915 * Data provider for the hash test
916 *
917 * @return array multi-dimensional array with the second level like this:
918 * @see hash
919 */
920 public function hashDataProvider() {
921 $data = array(
922 'testing md5' => array(
923 'joh316',
924 array(
925 'hash' => 'md5'
926 ),
927 'bacb98acf97e0b6112b1d1b650b84971'
928 ),
929 'testing sha1' => array(
930 'joh316',
931 array(
932 'hash' => 'sha1'
933 ),
934 '063b3d108bed9f88fa618c6046de0dccadcf3158'
935 ),
936 'testing non-existing hashing algorithm' => array(
937 'joh316',
938 array(
939 'hash' => 'non-existing'
940 ),
941 ''
942 ),
943 'testing stdWrap capability' => array(
944 'joh316',
945 array(
946 'hash.' => array(
947 'cObject' => 'TEXT',
948 'cObject.' => array(
949 'value' => 'md5'
950 )
951 )
952 ),
953 'bacb98acf97e0b6112b1d1b650b84971'
954 )
955 );
956 return $data;
957 }
958
959 /**
960 * Test for the stdWrap function "hash"
961 *
962 * @param string $text
963 * @param array $conf
964 * @param string $expected
965 * @return void
966 * @dataProvider hashDataProvider
967 * @test
968 */
969 public function stdWrap_hash($text, array $conf, $expected) {
970 $result = $this->cObj->stdWrap_hash($text, $conf);
971 $this->assertEquals($expected, $result);
972 }
973
974 /**
975 * Data provider for the numberFormat test
976 *
977 * @return array multi-dimensional array with the second level like this:
978 * @see numberFormat
979 */
980 public function numberFormatDataProvider() {
981 $data = array(
982 'testing decimals' => array(
983 0.8,
984 array(
985 'decimals' => 2
986 ),
987 '0.80'
988 ),
989 'testing decimals with input as string' => array(
990 '0.8',
991 array(
992 'decimals' => 2
993 ),
994 '0.80'
995 ),
996 'testing dec_point' => array(
997 0.8,
998 array(
999 'decimals' => 1,
1000 'dec_point' => ','
1001 ),
1002 '0,8'
1003 ),
1004 'testing thousands_sep' => array(
1005 999.99,
1006 array(
1007 'decimals' => 0,
1008 'thousands_sep.' => array(
1009 'char' => 46
1010 )
1011 ),
1012 '1.000'
1013 ),
1014 'testing mixture' => array(
1015 1281731.45,
1016 array(
1017 'decimals' => 1,
1018 'dec_point.' => array(
1019 'char' => 44
1020 ),
1021 'thousands_sep.' => array(
1022 'char' => 46
1023 )
1024 ),
1025 '1.281.731,5'
1026 )
1027 );
1028 return $data;
1029 }
1030
1031 /**
1032 * Check if stdWrap.numberFormat and all of its properties work properly
1033 *
1034 * @dataProvider numberFormatDataProvider
1035 * @test
1036 */
1037 public function numberFormat($float, $formatConf, $expected) {
1038 $result = $this->cObj->numberFormat($float, $formatConf);
1039 $this->assertEquals($expected, $result);
1040 }
1041
1042 /**
1043 * Data provider for the replacement test
1044 *
1045 * @return array multi-dimensional array with the second level like this:
1046 * @see replacement
1047 */
1048 public function replacementDataProvider() {
1049 $data = array(
1050 'multiple replacements, including regex' => array(
1051 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1052 array(
1053 'replacement.' => array(
1054 '120.' => array(
1055 'search' => 'in da hood',
1056 'replace' => 'around the block'
1057 ),
1058 '20.' => array(
1059 'search' => '_',
1060 'replace.' => array('char' => '32')
1061 ),
1062 '130.' => array(
1063 'search' => '#a (Cat|Dog|Tiger)#i',
1064 'replace' => 'an animal',
1065 'useRegExp' => '1'
1066 )
1067 )
1068 ),
1069 'There is an animal, an animal and an animal around the block! Yeah!'
1070 ),
1071 'replacement with optionSplit, normal pattern' => array(
1072 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1073 array(
1074 'replacement.' => array(
1075 '10.' => array(
1076 'search' => '_',
1077 'replace' => '1 || 2 || 3',
1078 'useOptionSplitReplace' => '1'
1079 ),
1080 )
1081 ),
1082 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1083 ),
1084 'replacement with optionSplit, using regex' => array(
1085 'There is a cat, a dog and a tiger in da hood! Yeah!',
1086 array(
1087 'replacement.' => array(
1088 '10.' => array(
1089 'search' => '#(a) (Cat|Dog|Tiger)#i',
1090 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1091 'useOptionSplitReplace' => '1',
1092 'useRegExp' => '1'
1093 )
1094 )
1095 ),
1096 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1097 ),
1098 );
1099 return $data;
1100 }
1101
1102 /**
1103 * Check if stdWrap.replacement and all of its properties work properly
1104 *
1105 * @dataProvider replacementDataProvider
1106 * @test
1107 */
1108 public function replacement($input, $conf, $expected) {
1109 $result = $this->cObj->stdWrap_replacement($input, $conf);
1110 $this->assertEquals($expected, $result);
1111 }
1112
1113 /**
1114 * Data provider for the getQuery test
1115 *
1116 * @return array multi-dimensional array with the second level like this:
1117 * @see getQuery
1118 */
1119 public function getQueryDataProvider() {
1120 $data = array(
1121 'testing empty conf' => array(
1122 'tt_content',
1123 array(),
1124 array(
1125 'SELECT' => '*'
1126 )
1127 ),
1128 'testing #17284: adding uid/pid for workspaces' => array(
1129 'tt_content',
1130 array(
1131 'selectFields' => 'header,bodytext'
1132 ),
1133 array(
1134 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1135 )
1136 ),
1137 'testing #17284: no need to add' => array(
1138 'tt_content',
1139 array(
1140 'selectFields' => 'tt_content.*'
1141 ),
1142 array(
1143 'SELECT' => 'tt_content.*'
1144 )
1145 ),
1146 'testing #17284: no need to add #2' => array(
1147 'tt_content',
1148 array(
1149 'selectFields' => '*'
1150 ),
1151 array(
1152 'SELECT' => '*'
1153 )
1154 ),
1155 'testing #29783: joined tables, prefix tablename' => array(
1156 'tt_content',
1157 array(
1158 'selectFields' => 'tt_content.header,be_users.username',
1159 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1160 ),
1161 array(
1162 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1163 )
1164 ),
1165 'testing #34152: single count(*), add nothing' => array(
1166 'tt_content',
1167 array(
1168 'selectFields' => 'count(*)'
1169 ),
1170 array(
1171 'SELECT' => 'count(*)'
1172 )
1173 ),
1174 'testing #34152: single max(crdate), add nothing' => array(
1175 'tt_content',
1176 array(
1177 'selectFields' => 'max(crdate)'
1178 ),
1179 array(
1180 'SELECT' => 'max(crdate)'
1181 )
1182 ),
1183 'testing #34152: single min(crdate), add nothing' => array(
1184 'tt_content',
1185 array(
1186 'selectFields' => 'min(crdate)'
1187 ),
1188 array(
1189 'SELECT' => 'min(crdate)'
1190 )
1191 ),
1192 'testing #34152: single sum(is_siteroot), add nothing' => array(
1193 'tt_content',
1194 array(
1195 'selectFields' => 'sum(is_siteroot)'
1196 ),
1197 array(
1198 'SELECT' => 'sum(is_siteroot)'
1199 )
1200 ),
1201 'testing #34152: single avg(crdate), add nothing' => array(
1202 'tt_content',
1203 array(
1204 'selectFields' => 'avg(crdate)'
1205 ),
1206 array(
1207 'SELECT' => 'avg(crdate)'
1208 )
1209 )
1210 );
1211 return $data;
1212 }
1213
1214 /**
1215 * Check if sanitizeSelectPart works as expected
1216 *
1217 * @dataProvider getQueryDataProvider
1218 * @test
1219 */
1220 public function getQuery($table, $conf, $expected) {
1221 $result = $this->cObj->getQuery($table, $conf, TRUE);
1222 foreach ($expected as $field => $value) {
1223 $this->assertEquals($value, $result[$field]);
1224 }
1225 }
1226
1227 /**
1228 * Data provider for the stdWrap_strftime test
1229 *
1230 * @return array multi-dimensional array with the second level like this:
1231 * @see stdWrap_strftime
1232 */
1233 public function stdWrap_strftimeReturnsFormattedStringDataProvider() {
1234 $data = array(
1235 'given timestamp' => array(
1236 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1237 array(
1238 'strftime' => '%d-%m-%Y',
1239 ),
1240 ),
1241 'empty string' => array(
1242 '',
1243 array(
1244 'strftime' => '%d-%m-%Y',
1245 ),
1246 ),
1247 'testing null' => array(
1248 NULL,
1249 array(
1250 'strftime' => '%d-%m-%Y',
1251 ),
1252 ),
1253 );
1254 return $data;
1255 }
1256
1257 /**
1258 * @test
1259 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1260 */
1261 public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1262 // Set exec_time to a hard timestamp
1263 $GLOBALS['EXEC_TIME'] = 1346500800;
1264 // Save current timezone and set to UTC to make the system under test behave
1265 // the same in all server timezone settings
1266 $timezoneBackup = date_default_timezone_get();
1267 date_default_timezone_set('UTC');
1268
1269 $result = $this->cObj->stdWrap_strftime($content, $conf);
1270
1271 // Reset timezone
1272 date_default_timezone_set($timezoneBackup);
1273
1274 $this->assertEquals('01-09-2012', $result);
1275 }
1276
1277 /**
1278 * @param string|NULL $content
1279 * @param array $configuration
1280 * @param string $expected
1281 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
1282 * @test
1283 */
1284 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1285 $result = $this->cObj->stdWrap_ifNull($content, $configuration);
1286 $this->assertEquals($expected, $result);
1287 }
1288
1289 /**
1290 * Data provider for stdWrap_ifNullDeterminesNullValues test
1291 *
1292 * @return array
1293 */
1294 public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
1295 return array(
1296 'null value' => array(
1297 NULL,
1298 array(
1299 'ifNull' => '1',
1300 ),
1301 '1',
1302 ),
1303 'zero value' => array(
1304 '0',
1305 array(
1306 'ifNull' => '1',
1307 ),
1308 '0',
1309 ),
1310 );
1311 }
1312
1313 /**
1314 * @param $content
1315 * @param array $configuration
1316 * @param $expected
1317 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
1318 * @test
1319 */
1320 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1321 $result = $this->cObj->stdWrap_noTrimWrap($content, $configuration);
1322 $this->assertEquals($expected, $result);
1323 }
1324
1325 /**
1326 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
1327 *
1328 * @return array
1329 */
1330 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
1331 return array(
1332 'No char given' => array(
1333 'middle',
1334 array(
1335 'noTrimWrap' => '| left | right |',
1336 ),
1337 ' left middle right '
1338 ),
1339 'Zero char given' => array(
1340 'middle',
1341 array(
1342 'noTrimWrap' => '0 left 0 right 0',
1343 'noTrimWrap.' => array('splitChar' => '0'),
1344
1345 ),
1346 ' left middle right '
1347 ),
1348 'Default char given' => array(
1349 'middle',
1350 array(
1351 'noTrimWrap' => '| left | right |',
1352 'noTrimWrap.' => array('splitChar' => '|'),
1353 ),
1354 ' left middle right '
1355 ),
1356 'Split char is a' => array(
1357 'middle',
1358 array(
1359 'noTrimWrap' => 'a left a right a',
1360 'noTrimWrap.' => array('splitChar' => 'a'),
1361 ),
1362 ' left middle right '
1363 ),
1364 'Split char is multi-char (ab)' => array(
1365 'middle',
1366 array(
1367 'noTrimWrap' => 'ab left ab right ab',
1368 'noTrimWrap.' => array('splitChar' => 'ab'),
1369 ),
1370 ' left middle right '
1371 ),
1372 'Split char accepts stdWrap' => array(
1373 'middle',
1374 array(
1375 'noTrimWrap' => 'abc left abc right abc',
1376 'noTrimWrap.' => array(
1377 'splitChar' => 'b',
1378 'splitChar.' => array('wrap' => 'a|c'),
1379 ),
1380 ),
1381 ' left middle right '
1382 ),
1383 );
1384 }
1385
1386 /**
1387 * @param array $expectedTags
1388 * @param array $configuration
1389 * @test
1390 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
1391 */
1392 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
1393 $this->cObj->stdWrap_addPageCacheTags('', $configuration);
1394 $this->assertEquals($expectedTags, $this->tsfe->_get('pageCacheTags'));
1395 }
1396
1397 /**
1398 * @return array
1399 */
1400 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
1401 return array(
1402 'No Tag' => array(
1403 array(),
1404 array('addPageCacheTags' => ''),
1405 ),
1406 'Two expectedTags' => array(
1407 array('tag1', 'tag2'),
1408 array('addPageCacheTags' => 'tag1,tag2'),
1409 ),
1410 'Two expectedTags plus one with stdWrap' => array(
1411 array('tag1', 'tag2', 'tag3'),
1412 array(
1413 'addPageCacheTags' => 'tag1,tag2',
1414 'addPageCacheTags.' => array('wrap' => '|,tag3')
1415 ),
1416 ),
1417 );
1418 }
1419
1420
1421 /////////////////////////////
1422 // Tests concerning getData()
1423 /////////////////////////////
1424
1425 /**
1426 * @return array
1427 */
1428 public function getDataWithTypeGpDataProvider() {
1429 return array(
1430 'Value in get-data' => array('onlyInGet', 'GetValue'),
1431 'Value in post-data' => array('onlyInPost', 'PostValue'),
1432 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
1433 );
1434 }
1435
1436 /**
1437 * Checks if getData() works with type "gp"
1438 *
1439 * @test
1440 * @dataProvider getDataWithTypeGpDataProvider
1441 */
1442 public function getDataWithTypeGp($key, $expectedValue) {
1443 $_GET = array(
1444 'onlyInGet' => 'GetValue',
1445 'inGetAndPost' => 'ValueInGet',
1446 );
1447 $_POST = array(
1448 'onlyInPost' => 'PostValue',
1449 'inGetAndPost' => 'ValueInPost',
1450 );
1451 $this->assertEquals($expectedValue, $this->cObj->getData('gp:' . $key));
1452 }
1453
1454 /**
1455 * Checks if getData() works with type "tsfe"
1456 *
1457 * @test
1458 */
1459 public function getDataWithTypeTsfe() {
1460 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('tsfe:renderCharset'));
1461 }
1462
1463 /**
1464 * Checks if getData() works with type "getenv"
1465 *
1466 * @test
1467 */
1468 public function getDataWithTypeGetenv() {
1469 $envName = uniqid('frontendtest');
1470 $value = uniqid('someValue');
1471 putenv($envName . '=' . $value);
1472 $this->assertEquals($value, $this->cObj->getData('getenv:' . $envName));
1473 }
1474
1475 /**
1476 * Checks if getData() works with type "getindpenv"
1477 *
1478 * @test
1479 */
1480 public function getDataWithTypeGetindpenv() {
1481 $this->assertEquals(PATH_thisScript, $this->cObj->getData('getindpenv:SCRIPT_FILENAME'));
1482 }
1483
1484 /**
1485 * Checks if getData() works with type "getindpenv"
1486 *
1487 * @test
1488 */
1489 public function getDataWithTypeField() {
1490 $key = 'someKey';
1491 $value = 'someValue';
1492 $field = array($key => $value);
1493
1494 $this->assertEquals($value, $this->cObj->getData('field:' . $key, $field));
1495 }
1496
1497 /**
1498 * Checks if getData() works with type "file"
1499 *
1500 * @test
1501 */
1502 public function getDataWithTypeFile() {
1503 $uid = rand();
1504 $properties = array(
1505 uniqid() => uniqid(),
1506 uniqid() => uniqid(),
1507 'uid' => $uid
1508 );
1509 $file = new \TYPO3\CMS\Core\Resource\File($properties);
1510 $this->cObj->setCurrentFile($file);
1511
1512 $this->assertEquals($uid, $this->cObj->getData('file:current:uid'));
1513 }
1514
1515 /**
1516 * Checks if getData() works with type "parameters"
1517 *
1518 * @test
1519 */
1520 public function getDataWithTypeParameters() {
1521 $key = uniqid('someKey');
1522 $value = uniqid('someValue');
1523 $this->cObj->parameters[$key] = $value;
1524
1525 $this->assertEquals($value, $this->cObj->getData('parameters:' . $key));
1526 }
1527
1528 /**
1529 * Checks if getData() works with type "register"
1530 *
1531 * @test
1532 */
1533 public function getDataWithTypeRegister() {
1534 $key = uniqid('someKey');
1535 $value = uniqid('someValue');
1536 $GLOBALS['TSFE']->register[$key] = $value;
1537
1538 $this->assertEquals($value, $this->cObj->getData('register:' . $key));
1539 }
1540
1541 /**
1542 * Checks if getData() works with type "level"
1543 *
1544 * @test
1545 */
1546 public function getDataWithTypeLevel() {
1547 $rootline = array(
1548 0 => array('uid' => 1, 'title' => 'title1'),
1549 1 => array('uid' => 2, 'title' => 'title2'),
1550 2 => array('uid' => 3, 'title' => 'title3'),
1551 );
1552
1553 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1554 $this->assertEquals(2, $this->cObj->getData('level'));
1555 }
1556
1557 /**
1558 * Checks if getData() works with type "global"
1559 *
1560 * @test
1561 */
1562 public function getDataWithTypeGlobal() {
1563 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->cObj->getData('global:TSFE|renderCharset'));
1564 }
1565
1566 /**
1567 * Checks if getData() works with type "leveltitle"
1568 *
1569 * @test
1570 */
1571 public function getDataWithTypeLeveltitle() {
1572 $rootline = array(
1573 0 => array('uid' => 1, 'title' => 'title1'),
1574 1 => array('uid' => 2, 'title' => 'title2'),
1575 2 => array('uid' => 3, 'title' => ''),
1576 );
1577
1578 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1579 $this->assertEquals('', $this->cObj->getData('leveltitle:-1'));
1580 // since "title3" is not set, it will slide to "title2"
1581 $this->assertEquals('title2', $this->cObj->getData('leveltitle:-1,slide'));
1582 }
1583
1584 /**
1585 * Checks if getData() works with type "levelmedia"
1586 *
1587 * @test
1588 */
1589 public function getDataWithTypeLevelmedia() {
1590 $rootline = array(
1591 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
1592 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
1593 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
1594 );
1595
1596 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1597 $this->assertEquals('', $this->cObj->getData('levelmedia:-1'));
1598 // since "title3" is not set, it will slide to "title2"
1599 $this->assertEquals('media2', $this->cObj->getData('levelmedia:-1,slide'));
1600 }
1601
1602 /**
1603 * Checks if getData() works with type "leveluid"
1604 *
1605 * @test
1606 */
1607 public function getDataWithTypeLeveluid() {
1608 $rootline = array(
1609 0 => array('uid' => 1, 'title' => 'title1'),
1610 1 => array('uid' => 2, 'title' => 'title2'),
1611 2 => array('uid' => 3, 'title' => 'title3'),
1612 );
1613
1614 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1615 $this->assertEquals(3, $this->cObj->getData('leveluid:-1'));
1616 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
1617 $this->assertEquals(3, $this->cObj->getData('leveluid:-1,slide'));
1618 }
1619
1620 /**
1621 * Checks if getData() works with type "levelfield"
1622 *
1623 * @test
1624 */
1625 public function getDataWithTypeLevelfield() {
1626 $rootline = array(
1627 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1628 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1629 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
1630 );
1631
1632 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1633 $this->assertEquals('', $this->cObj->getData('levelfield:-1,testfield'));
1634 $this->assertEquals('field2', $this->cObj->getData('levelfield:-1,testfield,slide'));
1635 }
1636
1637 /**
1638 * Checks if getData() works with type "fullrootline"
1639 *
1640 * @test
1641 */
1642 public function getDataWithTypeFullrootline() {
1643 $rootline1 = array(
1644 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1645 );
1646 $rootline2 = array(
1647 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
1648 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
1649 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
1650 );
1651
1652 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
1653 $GLOBALS['TSFE']->rootLine = $rootline2;
1654 $this->assertEquals('field2', $this->cObj->getData('fullrootline:-1,testfield'));
1655 }
1656
1657 /**
1658 * Checks if getData() works with type "date"
1659 *
1660 * @test
1661 */
1662 public function getDataWithTypeDate() {
1663 $format = 'Y-M-D';
1664 $defaultFormat = 'd/m Y';
1665
1666 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date:' . $format));
1667 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->cObj->getData('date'));
1668 }
1669
1670 /**
1671 * Checks if getData() works with type "page"
1672 *
1673 * @test
1674 */
1675 public function getDataWithTypePage() {
1676 $uid = rand();
1677 $GLOBALS['TSFE']->page['uid'] = $uid;
1678 $this->assertEquals($uid, $this->cObj->getData('page:uid'));
1679 }
1680
1681 /**
1682 * Checks if getData() works with type "current"
1683 *
1684 * @test
1685 */
1686 public function getDataWithTypeCurrent() {
1687 $key = uniqid('someKey');
1688 $value = uniqid('someValue');
1689 $this->cObj->data[$key] = $value;
1690 $this->cObj->currentValKey = $key;
1691 $this->assertEquals($value, $this->cObj->getData('current'));
1692 }
1693
1694 /**
1695 * Checks if getData() works with type "db"
1696 *
1697 * @test
1698 */
1699 public function getDataWithTypeDb() {
1700 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
1701
1702 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
1703 $this->assertEquals($dummyRecord['title'], $this->cObj->getData('db:tt_content:106:title'));
1704 }
1705
1706 /**
1707 * Checks if getData() works with type "lll"
1708 *
1709 * @test
1710 */
1711 public function getDataWithTypeLll() {
1712 $key = uniqid('someKey');
1713 $value = uniqid('someValue');
1714 $language = uniqid('someLanguage');
1715 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
1716 $GLOBALS['TSFE']->lang = $language;
1717
1718 $this->assertEquals($value, $this->cObj->getData('lll:' . $key));
1719 }
1720
1721 /**
1722 * Checks if getData() works with type "path"
1723 *
1724 * @test
1725 */
1726 public function getDataWithTypePath() {
1727 $filenameIn = uniqid('someValue');
1728 $filenameOut = uniqid('someValue');
1729 $this->template->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
1730 $this->assertEquals($filenameOut, $this->cObj->getData('path:' . $filenameIn));
1731 }
1732
1733 /**
1734 * Checks if getData() works with type "parentRecordNumber"
1735 *
1736 * @test
1737 */
1738 public function getDataWithTypeParentRecordNumber() {
1739 $recordNumber = rand();
1740 $this->cObj->parentRecordNumber = $recordNumber;
1741 $this->assertEquals($recordNumber, $this->cObj->getData('cobj:parentRecordNumber'));
1742 }
1743
1744 /**
1745 * Checks if getData() works with type "debug:rootLine"
1746 *
1747 * @test
1748 */
1749 public function getDataWithTypeDebugRootline() {
1750 $rootline = array(
1751 0 => array('uid' => 1, 'title' => 'title1'),
1752 1 => array('uid' => 2, 'title' => 'title2'),
1753 2 => array('uid' => 3, 'title' => ''),
1754 );
1755 $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
1756 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
1757
1758 $result = $this->cObj->getData('debug:rootLine');
1759 $cleanedResult = strip_tags($result);
1760 $cleanedResult = str_replace("\r", '', $cleanedResult);
1761 $cleanedResult = str_replace("\n", '', $cleanedResult);
1762 $cleanedResult = str_replace("\t", '', $cleanedResult);
1763 $cleanedResult = str_replace(' ', '', $cleanedResult);
1764
1765 $this->assertEquals($expectedResult, $cleanedResult);
1766 }
1767
1768 /**
1769 * Checks if getData() works with type "debug:fullRootLine"
1770 *
1771 * @test
1772 */
1773 public function getDataWithTypeDebugFullRootline() {
1774 $rootline = array(
1775 0 => array('uid' => 1, 'title' => 'title1'),
1776 1 => array('uid' => 2, 'title' => 'title2'),
1777 2 => array('uid' => 3, 'title' => ''),
1778 );
1779 $expectedResult = '0uid1titletitle11uid2titletitle22uid3title';
1780 $GLOBALS['TSFE']->rootLine = $rootline;
1781
1782 $result = $this->cObj->getData('debug:fullRootLine');
1783 $cleanedResult = strip_tags($result);
1784 $cleanedResult = str_replace("\r", '', $cleanedResult);
1785 $cleanedResult = str_replace("\n", '', $cleanedResult);
1786 $cleanedResult = str_replace("\t", '', $cleanedResult);
1787 $cleanedResult = str_replace(' ', '', $cleanedResult);
1788
1789 $this->assertEquals($expectedResult, $cleanedResult);
1790 }
1791
1792 /**
1793 * Checks if getData() works with type "debug:data"
1794 *
1795 * @test
1796 */
1797 public function getDataWithTypeDebugData() {
1798 $key = uniqid('someKey');
1799 $value = uniqid('someValue');
1800 $this->cObj->data = array($key => $value);
1801
1802 $expectedResult = $key . $value;
1803
1804 $result = $this->cObj->getData('debug:data');
1805 $cleanedResult = strip_tags($result);
1806 $cleanedResult = str_replace("\r", '', $cleanedResult);
1807 $cleanedResult = str_replace("\n", '', $cleanedResult);
1808 $cleanedResult = str_replace("\t", '', $cleanedResult);
1809 $cleanedResult = str_replace(' ', '', $cleanedResult);
1810
1811 $this->assertEquals($expectedResult, $cleanedResult);
1812 }
1813
1814 /**
1815 * Checks if getData() works with type "debug:register"
1816 *
1817 * @test
1818 */
1819 public function getDataWithTypeDebugRegister() {
1820 $key = uniqid('someKey');
1821 $value = uniqid('someValue');
1822 $GLOBALS['TSFE']->register = array($key => $value);
1823
1824 $expectedResult = $key . $value;
1825
1826 $result = $this->cObj->getData('debug:register');
1827 $cleanedResult = strip_tags($result);
1828 $cleanedResult = str_replace("\r", '', $cleanedResult);
1829 $cleanedResult = str_replace("\n", '', $cleanedResult);
1830 $cleanedResult = str_replace("\t", '', $cleanedResult);
1831 $cleanedResult = str_replace(' ', '', $cleanedResult);
1832
1833 $this->assertEquals($expectedResult, $cleanedResult);
1834 }
1835
1836 /**
1837 * Checks if getData() works with type "data:page"
1838 *
1839 * @test
1840 */
1841 public function getDataWithTypeDebugPage() {
1842 $uid = rand();
1843 $GLOBALS['TSFE']->page = array('uid' => $uid);
1844
1845 $expectedResult = 'uid' . $uid;
1846
1847 $result = $this->cObj->getData('debug:page');
1848 $cleanedResult = strip_tags($result);
1849 $cleanedResult = str_replace("\r", '', $cleanedResult);
1850 $cleanedResult = str_replace("\n", '', $cleanedResult);
1851 $cleanedResult = str_replace("\t", '', $cleanedResult);
1852 $cleanedResult = str_replace(' ', '', $cleanedResult);
1853
1854 $this->assertEquals($expectedResult, $cleanedResult);
1855 }
1856 }
1857
1858 ?>