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