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