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