38d4546cc522582ef0aeec730eae7171762c64a7
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / ContentObject / ContentObjectRendererTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Log\LoggerInterface;
18 use TYPO3\CMS\Core\Charset\CharsetConverter;
19 use TYPO3\CMS\Core\Core\ApplicationContext;
20 use TYPO3\CMS\Core\Log\LogManager;
21 use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
22 use TYPO3\CMS\Core\TypoScript\TemplateService;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
25 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
26 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
27 use TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Fixtures\PageRepositoryFixture;
28
29 /**
30 * Testcase for TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
31 */
32 class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
33 {
34 /**
35 * @var string
36 */
37 protected $currentLocale;
38
39 /**
40 * @var array A backup of registered singleton instances
41 */
42 protected $singletonInstances = array();
43
44 /**
45 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
46 */
47 protected $subject = null;
48
49 /**
50 * @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
51 */
52 protected $typoScriptFrontendControllerMock = null;
53
54 /**
55 * @var \PHPUnit_Framework_MockObject_MockObject|TemplateService
56 */
57 protected $templateServiceMock = null;
58
59 /**
60 * Default content object name -> class name map, shipped with TYPO3 CMS
61 *
62 * @var array
63 */
64 protected $contentObjectMap = array(
65 'TEXT' => \TYPO3\CMS\Frontend\ContentObject\TextContentObject::class,
66 'CASE' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject::class,
67 'COBJ_ARRAY' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject::class,
68 'COA' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject::class,
69 'COA_INT' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayInternalContentObject::class,
70 'USER' => \TYPO3\CMS\Frontend\ContentObject\UserContentObject::class,
71 'USER_INT' => \TYPO3\CMS\Frontend\ContentObject\UserInternalContentObject::class,
72 'FILE' => \TYPO3\CMS\Frontend\ContentObject\FileContentObject::class,
73 'FILES' => \TYPO3\CMS\Frontend\ContentObject\FilesContentObject::class,
74 'IMAGE' => \TYPO3\CMS\Frontend\ContentObject\ImageContentObject::class,
75 'IMG_RESOURCE' => \TYPO3\CMS\Frontend\ContentObject\ImageResourceContentObject::class,
76 'CONTENT' => \TYPO3\CMS\Frontend\ContentObject\ContentContentObject::class,
77 'RECORDS' => \TYPO3\CMS\Frontend\ContentObject\RecordsContentObject::class,
78 'HMENU' => \TYPO3\CMS\Frontend\ContentObject\HierarchicalMenuContentObject::class,
79 'CASEFUNC' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject::class,
80 'LOAD_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\LoadRegisterContentObject::class,
81 'RESTORE_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\RestoreRegisterContentObject::class,
82 'TEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\TemplateContentObject::class,
83 'FLUIDTEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject::class,
84 'SVG' => \TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject::class,
85 'EDITPANEL' => \TYPO3\CMS\Frontend\ContentObject\EditPanelContentObject::class
86 );
87
88 /**
89 * Set up
90 */
91 protected function setUp()
92 {
93 $this->currentLocale = setlocale(LC_NUMERIC, 0);
94
95 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
96 $this->createMockedLoggerAndLogManager();
97
98 $this->templateServiceMock = $this->getMock(TemplateService::class, array('getFileName', 'linkData'));
99 $pageRepositoryMock = $this->getMock(PageRepositoryFixture::class, array('getRawRecord'));
100
101 $this->typoScriptFrontendControllerMock = $this->getAccessibleMock(TypoScriptFrontendController::class, array('dummy'), array(), '', false);
102 $this->typoScriptFrontendControllerMock->tmpl = $this->templateServiceMock;
103 $this->typoScriptFrontendControllerMock->config = array();
104 $this->typoScriptFrontendControllerMock->page = array();
105 $this->typoScriptFrontendControllerMock->sys_page = $pageRepositoryMock;
106 $this->typoScriptFrontendControllerMock->csConvObj = new CharsetConverter();
107 $this->typoScriptFrontendControllerMock->renderCharset = 'utf-8';
108 $GLOBALS['TSFE'] = $this->typoScriptFrontendControllerMock;
109 $GLOBALS['TT'] = new NullTimeTracker();
110 $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array());
111 $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring';
112
113 $this->subject = $this->getAccessibleMock(
114 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
115 array('getResourceFactory', 'getEnvironmentVariable'),
116 array($this->typoScriptFrontendControllerMock)
117 );
118 $this->subject->setContentObjectClassMap($this->contentObjectMap);
119 $this->subject->start(array(), 'tt_content');
120 }
121
122 protected function tearDown()
123 {
124 setlocale(LC_NUMERIC, $this->currentLocale);
125 GeneralUtility::resetSingletonInstances($this->singletonInstances);
126 parent::tearDown();
127 }
128
129 //////////////////////
130 // Utility functions
131 //////////////////////
132
133 /**
134 * Avoid logging to the file system (file writer is currently the only configured writer)
135 */
136 protected function createMockedLoggerAndLogManager()
137 {
138 $logManagerMock = $this->getMock(LogManager::class);
139 $loggerMock = $this->getMock(LoggerInterface::class);
140 $logManagerMock->expects($this->any())
141 ->method('getLogger')
142 ->willReturn($loggerMock);
143 GeneralUtility::setSingletonInstance(LogManager::class, $logManagerMock);
144 }
145
146 /**
147 * Converts the subject and the expected result into the target charset.
148 *
149 * @param string $charset the target charset
150 * @param string $subject the subject, will be modified
151 * @param string $expected the expected result, will be modified
152 */
153 protected function handleCharset($charset, &$subject, &$expected)
154 {
155 $GLOBALS['TSFE']->renderCharset = $charset;
156 $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset);
157 $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset);
158 }
159
160 /////////////////////////////////////////////
161 // Tests concerning the getImgResource hook
162 /////////////////////////////////////////////
163 /**
164 * @test
165 */
166 public function getImgResourceCallsGetImgResourcePostProcessHook()
167 {
168 $this->templateServiceMock
169 ->expects($this->atLeastOnce())
170 ->method('getFileName')
171 ->with('typo3/clear.gif')
172 ->will($this->returnValue('typo3/clear.gif'));
173
174 $resourceFactory = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceFactory::class, array(), array(), '', false);
175 $this->subject->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
176
177 $className = $this->getUniqueId('tx_coretest');
178 $getImgResourceHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectGetImageResourceHookInterface::class, array('getImgResourcePostProcess'), array(), $className);
179 $getImgResourceHookMock
180 ->expects($this->once())
181 ->method('getImgResourcePostProcess')
182 ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
183 $getImgResourceHookObjects = array($getImgResourceHookMock);
184 $this->subject->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
185 $this->subject->getImgResource('typo3/clear.gif', array());
186 }
187
188 /**
189 * Handles the arguments that have been sent to the getImgResource hook.
190 *
191 * @return array
192 * @see getImgResourceHookGetsCalled
193 */
194 public function isGetImgResourceHookCalledCallback()
195 {
196 list($file, $fileArray, $imageResource, $parent) = func_get_args();
197 $this->assertEquals('typo3/clear.gif', $file);
198 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
199 $this->assertTrue(is_array($fileArray));
200 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer);
201 return $imageResource;
202 }
203
204 //////////////////////////////////////
205 // Tests concerning getContentObject
206 //////////////////////////////////////
207
208 public function getContentObjectValidContentObjectsDataProvider()
209 {
210 $dataProvider = array();
211 foreach ($this->contentObjectMap as $name => $className) {
212 $dataProvider[] = array($name, $className);
213 }
214 return $dataProvider;
215 }
216
217 /**
218 * @test
219 * @dataProvider getContentObjectValidContentObjectsDataProvider
220 * @param string $name TypoScript name of content object
221 * @param string $fullClassName Expected class name
222 */
223 public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $fullClassName)
224 {
225 $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', false);
226 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($fullClassName, $contentObjectInstance);
227 $this->assertSame($contentObjectInstance, $this->subject->getContentObject($name));
228 }
229
230 /////////////////////////////////////////
231 // Tests concerning getQueryArguments()
232 /////////////////////////////////////////
233 /**
234 * @test
235 */
236 public function getQueryArgumentsExcludesParameters()
237 {
238 $this->subject->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
239 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
240 );
241 $getQueryArgumentsConfiguration = array();
242 $getQueryArgumentsConfiguration['exclude'] = array();
243 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
244 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
245 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
246 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
247 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
248 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration);
249 $this->assertEquals($expectedResult, $actualResult);
250 }
251
252 /**
253 * @test
254 */
255 public function getQueryArgumentsExcludesGetParameters()
256 {
257 $_GET = array(
258 'key1' => 'value1',
259 'key2' => 'value2',
260 'key3' => array(
261 'key31' => 'value31',
262 'key32' => array(
263 'key321' => 'value321',
264 'key322' => 'value322'
265 )
266 )
267 );
268 $getQueryArgumentsConfiguration = array();
269 $getQueryArgumentsConfiguration['method'] = 'GET';
270 $getQueryArgumentsConfiguration['exclude'] = array();
271 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
272 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
273 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
274 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
275 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
276 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration);
277 $this->assertEquals($expectedResult, $actualResult);
278 }
279
280 /**
281 * @test
282 */
283 public function getQueryArgumentsOverrulesSingleParameter()
284 {
285 $this->subject->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
286 $this->returnValue('key1=value1')
287 );
288 $getQueryArgumentsConfiguration = array();
289 $overruleArguments = array(
290 // Should be overridden
291 'key1' => 'value1Overruled',
292 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
293 'key2' => 'value2Overruled'
294 );
295 $expectedResult = '&key1=value1Overruled';
296 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
297 $this->assertEquals($expectedResult, $actualResult);
298 }
299
300 /**
301 * @test
302 */
303 public function getQueryArgumentsOverrulesMultiDimensionalParameters()
304 {
305 $_POST = array(
306 'key1' => 'value1',
307 'key2' => 'value2',
308 'key3' => array(
309 'key31' => 'value31',
310 'key32' => array(
311 'key321' => 'value321',
312 'key322' => 'value322'
313 )
314 )
315 );
316 $getQueryArgumentsConfiguration = array();
317 $getQueryArgumentsConfiguration['method'] = 'POST';
318 $getQueryArgumentsConfiguration['exclude'] = array();
319 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
320 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
321 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
322 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
323 $overruleArguments = array(
324 // Should be overriden
325 'key2' => 'value2Overruled',
326 'key3' => array(
327 'key32' => array(
328 // Shouldn't be set: Parameter is excluded and not forced
329 'key321' => 'value321Overruled',
330 // Should be overriden: Parameter is not excluded
331 'key322' => 'value322Overruled',
332 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
333 'key323' => 'value323Overruled'
334 )
335 )
336 );
337 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
338 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
339 $this->assertEquals($expectedResult, $actualResult);
340 }
341
342 /**
343 * @test
344 */
345 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters()
346 {
347 $this->subject->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
348 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
349 );
350 $_POST = array(
351 'key1' => 'value1',
352 'key2' => 'value2',
353 'key3' => array(
354 'key31' => 'value31',
355 'key32' => array(
356 'key321' => 'value321',
357 'key322' => 'value322'
358 )
359 )
360 );
361 $getQueryArgumentsConfiguration = array();
362 $getQueryArgumentsConfiguration['exclude'] = array();
363 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
364 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
365 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
366 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
367 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
368 $overruleArguments = array(
369 // Should be overriden
370 'key2' => 'value2Overruled',
371 'key3' => array(
372 'key32' => array(
373 // Should be set: Parameter is excluded but forced
374 'key321' => 'value321Overruled',
375 // Should be set: Parameter doesn't exist in source array but is forced
376 'key323' => 'value323Overruled'
377 )
378 )
379 );
380 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
381 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, true);
382 $this->assertEquals($expectedResult, $actualResult);
383 $getQueryArgumentsConfiguration['method'] = 'POST';
384 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, true);
385 $this->assertEquals($expectedResult, $actualResult);
386 }
387
388 /**
389 * @test
390 */
391 public function getQueryArgumentsWithMethodPostGetMergesParameters()
392 {
393 $_POST = array(
394 'key1' => 'POST1',
395 'key2' => 'POST2',
396 'key3' => array(
397 'key31' => 'POST31',
398 'key32' => 'POST32',
399 'key33' => array(
400 'key331' => 'POST331',
401 'key332' => 'POST332',
402 )
403 )
404 );
405 $_GET = array(
406 'key2' => 'GET2',
407 'key3' => array(
408 'key32' => 'GET32',
409 'key33' => array(
410 'key331' => 'GET331',
411 )
412 )
413 );
414 $getQueryArgumentsConfiguration = array();
415 $getQueryArgumentsConfiguration['method'] = 'POST,GET';
416 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
417 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration);
418 $this->assertEquals($expectedResult, $actualResult);
419 }
420
421 /**
422 * @test
423 */
424 public function getQueryArgumentsWithMethodGetPostMergesParameters()
425 {
426 $_GET = array(
427 'key1' => 'GET1',
428 'key2' => 'GET2',
429 'key3' => array(
430 'key31' => 'GET31',
431 'key32' => 'GET32',
432 'key33' => array(
433 'key331' => 'GET331',
434 'key332' => 'GET332',
435 )
436 )
437 );
438 $_POST = array(
439 'key2' => 'POST2',
440 'key3' => array(
441 'key32' => 'POST32',
442 'key33' => array(
443 'key331' => 'POST331',
444 )
445 )
446 );
447 $getQueryArgumentsConfiguration = array();
448 $getQueryArgumentsConfiguration['method'] = 'GET,POST';
449 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
450 $actualResult = $this->subject->getQueryArguments($getQueryArgumentsConfiguration);
451 $this->assertEquals($expectedResult, $actualResult);
452 }
453
454 /**
455 * Encodes square brackets in URL.
456 *
457 * @param string $string
458 * @return string
459 */
460 private function rawUrlEncodeSquareBracketsInUrl($string)
461 {
462 return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
463 }
464
465 //////////////////////////
466 // Tests concerning crop
467 //////////////////////////
468 /**
469 * @test
470 */
471 public function cropIsMultibyteSafe()
472 {
473 $this->assertEquals('бла', $this->subject->crop('бла', '3|...'));
474 }
475
476 //////////////////////////////
477 // Tests concerning cropHTML
478 //////////////////////////////
479 /**
480 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
481 * of charset, text type, and configuration options to be tested.
482 *
483 * @return array two-dimensional array with the second level like this:
484 * @see cropHtmlWithDataProvider
485 */
486 public function cropHtmlDataProvider()
487 {
488 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
489 $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.';
490 $textWithEntities = 'Kasper Sk&aring;rh&oslash;j implemented the; original ' . 'version of the crop function.';
491 $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
492 $data = array();
493 foreach ($charsets as $charset) {
494 $data = array_merge($data, array(
495 $charset . ' plain text; 11|...' => array(
496 '11|...',
497 $plainText,
498 'Kasper Sk' . chr(229) . 'r...',
499 $charset
500 ),
501 $charset . ' plain text; -58|...' => array(
502 '-58|...',
503 $plainText,
504 '...h' . chr(248) . 'j implemented the original version of the crop function.',
505 $charset
506 ),
507 $charset . ' plain text; 4|...|1' => array(
508 '4|...|1',
509 $plainText,
510 'Kasp...',
511 $charset
512 ),
513 $charset . ' plain text; 20|...|1' => array(
514 '20|...|1',
515 $plainText,
516 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...',
517 $charset
518 ),
519 $charset . ' plain text; -5|...|1' => array(
520 '-5|...|1',
521 $plainText,
522 '...tion.',
523 $charset
524 ),
525 $charset . ' plain text; -49|...|1' => array(
526 '-49|...|1',
527 $plainText,
528 '...the original version of the crop function.',
529 $charset
530 ),
531 $charset . ' text with markup; 11|...' => array(
532 '11|...',
533 $textWithMarkup,
534 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>',
535 $charset
536 ),
537 $charset . ' text with markup; 13|...' => array(
538 '13|...',
539 $textWithMarkup,
540 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>',
541 $charset
542 ),
543 $charset . ' text with markup; 14|...' => array(
544 '14|...',
545 $textWithMarkup,
546 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
547 $charset
548 ),
549 $charset . ' text with markup; 15|...' => array(
550 '15|...',
551 $textWithMarkup,
552 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>',
553 $charset
554 ),
555 $charset . ' text with markup; 29|...' => array(
556 '29|...',
557 $textWithMarkup,
558 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...',
559 $charset
560 ),
561 $charset . ' text with markup; -58|...' => array(
562 '-58|...',
563 $textWithMarkup,
564 '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
565 $charset
566 ),
567 $charset . ' text with markup 4|...|1' => array(
568 '4|...|1',
569 $textWithMarkup,
570 '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>',
571 $charset
572 ),
573 $charset . ' text with markup; 11|...|1' => array(
574 '11|...|1',
575 $textWithMarkup,
576 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
577 $charset
578 ),
579 $charset . ' text with markup; 13|...|1' => array(
580 '13|...|1',
581 $textWithMarkup,
582 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
583 $charset
584 ),
585 $charset . ' text with markup; 14|...|1' => array(
586 '14|...|1',
587 $textWithMarkup,
588 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
589 $charset
590 ),
591 $charset . ' text with markup; 15|...|1' => array(
592 '15|...|1',
593 $textWithMarkup,
594 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
595 $charset
596 ),
597 $charset . ' text with markup; 29|...|1' => array(
598 '29|...|1',
599 $textWithMarkup,
600 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...',
601 $charset
602 ),
603 $charset . ' text with markup; -66|...|1' => array(
604 '-66|...|1',
605 $textWithMarkup,
606 '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
607 $charset
608 ),
609 $charset . ' text with entities 9|...' => array(
610 '9|...',
611 $textWithEntities,
612 'Kasper Sk...',
613 $charset
614 ),
615 $charset . ' text with entities 10|...' => array(
616 '10|...',
617 $textWithEntities,
618 'Kasper Sk&aring;...',
619 $charset
620 ),
621 $charset . ' text with entities 11|...' => array(
622 '11|...',
623 $textWithEntities,
624 'Kasper Sk&aring;r...',
625 $charset
626 ),
627 $charset . ' text with entities 13|...' => array(
628 '13|...',
629 $textWithEntities,
630 'Kasper Sk&aring;rh&oslash;...',
631 $charset
632 ),
633 $charset . ' text with entities 14|...' => array(
634 '14|...',
635 $textWithEntities,
636 'Kasper Sk&aring;rh&oslash;j...',
637 $charset
638 ),
639 $charset . ' text with entities 15|...' => array(
640 '15|...',
641 $textWithEntities,
642 'Kasper Sk&aring;rh&oslash;j ...',
643 $charset
644 ),
645 $charset . ' text with entities 16|...' => array(
646 '16|...',
647 $textWithEntities,
648 'Kasper Sk&aring;rh&oslash;j i...',
649 $charset
650 ),
651 $charset . ' text with entities -57|...' => array(
652 '-57|...',
653 $textWithEntities,
654 '...j implemented the; original version of the crop function.',
655 $charset
656 ),
657 $charset . ' text with entities -58|...' => array(
658 '-58|...',
659 $textWithEntities,
660 '...&oslash;j implemented the; original version of the crop function.',
661 $charset
662 ),
663 $charset . ' text with entities -59|...' => array(
664 '-59|...',
665 $textWithEntities,
666 '...h&oslash;j implemented the; original version of the crop function.',
667 $charset
668 ),
669 $charset . ' text with entities 4|...|1' => array(
670 '4|...|1',
671 $textWithEntities,
672 'Kasp...',
673 $charset
674 ),
675 $charset . ' text with entities 9|...|1' => array(
676 '9|...|1',
677 $textWithEntities,
678 'Kasper...',
679 $charset
680 ),
681 $charset . ' text with entities 10|...|1' => array(
682 '10|...|1',
683 $textWithEntities,
684 'Kasper...',
685 $charset
686 ),
687 $charset . ' text with entities 11|...|1' => array(
688 '11|...|1',
689 $textWithEntities,
690 'Kasper...',
691 $charset
692 ),
693 $charset . ' text with entities 13|...|1' => array(
694 '13|...|1',
695 $textWithEntities,
696 'Kasper...',
697 $charset
698 ),
699 $charset . ' text with entities 14|...|1' => array(
700 '14|...|1',
701 $textWithEntities,
702 'Kasper Sk&aring;rh&oslash;j...',
703 $charset
704 ),
705 $charset . ' text with entities 15|...|1' => array(
706 '15|...|1',
707 $textWithEntities,
708 'Kasper Sk&aring;rh&oslash;j...',
709 $charset
710 ),
711 $charset . ' text with entities 16|...|1' => array(
712 '16|...|1',
713 $textWithEntities,
714 'Kasper Sk&aring;rh&oslash;j...',
715 $charset
716 ),
717 $charset . ' text with entities -57|...|1' => array(
718 '-57|...|1',
719 $textWithEntities,
720 '...implemented the; original version of the crop function.',
721 $charset
722 ),
723 $charset . ' text with entities -58|...|1' => array(
724 '-58|...|1',
725 $textWithEntities,
726 '...implemented the; original version of the crop function.',
727 $charset
728 ),
729 $charset . ' text with entities -59|...|1' => array(
730 '-59|...|1',
731 $textWithEntities,
732 '...implemented the; original version of the crop function.',
733 $charset
734 ),
735 $charset . ' text with dash in html-element 28|...|1' => array(
736 '28|...|1',
737 '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',
738 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>',
739 $charset
740 ),
741 $charset . ' html elements with dashes in attributes' => array(
742 '9',
743 '<em data-foo="x">foobar</em>foobaz',
744 '<em data-foo="x">foobar</em>foo',
745 $charset
746 ),
747 $charset . ' html elements with iframe embedded 24|...|1' => array(
748 '24|...|1',
749 'Text with iframe <iframe src="//what.ever/"></iframe> and text after it',
750 'Text with iframe <iframe src="//what.ever/"></iframe> and...',
751 $charset
752 ),
753 $charset . ' html elements with script tag embedded 24|...|1' => array(
754 '24|...|1',
755 'Text with script <script>alert(\'foo\');</script> and text after it',
756 'Text with script <script>alert(\'foo\');</script> and...',
757 $charset
758 ),
759 ));
760 }
761 return $data;
762 }
763
764 /**
765 * Checks if stdWrap.cropHTML works with plain text cropping from left
766 *
767 * @test
768 * @dataProvider cropHtmlDataProvider
769 * @param string $settings
770 * @param string $subject the string to crop
771 * @param string $expected the expected cropped result
772 * @param string $charset the charset that will be set as renderCharset
773 */
774 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset)
775 {
776 $this->handleCharset($charset, $subject, $expected);
777 $this->assertEquals($expected, $this->subject->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"');
778 }
779
780 /**
781 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
782 * counts multiple invisible characters not as one (as the browser will output the content).
783 *
784 * @test
785 */
786 public function cropHtmlWorksWithComplexContent()
787 {
788 $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
789 $input =
790 '<h1>Blog Example</h1>' . LF .
791 '<hr>' . LF .
792 '<div class="csc-header csc-header-n1">' . LF .
793 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF .
794 '</div>' . LF .
795 '<p class="bodytext">' . LF .
796 ' 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>.' . LF .
797 '</p>' . LF .
798 '<div class="tx-blogexample-list-container">' . LF .
799 ' <p class="bodytext">' . LF .
800 ' Below are the most recent posts:' . LF .
801 ' </p>' . LF .
802 ' <ul>' . LF .
803 ' <li data-element="someId">' . LF .
804 ' <h3>' . LF .
805 ' <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>' . LF .
806 ' </h3>' . LF .
807 ' <p class="bodytext">' . LF .
808 ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...' . LF .
809 ' </p>' . LF .
810 ' <p class="metadata">' . LF .
811 ' Published on 26.08.2009 by Jochen Rau' . LF .
812 ' </p>' . LF .
813 ' <p>' . LF .
814 ' Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>' . LF .
815 ' <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>' . LF .
816 ' <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>' . LF .
817 ' </p>' . LF .
818 ' </li>' . LF .
819 ' </ul>' . LF .
820 ' <p>' . LF .
821 ' <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>' . LF .
822 ' </p>' . LF .
823 '</div>' . LF .
824 '<hr>' . LF .
825 '<p>' . LF .
826 ' ? TYPO3 Association' . LF .
827 '</p>';
828
829 $result = $this->subject->cropHTML($input, '300');
830
831 $expected =
832 '<h1>Blog Example</h1>' . LF .
833 '<hr>' . LF .
834 '<div class="csc-header csc-header-n1">' . LF .
835 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF .
836 '</div>' . LF .
837 '<p class="bodytext">' . LF .
838 ' 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>.' . LF .
839 '</p>' . LF .
840 '<div class="tx-blogexample-list-container">' . LF .
841 ' <p class="bodytext">' . LF .
842 ' Below are the most recent posts:' . LF .
843 ' </p>' . LF .
844 ' <ul>' . LF .
845 ' <li data-element="someId">' . LF .
846 ' <h3>' . LF .
847 ' <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</a></h3></li></ul></div>';
848
849 $this->assertEquals($expected, $result);
850
851 $result = $this->subject->cropHTML($input, '-100');
852
853 $expected =
854 '<div class="tx-blogexample-list-container"><ul><li data-element="someId"><p> Design]&nbsp;<br>' . LF .
855 ' <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>' . LF .
856 ' <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>' . LF .
857 ' </p>' . LF .
858 ' </li>' . LF .
859 ' </ul>' . LF .
860 ' <p>' . LF .
861 ' <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>' . LF .
862 ' </p>' . LF .
863 '</div>' . LF .
864 '<hr>' . LF .
865 '<p>' . LF .
866 ' ? TYPO3 Association' . LF .
867 '</p>';
868
869 $this->assertEquals($expected, $result);
870 }
871
872 /**
873 * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
874 *
875 * @test
876 */
877 public function cropHtmlWorksWithLinebreaks()
878 {
879 $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
880 $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
881 $result = $this->subject->cropHTML($subject, '121');
882 $this->assertEquals($expected, $result);
883 }
884
885 /**
886 * @return array
887 */
888 public function stdWrap_roundDataProvider()
889 {
890 return array(
891 'rounding off without any configuration' => array(
892 1.123456789,
893 array(),
894 1
895 ),
896 'rounding up without any configuration' => array(
897 1.523456789,
898 array(),
899 2
900 ),
901 'regular rounding (off) to two decimals' => array(
902 0.123456789,
903 array(
904 'decimals' => 2
905 ),
906 0.12
907 ),
908 'regular rounding (up) to two decimals' => array(
909 0.1256789,
910 array(
911 'decimals' => 2
912 ),
913 0.13
914 ),
915 'rounding up to integer with type ceil' => array(
916 0.123456789,
917 array(
918 'roundType' => 'ceil'
919 ),
920 1
921 ),
922 'rounding down to integer with type floor' => array(
923 2.3481,
924 array(
925 'roundType' => 'floor'
926 ),
927 2
928 )
929 );
930 }
931
932 /**
933 * Test for the stdWrap function "round"
934 *
935 * @param float $float
936 * @param array $conf
937 * @param float $expected
938 * @return void
939 * @dataProvider stdWrap_roundDataProvider
940 * @test
941 */
942 public function stdWrap_round($float, $conf, $expected)
943 {
944 $conf = array(
945 'round.' => $conf
946 );
947 $result = $this->subject->stdWrap_round($float, $conf);
948 $this->assertEquals($expected, $result);
949 }
950
951 /**
952 * @return array
953 */
954 public function stdWrap_numberFormatDataProvider()
955 {
956 return array(
957 'testing decimals' => array(
958 0.8,
959 array(
960 'numberFormat.' => array(
961 'decimals' => 2
962 ),
963 ),
964 '0.80'
965 ),
966 'testing decimals with input as string' => array(
967 '0.8',
968 array(
969 'numberFormat.' => array(
970 'decimals' => 2
971 ),
972 ),
973 '0.80'
974 ),
975 'testing dec_point' => array(
976 0.8,
977 array(
978 'numberFormat.' => array(
979 'decimals' => 1,
980 'dec_point' => ','
981 ),
982 ),
983 '0,8'
984 ),
985 'testing thousands_sep' => array(
986 999.99,
987 array(
988 'numberFormat.' => array(
989 'decimals' => 0,
990 'thousands_sep.' => array(
991 'char' => 46
992 ),
993 ),
994 ),
995 '1.000'
996 ),
997 'testing mixture' => array(
998 1281731.45,
999 array(
1000 'numberFormat.' => array(
1001 'decimals' => 1,
1002 'dec_point.' => array(
1003 'char' => 44
1004 ),
1005 'thousands_sep.' => array(
1006 'char' => 46
1007 ),
1008 ),
1009 ),
1010 '1.281.731,5'
1011 )
1012 );
1013 }
1014
1015 /**
1016 * Test for the stdWrap function "round"
1017 *
1018 * @param float $float
1019 * @param array $conf
1020 * @param string $expected
1021 * @return void
1022 * @dataProvider stdWrap_numberFormatDataProvider
1023 * @test
1024 */
1025 public function stdWrap_numberFormat($float, $conf, $expected)
1026 {
1027 $result = $this->subject->stdWrap_numberFormat($float, $conf);
1028 $this->assertEquals($expected, $result);
1029 }
1030
1031 /**
1032 * @return array
1033 */
1034 public function stdWrap_expandListDataProvider()
1035 {
1036 return array(
1037 'numbers' => array(
1038 '1,2,3',
1039 '1,2,3',
1040 ),
1041 'range' => array(
1042 '3-5',
1043 '3,4,5',
1044 ),
1045 'numbers and range' => array(
1046 '1,3-5,7',
1047 '1,3,4,5,7',
1048 ),
1049 );
1050 }
1051
1052 /**
1053 * Test for the stdWrap function "expandList"
1054 *
1055 * @param string $content
1056 * @param string $expected
1057 *
1058 * @dataProvider stdWrap_expandListDataProvider
1059 * @test
1060 */
1061 public function stdWrap_expandList($content, $expected)
1062 {
1063 $result = $this->subject->stdWrap_expandList($content);
1064 $this->assertEquals($expected, $result);
1065 }
1066
1067 /**
1068 * @return array
1069 */
1070 public function stdWrap_trimDataProvider()
1071 {
1072 return array(
1073 'trimstring' => array(
1074 'trimstring',
1075 'trimstring',
1076 ),
1077 'trim string with space inside' => array(
1078 'trim string',
1079 'trim string',
1080 ),
1081 'trim string with space at the begin and end' => array(
1082 ' trim string ',
1083 'trim string',
1084 ),
1085 );
1086 }
1087
1088 /**
1089 * Test for the stdWrap function "trim"
1090 *
1091 * @param string $content
1092 * @param string $expected
1093 *
1094 * @dataProvider stdWrap_trimDataProvider
1095 * @test
1096 */
1097 public function stdWrap_trim($content, $expected)
1098 {
1099 $result = $this->subject->stdWrap_trim($content);
1100 $this->assertEquals($expected, $result);
1101 }
1102
1103 /**
1104 * @return array
1105 */
1106 public function stdWrap_intvalDataProvider()
1107 {
1108 return array(
1109 'number' => array(
1110 '123',
1111 123,
1112 ),
1113 'float' => array(
1114 '123.45',
1115 123,
1116 ),
1117 'string' => array(
1118 'string',
1119 0,
1120 ),
1121 'zero' => array(
1122 '0',
1123 0,
1124 ),
1125 'empty' => array(
1126 '',
1127 0,
1128 ),
1129 'NULL' => array(
1130 null,
1131 0,
1132 ),
1133 'bool TRUE' => array(
1134 true,
1135 1,
1136 ),
1137 'bool FALSE' => array(
1138 false,
1139 0,
1140 ),
1141 );
1142 }
1143
1144 /**
1145 * Test for the stdWrap function "intval"
1146 *
1147 * @param string $content
1148 * @param int $expected
1149 *
1150 * @dataProvider stdWrap_intvalDataProvider
1151 * @test
1152 */
1153 public function stdWrap_intval($content, $expected)
1154 {
1155 $result = $this->subject->stdWrap_intval($content);
1156 $this->assertEquals($expected, $result);
1157 }
1158
1159 /**
1160 * @return array
1161 */
1162 public function stdWrap_strPadDataProvider()
1163 {
1164 return array(
1165 'pad string with default settings and length 10' => array(
1166 'Alien',
1167 array(
1168 'length' => '10',
1169 ),
1170 'Alien ',
1171 ),
1172 'pad string with padWith -= and type left and length 10' => array(
1173 'Alien',
1174 array(
1175 'length' => '10',
1176 'padWith' => '-=',
1177 'type' => 'left',
1178 ),
1179 '-=-=-Alien',
1180 ),
1181 'pad string with padWith _ and type both and length 10' => array(
1182 'Alien',
1183 array(
1184 'length' => '10',
1185 'padWith' => '_',
1186 'type' => 'both',
1187 ),
1188 '__Alien___',
1189 ),
1190 'pad string with padWith 0 and type both and length 10' => array(
1191 'Alien',
1192 array(
1193 'length' => '10',
1194 'padWith' => '0',
1195 'type' => 'both',
1196 ),
1197 '00Alien000',
1198 ),
1199 'pad string with padWith ___ and type both and length 6' => array(
1200 'Alien',
1201 array(
1202 'length' => '6',
1203 'padWith' => '___',
1204 'type' => 'both',
1205 ),
1206 'Alien_',
1207 ),
1208 'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
1209 'Alien',
1210 array(
1211 'length' => '1',
1212 'length.' => array(
1213 'wrap' => '|2',
1214 ),
1215 'padWith' => '_',
1216 'type' => 'both',
1217 ),
1218 '___Alien____',
1219 ),
1220 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
1221 'Alien',
1222 array(
1223 'length' => '12',
1224 'padWith' => '_',
1225 'padWith.' => array(
1226 'wrap' => '-|=',
1227 ),
1228 'type' => 'both',
1229 ),
1230 '-_=Alien-_=-',
1231 ),
1232 'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
1233 'Alien',
1234 array(
1235 'length' => '12',
1236 'padWith' => '_',
1237 'type' => 'both',
1238 // make type become "left"
1239 'type.' => array(
1240 'substring' => '2,1',
1241 'wrap' => 'lef|',
1242 ),
1243 ),
1244 '_______Alien',
1245 ),
1246 );
1247 }
1248
1249 /**
1250 * Test for the stdWrap function "strPad"
1251 *
1252 * @param string $content
1253 * @param array $conf
1254 * @param string $expected
1255 *
1256 * @dataProvider stdWrap_strPadDataProvider
1257 * @test
1258 */
1259 public function stdWrap_strPad($content, $conf, $expected)
1260 {
1261 $conf = array(
1262 'strPad.' => $conf
1263 );
1264 $result = $this->subject->stdWrap_strPad($content, $conf);
1265 $this->assertEquals($expected, $result);
1266 }
1267
1268 /**
1269 * Data provider for the hash test
1270 *
1271 * @return array multi-dimensional array with the second level like this:
1272 * @see hash
1273 */
1274 public function hashDataProvider()
1275 {
1276 $data = array(
1277 'testing md5' => array(
1278 'joh316',
1279 array(
1280 'hash' => 'md5'
1281 ),
1282 'bacb98acf97e0b6112b1d1b650b84971'
1283 ),
1284 'testing sha1' => array(
1285 'joh316',
1286 array(
1287 'hash' => 'sha1'
1288 ),
1289 '063b3d108bed9f88fa618c6046de0dccadcf3158'
1290 ),
1291 'testing non-existing hashing algorithm' => array(
1292 'joh316',
1293 array(
1294 'hash' => 'non-existing'
1295 ),
1296 ''
1297 ),
1298 'testing stdWrap capability' => array(
1299 'joh316',
1300 array(
1301 'hash.' => array(
1302 'cObject' => 'TEXT',
1303 'cObject.' => array(
1304 'value' => 'md5'
1305 )
1306 )
1307 ),
1308 'bacb98acf97e0b6112b1d1b650b84971'
1309 )
1310 );
1311 return $data;
1312 }
1313
1314 /**
1315 * Test for the stdWrap function "hash"
1316 *
1317 * @param string $text
1318 * @param array $conf
1319 * @param string $expected
1320 * @return void
1321 * @dataProvider hashDataProvider
1322 * @test
1323 */
1324 public function stdWrap_hash($text, array $conf, $expected)
1325 {
1326 $result = $this->subject->stdWrap_hash($text, $conf);
1327 $this->assertEquals($expected, $result);
1328 }
1329
1330 /**
1331 * @test
1332 */
1333 public function recursiveStdWrapProperlyRendersBasicString()
1334 {
1335 $stdWrapConfiguration = array(
1336 'noTrimWrap' => '|| 123|',
1337 'stdWrap.' => array(
1338 'wrap' => '<b>|</b>'
1339 )
1340 );
1341 $this->assertSame(
1342 '<b>Test</b> 123',
1343 $this->subject->stdWrap('Test', $stdWrapConfiguration)
1344 );
1345 }
1346
1347 /**
1348 * @test
1349 */
1350 public function recursiveStdWrapIsOnlyCalledOnce()
1351 {
1352 $stdWrapConfiguration = array(
1353 'append' => 'TEXT',
1354 'append.' => array(
1355 'data' => 'register:Counter'
1356 ),
1357 'stdWrap.' => array(
1358 'append' => 'LOAD_REGISTER',
1359 'append.' => array(
1360 'Counter.' => array(
1361 'prioriCalc' => 'intval',
1362 'cObject' => 'TEXT',
1363 'cObject.' => array(
1364 'data' => 'register:Counter',
1365 'wrap' => '|+1',
1366 )
1367 )
1368 )
1369 )
1370 );
1371 $this->assertSame(
1372 'Counter:1',
1373 $this->subject->stdWrap('Counter:', $stdWrapConfiguration)
1374 );
1375 }
1376
1377 /**
1378 * Data provider for the numberFormat test
1379 *
1380 * @return array multi-dimensional array with the second level like this:
1381 * @see numberFormat
1382 */
1383 public function numberFormatDataProvider()
1384 {
1385 $data = array(
1386 'testing decimals' => array(
1387 0.8,
1388 array(
1389 'decimals' => 2
1390 ),
1391 '0.80'
1392 ),
1393 'testing decimals with input as string' => array(
1394 '0.8',
1395 array(
1396 'decimals' => 2
1397 ),
1398 '0.80'
1399 ),
1400 'testing dec_point' => array(
1401 0.8,
1402 array(
1403 'decimals' => 1,
1404 'dec_point' => ','
1405 ),
1406 '0,8'
1407 ),
1408 'testing thousands_sep' => array(
1409 999.99,
1410 array(
1411 'decimals' => 0,
1412 'thousands_sep.' => array(
1413 'char' => 46
1414 )
1415 ),
1416 '1.000'
1417 ),
1418 'testing mixture' => array(
1419 1281731.45,
1420 array(
1421 'decimals' => 1,
1422 'dec_point.' => array(
1423 'char' => 44
1424 ),
1425 'thousands_sep.' => array(
1426 'char' => 46
1427 )
1428 ),
1429 '1.281.731,5'
1430 )
1431 );
1432 return $data;
1433 }
1434
1435 /**
1436 * Check if stdWrap.numberFormat and all of its properties work properly
1437 *
1438 * @dataProvider numberFormatDataProvider
1439 * @test
1440 */
1441 public function numberFormat($float, $formatConf, $expected)
1442 {
1443 $result = $this->subject->numberFormat($float, $formatConf);
1444 $this->assertEquals($expected, $result);
1445 }
1446
1447 /**
1448 * Data provider for the replacement test
1449 *
1450 * @return array multi-dimensional array with the second level like this:
1451 * @see replacement
1452 */
1453 public function replacementDataProvider()
1454 {
1455 $data = array(
1456 'multiple replacements, including regex' => array(
1457 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1458 array(
1459 'replacement.' => array(
1460 '120.' => array(
1461 'search' => 'in da hood',
1462 'replace' => 'around the block'
1463 ),
1464 '20.' => array(
1465 'search' => '_',
1466 'replace.' => array('char' => '32')
1467 ),
1468 '130.' => array(
1469 'search' => '#a (Cat|Dog|Tiger)#i',
1470 'replace' => 'an animal',
1471 'useRegExp' => '1'
1472 )
1473 )
1474 ),
1475 'There is an animal, an animal and an animal around the block! Yeah!'
1476 ),
1477 'replacement with optionSplit, normal pattern' => array(
1478 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1479 array(
1480 'replacement.' => array(
1481 '10.' => array(
1482 'search' => '_',
1483 'replace' => '1 || 2 || 3',
1484 'useOptionSplitReplace' => '1'
1485 ),
1486 )
1487 ),
1488 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1489 ),
1490 'replacement with optionSplit, using regex' => array(
1491 'There is a cat, a dog and a tiger in da hood! Yeah!',
1492 array(
1493 'replacement.' => array(
1494 '10.' => array(
1495 'search' => '#(a) (Cat|Dog|Tiger)#i',
1496 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1497 'useOptionSplitReplace' => '1',
1498 'useRegExp' => '1'
1499 )
1500 )
1501 ),
1502 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1503 ),
1504 );
1505 return $data;
1506 }
1507
1508 /**
1509 * Check if stdWrap.replacement and all of its properties work properly
1510 *
1511 * @dataProvider replacementDataProvider
1512 * @test
1513 */
1514 public function replacement($input, $conf, $expected)
1515 {
1516 $result = $this->subject->stdWrap_replacement($input, $conf);
1517 $this->assertEquals($expected, $result);
1518 }
1519
1520 /**
1521 * Data provider for the getQuery test
1522 *
1523 * @return array multi-dimensional array with the second level like this:
1524 * @see getQuery
1525 */
1526 public function getQueryDataProvider()
1527 {
1528 $data = array(
1529 'testing empty conf' => array(
1530 'tt_content',
1531 array(),
1532 array(
1533 'SELECT' => '*'
1534 )
1535 ),
1536 'testing #17284: adding uid/pid for workspaces' => array(
1537 'tt_content',
1538 array(
1539 'selectFields' => 'header,bodytext'
1540 ),
1541 array(
1542 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1543 )
1544 ),
1545 'testing #17284: no need to add' => array(
1546 'tt_content',
1547 array(
1548 'selectFields' => 'tt_content.*'
1549 ),
1550 array(
1551 'SELECT' => 'tt_content.*'
1552 )
1553 ),
1554 'testing #17284: no need to add #2' => array(
1555 'tt_content',
1556 array(
1557 'selectFields' => '*'
1558 ),
1559 array(
1560 'SELECT' => '*'
1561 )
1562 ),
1563 'testing #29783: joined tables, prefix tablename' => array(
1564 'tt_content',
1565 array(
1566 'selectFields' => 'tt_content.header,be_users.username',
1567 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1568 ),
1569 array(
1570 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1571 )
1572 ),
1573 'testing #34152: single count(*), add nothing' => array(
1574 'tt_content',
1575 array(
1576 'selectFields' => 'count(*)'
1577 ),
1578 array(
1579 'SELECT' => 'count(*)'
1580 )
1581 ),
1582 'testing #34152: single max(crdate), add nothing' => array(
1583 'tt_content',
1584 array(
1585 'selectFields' => 'max(crdate)'
1586 ),
1587 array(
1588 'SELECT' => 'max(crdate)'
1589 )
1590 ),
1591 'testing #34152: single min(crdate), add nothing' => array(
1592 'tt_content',
1593 array(
1594 'selectFields' => 'min(crdate)'
1595 ),
1596 array(
1597 'SELECT' => 'min(crdate)'
1598 )
1599 ),
1600 'testing #34152: single sum(is_siteroot), add nothing' => array(
1601 'tt_content',
1602 array(
1603 'selectFields' => 'sum(is_siteroot)'
1604 ),
1605 array(
1606 'SELECT' => 'sum(is_siteroot)'
1607 )
1608 ),
1609 'testing #34152: single avg(crdate), add nothing' => array(
1610 'tt_content',
1611 array(
1612 'selectFields' => 'avg(crdate)'
1613 ),
1614 array(
1615 'SELECT' => 'avg(crdate)'
1616 )
1617 )
1618 );
1619 return $data;
1620 }
1621
1622 /**
1623 * Check if sanitizeSelectPart works as expected
1624 *
1625 * @dataProvider getQueryDataProvider
1626 * @test
1627 */
1628 public function getQuery($table, $conf, $expected)
1629 {
1630 $GLOBALS['TCA'] = array(
1631 'pages' => array(
1632 'ctrl' => array(
1633 'enablecolumns' => array(
1634 'disabled' => 'hidden'
1635 )
1636 )
1637 ),
1638 'tt_content' => array(
1639 'ctrl' => array(
1640 'enablecolumns' => array(
1641 'disabled' => 'hidden'
1642 ),
1643 'versioningWS' => true
1644 )
1645 ),
1646 );
1647 $result = $this->subject->getQuery($table, $conf, true);
1648 foreach ($expected as $field => $value) {
1649 $this->assertEquals($value, $result[$field]);
1650 }
1651 }
1652
1653 /**
1654 * @test
1655 */
1656 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet()
1657 {
1658 $GLOBALS['TCA'] = array(
1659 'pages' => array(
1660 'ctrl' => array(
1661 'enablecolumns' => array(
1662 'disabled' => 'hidden'
1663 )
1664 )
1665 ),
1666 'tt_content' => array(
1667 'ctrl' => array(
1668 'enablecolumns' => array(
1669 'disabled' => 'hidden'
1670 )
1671 )
1672 ),
1673 );
1674 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array('getTreeList'));
1675 $this->subject->start(array(), 'tt_content');
1676 $conf = array(
1677 'recursive' => '15',
1678 'pidInList' => '16, -35'
1679 );
1680 $this->subject->expects($this->at(0))
1681 ->method('getTreeList')
1682 ->with(-16, 15)
1683 ->will($this->returnValue('15,16'));
1684 $this->subject->expects($this->at(1))
1685 ->method('getTreeList')
1686 ->with(-35, 15)
1687 ->will($this->returnValue('15,35'));
1688 $this->subject->getQuery('tt_content', $conf, true);
1689 }
1690
1691 /**
1692 * @test
1693 */
1694 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet()
1695 {
1696 $GLOBALS['TCA'] = array(
1697 'pages' => array(
1698 'ctrl' => array(
1699 'enablecolumns' => array(
1700 'disabled' => 'hidden'
1701 )
1702 )
1703 ),
1704 'tt_content' => array(
1705 'ctrl' => array(
1706 'enablecolumns' => array(
1707 'disabled' => 'hidden'
1708 )
1709 )
1710 ),
1711 );
1712 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array('getTreeList'));
1713 $GLOBALS['TSFE']->id = 27;
1714 $this->subject->start(array(), 'tt_content');
1715 $conf = array(
1716 'pidInList' => 'this',
1717 'recursive' => '4'
1718 );
1719 $this->subject->expects($this->once())
1720 ->method('getTreeList')
1721 ->with(-27)
1722 ->will($this->returnValue('27'));
1723 $this->subject->getQuery('tt_content', $conf, true);
1724 }
1725
1726 /**
1727 * Data provider for the stdWrap_date test
1728 *
1729 * @return array multi-dimensional array with the second level like this:
1730 * @see stdWrap_date
1731 */
1732 public function stdWrap_dateDataProvider()
1733 {
1734 return array(
1735 'given timestamp' => array(
1736 1443780000, // This is 2015-10-02 12:00
1737 array(
1738 'date' => 'd.m.Y',
1739 ),
1740 '02.10.2015',
1741 ),
1742 'empty string' => array(
1743 '',
1744 array(
1745 'date' => 'd.m.Y',
1746 ),
1747 '02.10.2015',
1748 ),
1749 'testing null' => array(
1750 null,
1751 array(
1752 'date' => 'd.m.Y',
1753 ),
1754 '02.10.2015',
1755 ),
1756 'given timestamp return GMT' => array(
1757 1443780000, // This is 2015-10-02 12:00
1758 array(
1759 'date' => 'd.m.Y H:i:s',
1760 'date.' => array(
1761 'GMT' => true,
1762 )
1763 ),
1764 '02.10.2015 10:00:00',
1765 ),
1766 );
1767 }
1768
1769 /**
1770 * @test
1771 * @dataProvider stdWrap_dateDataProvider
1772 * @param string|int|NULL $content
1773 * @param array $conf
1774 * @param string $expected
1775 */
1776 public function stdWrap_date($content, $conf, $expected)
1777 {
1778 // Set exec_time to a hard timestamp
1779 $GLOBALS['EXEC_TIME'] = 1443780000;
1780
1781 $result = $this->subject->stdWrap_date($content, $conf);
1782
1783 $this->assertEquals($expected, $result);
1784 }
1785
1786 /**
1787 * Data provider for the stdWrap_strftime test
1788 *
1789 * @return array multi-dimensional array with the second level like this:
1790 * @see stdWrap_strftime
1791 */
1792 public function stdWrap_strftimeReturnsFormattedStringDataProvider()
1793 {
1794 $data = array(
1795 'given timestamp' => array(
1796 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1797 array(
1798 'strftime' => '%d-%m-%Y',
1799 ),
1800 ),
1801 'empty string' => array(
1802 '',
1803 array(
1804 'strftime' => '%d-%m-%Y',
1805 ),
1806 ),
1807 'testing null' => array(
1808 null,
1809 array(
1810 'strftime' => '%d-%m-%Y',
1811 ),
1812 ),
1813 );
1814 return $data;
1815 }
1816
1817 /**
1818 * @test
1819 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1820 */
1821 public function stdWrap_strftimeReturnsFormattedString($content, $conf)
1822 {
1823 // Set exec_time to a hard timestamp
1824 $GLOBALS['EXEC_TIME'] = 1346500800;
1825 // Save current timezone and set to UTC to make the system under test behave
1826 // the same in all server timezone settings
1827 $timezoneBackup = date_default_timezone_get();
1828 date_default_timezone_set('UTC');
1829
1830 $result = $this->subject->stdWrap_strftime($content, $conf);
1831
1832 // Reset timezone
1833 date_default_timezone_set($timezoneBackup);
1834
1835 $this->assertEquals('01-09-2012', $result);
1836 }
1837
1838 /**
1839 * Data provider for the stdWrap_strtotime test
1840 *
1841 * @return array
1842 * @see stdWrap_strtotime
1843 */
1844 public function stdWrap_strtotimeReturnsTimestampDataProvider()
1845 {
1846 return array(
1847 'date from content' => array(
1848 '2014-12-04',
1849 array(
1850 'strtotime' => '1',
1851 ),
1852 1417651200,
1853 ),
1854 'manipulation of date from content' => array(
1855 '2014-12-04',
1856 array(
1857 'strtotime' => '+ 2 weekdays',
1858 ),
1859 1417996800,
1860 ),
1861 'date from configuration' => array(
1862 '',
1863 array(
1864 'strtotime' => '2014-12-04',
1865 ),
1866 1417651200,
1867 ),
1868 'manipulation of date from configuration' => array(
1869 '',
1870 array(
1871 'strtotime' => '2014-12-04 + 2 weekdays',
1872 ),
1873 1417996800,
1874 ),
1875 'empty input' => array(
1876 '',
1877 array(
1878 'strtotime' => '1',
1879 ),
1880 false,
1881 ),
1882 'date from content and configuration' => array(
1883 '2014-12-04',
1884 array(
1885 'strtotime' => '2014-12-05',
1886 ),
1887 false,
1888 ),
1889 );
1890 }
1891
1892 /**
1893 * @param string|NULL $content
1894 * @param array $configuration
1895 * @param int $expected
1896 * @dataProvider stdWrap_strtotimeReturnsTimestampDataProvider
1897 * @test
1898 */
1899 public function stdWrap_strtotimeReturnsTimestamp($content, $configuration, $expected)
1900 {
1901 // Set exec_time to a hard timestamp
1902 $GLOBALS['EXEC_TIME'] = 1417392000;
1903 // Save current timezone and set to UTC to make the system under test behave
1904 // the same in all server timezone settings
1905 $timezoneBackup = date_default_timezone_get();
1906 date_default_timezone_set('UTC');
1907
1908 $result = $this->subject->stdWrap_strtotime($content, $configuration);
1909
1910 // Reset timezone
1911 date_default_timezone_set($timezoneBackup);
1912
1913 $this->assertEquals($expected, $result);
1914 }
1915
1916 /**
1917 * @test
1918 */
1919 public function stdWrap_ageCallsCalcAgeWithSubtractedTimestampAndSubPartOfArray()
1920 {
1921 $subject = $this->getMock(
1922 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
1923 array('calcAge')
1924 );
1925 // Set exec_time to a hard timestamp
1926 $GLOBALS['EXEC_TIME'] = 10;
1927 $subject->expects($this->once())->method('calcAge')->with(1, 'Min| Hrs| Days| Yrs');
1928 $subject->stdWrap_age(9, array('age' => 'Min| Hrs| Days| Yrs'));
1929 }
1930
1931 /**
1932 * Data provider for calcAgeCalculatesAgeOfTimestamp
1933 *
1934 * @return array
1935 * @see calcAge
1936 */
1937 public function calcAgeCalculatesAgeOfTimestampDataProvider()
1938 {
1939 return array(
1940 'minutes' => array(
1941 120,
1942 ' min| hrs| days| yrs',
1943 '2 min',
1944 ),
1945 'hours' => array(
1946 7200,
1947 ' min| hrs| days| yrs',
1948 '2 hrs',
1949 ),
1950 'days' => array(
1951 604800,
1952 ' min| hrs| days| yrs',
1953 '7 days',
1954 ),
1955 'day with provided singular labels' => array(
1956 86400,
1957 ' min| hrs| days| yrs| min| hour| day| year',
1958 '1 day',
1959 ),
1960 'years' => array(
1961 1417997800,
1962 ' min| hrs| days| yrs',
1963 '45 yrs',
1964 ),
1965 'different labels' => array(
1966 120,
1967 ' Minutes| Hrs| Days| Yrs',
1968 '2 Minutes',
1969 ),
1970 'negative values' => array(
1971 -604800,
1972 ' min| hrs| days| yrs',
1973 '-7 days',
1974 ),
1975 'default label values for wrong label input' => array(
1976 121,
1977 10,
1978 '2 min',
1979 ),
1980 'default singular label values for wrong label input' => array(
1981 31536000,
1982 10,
1983 '1 year',
1984 )
1985 );
1986 }
1987
1988 /**
1989 * @param int $timestamp
1990 * @param string $labels
1991 * @param int $expectation
1992 * @dataProvider calcAgeCalculatesAgeOfTimestampDataProvider
1993 * @test
1994 */
1995 public function calcAgeCalculatesAgeOfTimestamp($timestamp, $labels, $expectation)
1996 {
1997 $result = $this->subject->calcAge($timestamp, $labels);
1998 $this->assertEquals($result, $expectation);
1999 }
2000
2001 /**
2002 * Data provider for stdWrap_case test
2003 *
2004 * @return array
2005 */
2006 public function stdWrap_caseDataProvider()
2007 {
2008 return array(
2009 'lower case text to upper' => array(
2010 '<span>text</span>',
2011 array(
2012 'case' => 'upper',
2013 ),
2014 '<span>TEXT</span>',
2015 ),
2016 'upper case text to lower' => array(
2017 '<span>TEXT</span>',
2018 array(
2019 'case' => 'lower',
2020 ),
2021 '<span>text</span>',
2022 ),
2023 'capitalize text' => array(
2024 '<span>this is a text</span>',
2025 array(
2026 'case' => 'capitalize',
2027 ),
2028 '<span>This Is A Text</span>',
2029 ),
2030 'ucfirst text' => array(
2031 '<span>this is a text</span>',
2032 array(
2033 'case' => 'ucfirst',
2034 ),
2035 '<span>This is a text</span>',
2036 ),
2037 'lcfirst text' => array(
2038 '<span>This is a Text</span>',
2039 array(
2040 'case' => 'lcfirst',
2041 ),
2042 '<span>this is a Text</span>',
2043 ),
2044 'uppercamelcase text' => array(
2045 '<span>this_is_a_text</span>',
2046 array(
2047 'case' => 'uppercamelcase',
2048 ),
2049 '<span>ThisIsAText</span>',
2050 ),
2051 'lowercamelcase text' => array(
2052 '<span>this_is_a_text</span>',
2053 array(
2054 'case' => 'lowercamelcase',
2055 ),
2056 '<span>thisIsAText</span>',
2057 ),
2058 );
2059 }
2060
2061 /**
2062 * @param string|NULL $content
2063 * @param array $configuration
2064 * @param string $expected
2065 * @dataProvider stdWrap_caseDataProvider
2066 * @test
2067 */
2068 public function stdWrap_case($content, array $configuration, $expected)
2069 {
2070 $result = $this->subject->stdWrap_case($content, $configuration);
2071 $this->assertEquals($expected, $result);
2072 }
2073
2074 /**
2075 * Data provider for stdWrap_bytes test
2076 *
2077 * @return array
2078 */
2079 public function stdWrap_bytesDataProvider()
2080 {
2081 return array(
2082 'value 1234 default' => array(
2083 '1234',
2084 array(
2085 'bytes.' => array(
2086 'labels' => '',
2087 'base' => 0,
2088 ),
2089 ),
2090 '1.21 Ki',
2091 'en_US.UTF-8'
2092 ),
2093 'value 1234 si' => array(
2094 '1234',
2095 array(
2096 'bytes.' => array(
2097 'labels' => 'si',
2098 'base' => 0,
2099 ),
2100 ),
2101 '1.23 k',
2102 'en_US.UTF-8'
2103 ),
2104 'value 1234 iec' => array(
2105 '1234',
2106 array(
2107 'bytes.' => array(
2108 'labels' => 'iec',
2109 'base' => 0,
2110 ),
2111 ),
2112 '1.21 Ki',
2113 'en_US.UTF-8'
2114 ),
2115 'value 1234 a-i' => array(
2116 '1234',
2117 array(
2118 'bytes.' => array(
2119 'labels' => 'a|b|c|d|e|f|g|h|i',
2120 'base' => 1000,
2121 ),
2122 ),
2123 '1.23b',
2124 'en_US.UTF-8'
2125 ),
2126 'value 1234 a-i invalid base' => array(
2127 '1234',
2128 array(
2129 'bytes.' => array(
2130 'labels' => 'a|b|c|d|e|f|g|h|i',
2131 'base' => 54,
2132 ),
2133 ),
2134 '1.21b',
2135 'en_US.UTF-8'
2136 ),
2137 'value 1234567890 default' => array(
2138 '1234567890',
2139 array(
2140 'bytes.' => array(
2141 'labels' => '',
2142 'base' => 0,
2143 ),
2144 ),
2145 '1.15 Gi',
2146 'en_US.UTF-8'
2147 ),
2148 );
2149 }
2150
2151 /**
2152 * @param string|NULL $content
2153 * @param array $configuration
2154 * @param string $expected
2155 * @dataProvider stdWrap_bytesDataProvider
2156 * @test
2157 */
2158 public function stdWrap_bytes($content, array $configuration, $expected, $locale)
2159 {
2160 if (!setlocale(LC_NUMERIC, $locale)) {
2161 $this->markTestSkipped('Locale ' . $locale . ' is not available.');
2162 }
2163 $result = $this->subject->stdWrap_bytes($content, $configuration);
2164 $this->assertSame($expected, $result);
2165 }
2166
2167 /**
2168 * Data provider for stdWrap_substring test
2169 *
2170 * @return array
2171 */
2172 public function stdWrap_substringDataProvider()
2173 {
2174 return array(
2175 'sub -1' => array(
2176 'substring',
2177 array(
2178 'substring' => '-1',
2179 ),
2180 'g',
2181 ),
2182 'sub -1,0' => array(
2183 'substring',
2184 array(
2185 'substring' => '-1,0',
2186 ),
2187 'g',
2188 ),
2189 'sub -1,-1' => array(
2190 'substring',
2191 array(
2192 'substring' => '-1,-1',
2193 ),
2194 '',
2195 ),
2196 'sub -1,1' => array(
2197 'substring',
2198 array(
2199 'substring' => '-1,1',
2200 ),
2201 'g',
2202 ),
2203 'sub 0' => array(
2204 'substring',
2205 array(
2206 'substring' => '0',
2207 ),
2208 'substring',
2209 ),
2210 'sub 0,0' => array(
2211 'substring',
2212 array(
2213 'substring' => '0,0',
2214 ),
2215 'substring',
2216 ),
2217 'sub 0,-1' => array(
2218 'substring',
2219 array(
2220 'substring' => '0,-1',
2221 ),
2222 'substrin',
2223 ),
2224 'sub 0,1' => array(
2225 'substring',
2226 array(
2227 'substring' => '0,1',
2228 ),
2229 's',
2230 ),
2231 'sub 1' => array(
2232 'substring',
2233 array(
2234 'substring' => '1',
2235 ),
2236 'ubstring',
2237 ),
2238 'sub 1,0' => array(
2239 'substring',
2240 array(
2241 'substring' => '1,0',
2242 ),
2243 'ubstring',
2244 ),
2245 'sub 1,-1' => array(
2246 'substring',
2247 array(
2248 'substring' => '1,-1',
2249 ),
2250 'ubstrin',
2251 ),
2252 'sub 1,1' => array(
2253 'substring',
2254 array(
2255 'substring' => '1,1',
2256 ),
2257 'u',
2258 ),
2259 'sub' => array(
2260 'substring',
2261 array(
2262 'substring' => '',
2263 ),
2264 'substring',
2265 ),
2266 );
2267 }
2268
2269 /**
2270 * @param string $content
2271 * @param array $configuration
2272 * @param string $expected
2273 * @dataProvider stdWrap_substringDataProvider
2274 * @test
2275 */
2276 public function stdWrap_substring($content, array $configuration, $expected)
2277 {
2278 $result = $this->subject->stdWrap_substring($content, $configuration);
2279 $this->assertSame($expected, $result);
2280 }
2281
2282 /**
2283 * Data provider for stdWrap_stdWrapValue test
2284 *
2285 * @return array
2286 */
2287 public function stdWrap_stdWrapValueDataProvider()
2288 {
2289 return array(
2290 'only key returns value' => array(
2291 'ifNull',
2292 array(
2293 'ifNull' => '1',
2294 ),
2295 '',
2296 '1',
2297 ),
2298 'array without key returns empty string' => array(
2299 'ifNull',
2300 array(
2301 'ifNull.' => '1',
2302 ),
2303 '',
2304 '',
2305 ),
2306 'array without key returns default' => array(
2307 'ifNull',
2308 array(
2309 'ifNull.' => '1',
2310 ),
2311 'default',
2312 'default',
2313 ),
2314 'non existing key returns default' => array(
2315 'ifNull',
2316 array(
2317 'noTrimWrap' => 'test',
2318 'noTrimWrap.' => '1',
2319 ),
2320 'default',
2321 'default',
2322 ),
2323 'existing key and array returns stdWrap' => array(
2324 'test',
2325 array(
2326 'test' => 'value',
2327 'test.' => array('case' => 'upper'),
2328 ),
2329 'default',
2330 'VALUE'
2331 ),
2332 );
2333 }
2334
2335 /**
2336 * @param string $key
2337 * @param array $configuration
2338 * @param string $defaultValue
2339 * @param string $expected
2340 * @dataProvider stdWrap_stdWrapValueDataProvider
2341 * @test
2342 */
2343 public function stdWrap_stdWrapValue($key, array $configuration, $defaultValue, $expected)
2344 {
2345 $result = $this->subject->stdWrapValue($key, $configuration, $defaultValue);
2346 $this->assertEquals($expected, $result);
2347 }
2348
2349 /**
2350 * @param string|NULL $content
2351 * @param array $configuration
2352 * @param string $expected
2353 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
2354 * @test
2355 */
2356 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected)
2357 {
2358 $result = $this->subject->stdWrap_ifNull($content, $configuration);
2359 $this->assertEquals($expected, $result);
2360 }
2361
2362 /**
2363 * Data provider for stdWrap_ifNullDeterminesNullValues test
2364 *
2365 * @return array
2366 */
2367 public function stdWrap_ifNullDeterminesNullValuesDataProvider()
2368 {
2369 return array(
2370 'null value' => array(
2371 null,
2372 array(
2373 'ifNull' => '1',
2374 ),
2375 '1',
2376 ),
2377 'zero value' => array(
2378 '0',
2379 array(
2380 'ifNull' => '1',
2381 ),
2382 '0',
2383 ),
2384 );
2385 }
2386
2387 /**
2388 * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
2389 *
2390 * @return array
2391 */
2392 public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider()
2393 {
2394 return array(
2395 'null value' => array(
2396 null,
2397 array(
2398 'ifEmpty' => '1',
2399 ),
2400 '1',
2401 ),
2402 'empty value' => array(
2403 '',
2404 array(
2405 'ifEmpty' => '1',
2406 ),
2407 '1',
2408 ),
2409 'string value' => array(
2410 'string',
2411 array(
2412 'ifEmpty' => '1',
2413 ),
2414 'string',
2415 ),
2416 'empty string value' => array(
2417 ' ',
2418 array(
2419 'ifEmpty' => '1',
2420 ),
2421 '1',
2422 ),
2423 );
2424 }
2425
2426 /**
2427 * @param string|NULL $content
2428 * @param array $configuration
2429 * @param string $expected
2430 * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
2431 * @test
2432 */
2433 public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected)
2434 {
2435 $result = $this->subject->stdWrap_ifEmpty($content, $configuration);
2436 $this->assertEquals($expected, $result);
2437 }
2438
2439 /**
2440 * @param $content
2441 * @param array $configuration
2442 * @param $expected
2443 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
2444 * @test
2445 */
2446 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected)
2447 {
2448 $result = $this->subject->stdWrap_noTrimWrap($content, $configuration);
2449 $this->assertEquals($expected, $result);
2450 }
2451
2452 /**
2453 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
2454 *
2455 * @return array
2456 */
2457 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider()
2458 {
2459 return array(
2460 'No char given' => array(
2461 'middle',
2462 array(
2463 'noTrimWrap' => '| left | right |',
2464 ),
2465 ' left middle right '
2466 ),
2467 'Zero char given' => array(
2468 'middle',
2469 array(
2470 'noTrimWrap' => '0 left 0 right 0',
2471 'noTrimWrap.' => array('splitChar' => '0'),
2472
2473 ),
2474 ' left middle right '
2475 ),
2476 'Default char given' => array(
2477 'middle',
2478 array(
2479 'noTrimWrap' => '| left | right |',
2480 'noTrimWrap.' => array('splitChar' => '|'),
2481 ),
2482 ' left middle right '
2483 ),
2484 'Split char is a' => array(
2485 'middle',
2486 array(
2487 'noTrimWrap' => 'a left a right a',
2488 'noTrimWrap.' => array('splitChar' => 'a'),
2489 ),
2490 ' left middle right '
2491 ),
2492 'Split char is multi-char (ab)' => array(
2493 'middle',
2494 array(
2495 'noTrimWrap' => 'ab left ab right ab',
2496 'noTrimWrap.' => array('splitChar' => 'ab'),
2497 ),
2498 ' left middle right '
2499 ),
2500 'Split char accepts stdWrap' => array(
2501 'middle',
2502 array(
2503 'noTrimWrap' => 'abc left abc right abc',
2504 'noTrimWrap.' => array(
2505 'splitChar' => 'b',
2506 'splitChar.' => array('wrap' => 'a|c'),
2507 ),
2508 ),
2509 ' left middle right '
2510 ),
2511 );
2512 }
2513
2514 /**
2515 * @param array $expectedTags
2516 * @param array $configuration
2517 * @test
2518 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
2519 */
2520 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration)
2521 {
2522 $this->subject->stdWrap_addPageCacheTags('', $configuration);
2523 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock->_get('pageCacheTags'));
2524 }
2525
2526 /**
2527 * @return array
2528 */
2529 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider()
2530 {
2531 return array(
2532 'No Tag' => array(
2533 array(),
2534 array('addPageCacheTags' => ''),
2535 ),
2536 'Two expectedTags' => array(
2537 array('tag1', 'tag2'),
2538 array('addPageCacheTags' => 'tag1,tag2'),
2539 ),
2540 'Two expectedTags plus one with stdWrap' => array(
2541 array('tag1', 'tag2', 'tag3'),
2542 array(
2543 'addPageCacheTags' => 'tag1,tag2',
2544 'addPageCacheTags.' => array('wrap' => '|,tag3')
2545 ),
2546 ),
2547 );
2548 }
2549
2550 /**
2551 * Data provider for stdWrap_encodeForJavaScriptValue test
2552 *
2553 * @return array multi-dimensional array with the second level like this:
2554 * @see encodeForJavaScriptValue
2555 */
2556 public function stdWrap_encodeForJavaScriptValueDataProvider()
2557 {
2558 return array(
2559 'double quote in string' => array(
2560 'double quote"',
2561 array(),
2562 '\'double\u0020quote\u0022\''
2563 ),
2564 'backslash in string' => array(
2565 'backslash \\',
2566 array(),
2567 '\'backslash\u0020\u005C\''
2568 ),
2569 'exclamation mark' => array(
2570 'exclamation!',
2571 array(),
2572 '\'exclamation\u0021\''
2573 ),
2574 'whitespace tab, newline and carriage return' => array(
2575 "white\tspace\ns\r",
2576 array(),
2577 '\'white\u0009space\u000As\u000D\''
2578 ),
2579 'single quote in string' => array(
2580 'single quote \'',
2581 array(),
2582 '\'single\u0020quote\u0020\u0027\''
2583 ),
2584 'tag' => array(
2585 '<tag>',
2586 array(),
2587 '\'\u003Ctag\u003E\''
2588 ),
2589 'ampersand in string' => array(
2590 'amper&sand',
2591 array(),
2592 '\'amper\u0026sand\''
2593 ),
2594 );
2595 }
2596
2597 /**
2598 * Check if encodeForJavaScriptValue works properly
2599 *
2600 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
2601 * @test
2602 */
2603 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected)
2604 {
2605 $result = $this->subject->stdWrap_encodeForJavaScriptValue($input, $conf);
2606 $this->assertEquals($expected, $result);
2607 }
2608
2609 ///////////////////////////////
2610 // Tests concerning getData()
2611 ///////////////////////////////
2612
2613 /**
2614 * @return array
2615 */
2616 public function getDataWithTypeGpDataProvider()
2617 {
2618 return array(
2619 'Value in get-data' => array('onlyInGet', 'GetValue'),
2620 'Value in post-data' => array('onlyInPost', 'PostValue'),
2621 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
2622 );
2623 }
2624
2625 /**
2626 * Checks if getData() works with type "gp"
2627 *
2628 * @test
2629 * @dataProvider getDataWithTypeGpDataProvider
2630 */
2631 public function getDataWithTypeGp($key, $expectedValue)
2632 {
2633 $_GET = array(
2634 'onlyInGet' => 'GetValue',
2635 'inGetAndPost' => 'ValueInGet',
2636 );
2637 $_POST = array(
2638 'onlyInPost' => 'PostValue',
2639 'inGetAndPost' => 'ValueInPost',
2640 );
2641 $this->assertEquals($expectedValue, $this->subject->getData('gp:' . $key));
2642 }
2643
2644 /**
2645 * Checks if getData() works with type "tsfe"
2646 *
2647 * @test
2648 */
2649 public function getDataWithTypeTsfe()
2650 {
2651 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('tsfe:renderCharset'));
2652 }
2653
2654 /**
2655 * Checks if getData() works with type "getenv"
2656 *
2657 * @test
2658 */
2659 public function getDataWithTypeGetenv()
2660 {
2661 $envName = $this->getUniqueId('frontendtest');
2662 $value = $this->getUniqueId('someValue');
2663 putenv($envName . '=' . $value);
2664 $this->assertEquals($value, $this->subject->getData('getenv:' . $envName));
2665 }
2666
2667 /**
2668 * Checks if getData() works with type "getindpenv"
2669 *
2670 * @test
2671 */
2672 public function getDataWithTypeGetindpenv()
2673 {
2674 $this->subject->expects($this->once())->method('getEnvironmentVariable')
2675 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
2676 $this->assertEquals('dummyPath', $this->subject->getData('getindpenv:SCRIPT_FILENAME'));
2677 }
2678
2679 /**
2680 * Checks if getData() works with type "field"
2681 *
2682 * @test
2683 */
2684 public function getDataWithTypeField()
2685 {
2686 $key = 'someKey';
2687 $value = 'someValue';
2688 $field = array($key => $value);
2689
2690 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2691 }
2692
2693 /**
2694 * Checks if getData() works with type "field" of the field content
2695 * is multi-dimensional (e.g. an array)
2696 *
2697 * @test
2698 */
2699 public function getDataWithTypeFieldAndFieldIsMultiDimensional()
2700 {
2701 $key = 'somekey|level1|level2';
2702 $value = 'somevalue';
2703 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
2704
2705 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2706 }
2707
2708 /**
2709 * Basic check if getData gets the uid of a file object
2710 *
2711 * @test
2712 */
2713 public function getDataWithTypeFileReturnsUidOfFileObject()
2714 {
2715 $uid = $this->getUniqueId();
2716 $file = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(), '', false);
2717 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
2718 $this->subject->setCurrentFile($file);
2719 $this->assertEquals($uid, $this->subject->getData('file:current:uid'));
2720 }
2721
2722 /**
2723 * Checks if getData() works with type "parameters"
2724 *
2725 * @test
2726 */
2727 public function getDataWithTypeParameters()
2728 {
2729 $key = $this->getUniqueId('someKey');
2730 $value = $this->getUniqueId('someValue');
2731 $this->subject->parameters[$key] = $value;
2732
2733 $this->assertEquals($value, $this->subject->getData('parameters:' . $key));
2734 }
2735
2736 /**
2737 * Checks if getData() works with type "register"
2738 *
2739 * @test
2740 */
2741 public function getDataWithTypeRegister()
2742 {
2743 $key = $this->getUniqueId('someKey');
2744 $value = $this->getUniqueId('someValue');
2745 $GLOBALS['TSFE']->register[$key] = $value;
2746
2747 $this->assertEquals($value, $this->subject->getData('register:' . $key));
2748 }
2749
2750 /**
2751 * Checks if getData() works with type "level"
2752 *
2753 * @test
2754 */
2755 public function getDataWithTypeLevel()
2756 {
2757 $rootline = array(
2758 0 => array('uid' => 1, 'title' => 'title1'),
2759 1 => array('uid' => 2, 'title' => 'title2'),
2760 2 => array('uid' => 3, 'title' => 'title3'),
2761 );
2762
2763 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2764 $this->assertEquals(2, $this->subject->getData('level'));
2765 }
2766
2767 /**
2768 * Checks if getData() works with type "global"
2769 *
2770 * @test
2771 */
2772 public function getDataWithTypeGlobal()
2773 {
2774 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('global:TSFE|renderCharset'));
2775 }
2776
2777 /**
2778 * Checks if getData() works with type "leveltitle"
2779 *
2780 * @test
2781 */
2782 public function getDataWithTypeLeveltitle()
2783 {
2784 $rootline = array(
2785 0 => array('uid' => 1, 'title' => 'title1'),
2786 1 => array('uid' => 2, 'title' => 'title2'),
2787 2 => array('uid' => 3, 'title' => ''),
2788 );
2789
2790 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2791 $this->assertEquals('', $this->subject->getData('leveltitle:-1'));
2792 // since "title3" is not set, it will slide to "title2"
2793 $this->assertEquals('title2', $this->subject->getData('leveltitle:-1,slide'));
2794 }
2795
2796 /**
2797 * Checks if getData() works with type "levelmedia"
2798 *
2799 * @test
2800 */
2801 public function getDataWithTypeLevelmedia()
2802 {
2803 $rootline = array(
2804 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
2805 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
2806 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
2807 );
2808
2809 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2810 $this->assertEquals('', $this->subject->getData('levelmedia:-1'));
2811 // since "title3" is not set, it will slide to "title2"
2812 $this->assertEquals('media2', $this->subject->getData('levelmedia:-1,slide'));
2813 }
2814
2815 /**
2816 * Checks if getData() works with type "leveluid"
2817 *
2818 * @test
2819 */
2820 public function getDataWithTypeLeveluid()
2821 {
2822 $rootline = array(
2823 0 => array('uid' => 1, 'title' => 'title1'),
2824 1 => array('uid' => 2, 'title' => 'title2'),
2825 2 => array('uid' => 3, 'title' => 'title3'),
2826 );
2827
2828 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2829 $this->assertEquals(3, $this->subject->getData('leveluid:-1'));
2830 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
2831 $this->assertEquals(3, $this->subject->getData('leveluid:-1,slide'));
2832 }
2833
2834 /**
2835 * Checks if getData() works with type "levelfield"
2836 *
2837 * @test
2838 */
2839 public function getDataWithTypeLevelfield()
2840 {
2841 $rootline = array(
2842 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2843 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2844 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2845 );
2846
2847 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2848 $this->assertEquals('', $this->subject->getData('levelfield:-1,testfield'));
2849 $this->assertEquals('field2', $this->subject->getData('levelfield:-1,testfield,slide'));
2850 }
2851
2852 /**
2853 * Checks if getData() works with type "fullrootline"
2854 *
2855 * @test
2856 */
2857 public function getDataWithTypeFullrootline()
2858 {
2859 $rootline1 = array(
2860 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2861 );
2862 $rootline2 = array(
2863 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2864 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2865 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2866 );
2867
2868 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
2869 $GLOBALS['TSFE']->rootLine = $rootline2;
2870 $this->assertEquals('field2', $this->subject->getData('fullrootline:-1,testfield'));
2871 }
2872
2873 /**
2874 * Checks if getData() works with type "date"
2875 *
2876 * @test
2877 */
2878 public function getDataWithTypeDate()
2879 {
2880 $format = 'Y-M-D';
2881 $defaultFormat = 'd/m Y';
2882
2883 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject->getData('date:' . $format));
2884 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject->getData('date'));
2885 }
2886
2887 /**
2888 * Checks if getData() works with type "page"
2889 *
2890 * @test
2891 */
2892 public function getDataWithTypePage()
2893 {
2894 $uid = rand();
2895 $GLOBALS['TSFE']->page['uid'] = $uid;
2896 $this->assertEquals($uid, $this->subject->getData('page:uid'));
2897 }
2898
2899 /**
2900 * Checks if getData() works with type "current"
2901 *
2902 * @test
2903 */
2904 public function getDataWithTypeCurrent()
2905 {
2906 $key = $this->getUniqueId('someKey');
2907 $value = $this->getUniqueId('someValue');
2908 $this->subject->data[$key] = $value;
2909 $this->subject->currentValKey = $key;
2910 $this->assertEquals($value, $this->subject->getData('current'));
2911 }
2912
2913 /**
2914 * Checks if getData() works with type "db"
2915 *
2916 * @test
2917 */
2918 public function getDataWithTypeDb()
2919 {
2920 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2921
2922 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2923 $this->assertEquals($dummyRecord['title'], $this->subject->getData('db:tt_content:106:title'));
2924 }
2925
2926 /**
2927 * Checks if getData() works with type "lll"
2928 *
2929 * @test
2930 */
2931 public function getDataWithTypeLll()
2932 {
2933 $key = $this->getUniqueId('someKey');
2934 $value = $this->getUniqueId('someValue');
2935 $language = $this->getUniqueId('someLanguage');
2936 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
2937 $GLOBALS['TSFE']->lang = $language;
2938
2939 $this->assertEquals($value, $this->subject->getData('lll:' . $key));
2940 }
2941
2942 /**
2943 * Checks if getData() works with type "path"
2944 *
2945 * @test
2946 */
2947 public function getDataWithTypePath()
2948 {
2949 $filenameIn = $this->getUniqueId('someValue');
2950 $filenameOut = $this->getUniqueId('someValue');
2951 $this->templateServiceMock->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2952 $this->assertEquals($filenameOut, $this->subject->getData('path:' . $filenameIn));
2953 }
2954
2955 /**
2956 * Checks if getData() works with type "parentRecordNumber"
2957 *
2958 * @test
2959 */
2960 public function getDataWithTypeParentRecordNumber()
2961 {
2962 $recordNumber = rand();
2963 $this->subject->parentRecordNumber = $recordNumber;
2964 $this->assertEquals($recordNumber, $this->subject->getData('cobj:parentRecordNumber'));
2965 }
2966
2967 /**
2968 * Checks if getData() works with type "debug:rootLine"
2969 *
2970 * @test
2971 */
2972 public function getDataWithTypeDebugRootline()
2973 {
2974 $rootline = array(
2975 0 => array('uid' => 1, 'title' => 'title1'),
2976 1 => array('uid' => 2, 'title' => 'title2'),
2977 2 => array('uid' => 3, 'title' => ''),
2978 );
2979 $expectedResult = 'array(3items)0=>array(2items)uid=>1(integer)title=>"title1"(6chars)1=>array(2items)uid=>2(integer)title=>"title2"(6chars)2=>array(2items)uid=>3(integer)title=>""(0chars)';
2980 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2981
2982 $result = $this->subject->getData('debug:rootLine');
2983 $cleanedResult = strip_tags($result);
2984 $cleanedResult = str_replace("\r", '', $cleanedResult);
2985 $cleanedResult = str_replace("\n", '', $cleanedResult);
2986 $cleanedResult = str_replace("\t", '', $cleanedResult);
2987 $cleanedResult = str_replace(' ', '', $cleanedResult);
2988
2989 $this->assertEquals($expectedResult, $cleanedResult);
2990 }
2991
2992 /**
2993 * Checks if getData() works with type "debug:fullRootLine"
2994 *
2995 * @test
2996 */
2997 public function getDataWithTypeDebugFullRootline()
2998 {
2999 $rootline = array(
3000 0 => array('uid' => 1, 'title' => 'title1'),
3001 1 => array('uid' => 2, 'title' => 'title2'),
3002 2 => array('uid' => 3, 'title' => ''),
3003 );
3004 $expectedResult = 'array(3items)0=>array(2items)uid=>1(integer)title=>"title1"(6chars)1=>array(2items)uid=>2(integer)title=>"title2"(6chars)2=>array(2items)uid=>3(integer)title=>""(0chars)';
3005 $GLOBALS['TSFE']->rootLine = $rootline;
3006
3007 $result = $this->subject->getData('debug:fullRootLine');
3008 $cleanedResult = strip_tags($result);
3009 $cleanedResult = str_replace("\r", '', $cleanedResult);
3010 $cleanedResult = str_replace("\n", '', $cleanedResult);
3011 $cleanedResult = str_replace("\t", '', $cleanedResult);
3012 $cleanedResult = str_replace(' ', '', $cleanedResult);
3013
3014 $this->assertEquals($expectedResult, $cleanedResult);
3015 }
3016
3017 /**
3018 * Checks if getData() works with type "debug:data"
3019 *
3020 * @test
3021 */
3022 public function getDataWithTypeDebugData()
3023 {
3024 $key = $this->getUniqueId('someKey');
3025 $value = $this->getUniqueId('someValue');
3026 $this->subject->data = array($key => $value);
3027
3028 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
3029
3030 $result = $this->subject->getData('debug:data');
3031 $cleanedResult = strip_tags($result);
3032 $cleanedResult = str_replace("\r", '', $cleanedResult);
3033 $cleanedResult = str_replace("\n", '', $cleanedResult);
3034 $cleanedResult = str_replace("\t", '', $cleanedResult);
3035 $cleanedResult = str_replace(' ', '', $cleanedResult);
3036
3037 $this->assertEquals($expectedResult, $cleanedResult);
3038 }
3039
3040 /**
3041 * Checks if getData() works with type "debug:register"
3042 *
3043 * @test
3044 */
3045 public function getDataWithTypeDebugRegister()
3046 {
3047 $key = $this->getUniqueId('someKey');
3048 $value = $this->getUniqueId('someValue');
3049 $GLOBALS['TSFE']->register = array($key => $value);
3050
3051 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
3052
3053 $result = $this->subject->getData('debug:register');