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