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