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