[TASK] Remove last part of singleton pattern in getUserObj()
[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 * Data provider for the getQuery test
1469 *
1470 * @return array multi-dimensional array with the second level like this:
1471 * @see getQuery
1472 */
1473 public function getQueryDataProvider()
1474 {
1475 $data = array(
1476 'testing empty conf' => array(
1477 'tt_content',
1478 array(),
1479 array(
1480 'SELECT' => '*'
1481 )
1482 ),
1483 'testing #17284: adding uid/pid for workspaces' => array(
1484 'tt_content',
1485 array(
1486 'selectFields' => 'header,bodytext'
1487 ),
1488 array(
1489 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1490 )
1491 ),
1492 'testing #17284: no need to add' => array(
1493 'tt_content',
1494 array(
1495 'selectFields' => 'tt_content.*'
1496 ),
1497 array(
1498 'SELECT' => 'tt_content.*'
1499 )
1500 ),
1501 'testing #17284: no need to add #2' => array(
1502 'tt_content',
1503 array(
1504 'selectFields' => '*'
1505 ),
1506 array(
1507 'SELECT' => '*'
1508 )
1509 ),
1510 'testing #29783: joined tables, prefix tablename' => array(
1511 'tt_content',
1512 array(
1513 'selectFields' => 'tt_content.header,be_users.username',
1514 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1515 ),
1516 array(
1517 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1518 )
1519 ),
1520 'testing #34152: single count(*), add nothing' => array(
1521 'tt_content',
1522 array(
1523 'selectFields' => 'count(*)'
1524 ),
1525 array(
1526 'SELECT' => 'count(*)'
1527 )
1528 ),
1529 'testing #34152: single max(crdate), add nothing' => array(
1530 'tt_content',
1531 array(
1532 'selectFields' => 'max(crdate)'
1533 ),
1534 array(
1535 'SELECT' => 'max(crdate)'
1536 )
1537 ),
1538 'testing #34152: single min(crdate), add nothing' => array(
1539 'tt_content',
1540 array(
1541 'selectFields' => 'min(crdate)'
1542 ),
1543 array(
1544 'SELECT' => 'min(crdate)'
1545 )
1546 ),
1547 'testing #34152: single sum(is_siteroot), add nothing' => array(
1548 'tt_content',
1549 array(
1550 'selectFields' => 'sum(is_siteroot)'
1551 ),
1552 array(
1553 'SELECT' => 'sum(is_siteroot)'
1554 )
1555 ),
1556 'testing #34152: single avg(crdate), add nothing' => array(
1557 'tt_content',
1558 array(
1559 'selectFields' => 'avg(crdate)'
1560 ),
1561 array(
1562 'SELECT' => 'avg(crdate)'
1563 )
1564 )
1565 );
1566 return $data;
1567 }
1568
1569 /**
1570 * Check if sanitizeSelectPart works as expected
1571 *
1572 * @dataProvider getQueryDataProvider
1573 * @test
1574 */
1575 public function getQuery($table, $conf, $expected)
1576 {
1577 $GLOBALS['TCA'] = array(
1578 'pages' => array(
1579 'ctrl' => array(
1580 'enablecolumns' => array(
1581 'disabled' => 'hidden'
1582 )
1583 )
1584 ),
1585 'tt_content' => array(
1586 'ctrl' => array(
1587 'enablecolumns' => array(
1588 'disabled' => 'hidden'
1589 ),
1590 'versioningWS' => true
1591 )
1592 ),
1593 );
1594 $result = $this->subject->getQuery($table, $conf, true);
1595 foreach ($expected as $field => $value) {
1596 $this->assertEquals($value, $result[$field]);
1597 }
1598 }
1599
1600 /**
1601 * @test
1602 */
1603 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet()
1604 {
1605 $GLOBALS['TCA'] = array(
1606 'pages' => array(
1607 'ctrl' => array(
1608 'enablecolumns' => array(
1609 'disabled' => 'hidden'
1610 )
1611 )
1612 ),
1613 'tt_content' => array(
1614 'ctrl' => array(
1615 'enablecolumns' => array(
1616 'disabled' => 'hidden'
1617 )
1618 )
1619 ),
1620 );
1621 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array('getTreeList'));
1622 $this->subject->start(array(), 'tt_content');
1623 $conf = array(
1624 'recursive' => '15',
1625 'pidInList' => '16, -35'
1626 );
1627 $this->subject->expects($this->at(0))
1628 ->method('getTreeList')
1629 ->with(-16, 15)
1630 ->will($this->returnValue('15,16'));
1631 $this->subject->expects($this->at(1))
1632 ->method('getTreeList')
1633 ->with(-35, 15)
1634 ->will($this->returnValue('15,35'));
1635 $this->subject->getQuery('tt_content', $conf, true);
1636 }
1637
1638 /**
1639 * @test
1640 */
1641 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet()
1642 {
1643 $GLOBALS['TCA'] = array(
1644 'pages' => array(
1645 'ctrl' => array(
1646 'enablecolumns' => array(
1647 'disabled' => 'hidden'
1648 )
1649 )
1650 ),
1651 'tt_content' => array(
1652 'ctrl' => array(
1653 'enablecolumns' => array(
1654 'disabled' => 'hidden'
1655 )
1656 )
1657 ),
1658 );
1659 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array('getTreeList'));
1660 $GLOBALS['TSFE']->id = 27;
1661 $this->subject->start(array(), 'tt_content');
1662 $conf = array(
1663 'pidInList' => 'this',
1664 'recursive' => '4'
1665 );
1666 $this->subject->expects($this->once())
1667 ->method('getTreeList')
1668 ->with(-27)
1669 ->will($this->returnValue('27'));
1670 $this->subject->getQuery('tt_content', $conf, true);
1671 }
1672
1673 /**
1674 * Data provider for the stdWrap_date test
1675 *
1676 * @return array multi-dimensional array with the second level like this:
1677 * @see stdWrap_date
1678 */
1679 public function stdWrap_dateDataProvider()
1680 {
1681 return array(
1682 'given timestamp' => array(
1683 1443780000, // This is 2015-10-02 12:00
1684 array(
1685 'date' => 'd.m.Y',
1686 ),
1687 '02.10.2015',
1688 ),
1689 'empty string' => array(
1690 '',
1691 array(
1692 'date' => 'd.m.Y',
1693 ),
1694 '02.10.2015',
1695 ),
1696 'testing null' => array(
1697 null,
1698 array(
1699 'date' => 'd.m.Y',
1700 ),
1701 '02.10.2015',
1702 ),
1703 'given timestamp return GMT' => array(
1704 1443780000, // This is 2015-10-02 12:00
1705 array(
1706 'date' => 'd.m.Y H:i:s',
1707 'date.' => array(
1708 'GMT' => true,
1709 )
1710 ),
1711 '02.10.2015 10:00:00',
1712 ),
1713 );
1714 }
1715
1716 /**
1717 * @test
1718 * @dataProvider stdWrap_dateDataProvider
1719 * @param string|int|NULL $content
1720 * @param array $conf
1721 * @param string $expected
1722 */
1723 public function stdWrap_date($content, $conf, $expected)
1724 {
1725 // Set exec_time to a hard timestamp
1726 $GLOBALS['EXEC_TIME'] = 1443780000;
1727
1728 $result = $this->subject->stdWrap_date($content, $conf);
1729
1730 $this->assertEquals($expected, $result);
1731 }
1732
1733 /**
1734 * Data provider for the stdWrap_strftime test
1735 *
1736 * @return array multi-dimensional array with the second level like this:
1737 * @see stdWrap_strftime
1738 */
1739 public function stdWrap_strftimeReturnsFormattedStringDataProvider()
1740 {
1741 $data = array(
1742 'given timestamp' => array(
1743 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1744 array(
1745 'strftime' => '%d-%m-%Y',
1746 ),
1747 ),
1748 'empty string' => array(
1749 '',
1750 array(
1751 'strftime' => '%d-%m-%Y',
1752 ),
1753 ),
1754 'testing null' => array(
1755 null,
1756 array(
1757 'strftime' => '%d-%m-%Y',
1758 ),
1759 ),
1760 );
1761 return $data;
1762 }
1763
1764 /**
1765 * @test
1766 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1767 */
1768 public function stdWrap_strftimeReturnsFormattedString($content, $conf)
1769 {
1770 // Set exec_time to a hard timestamp
1771 $GLOBALS['EXEC_TIME'] = 1346500800;
1772 // Save current timezone and set to UTC to make the system under test behave
1773 // the same in all server timezone settings
1774 $timezoneBackup = date_default_timezone_get();
1775 date_default_timezone_set('UTC');
1776
1777 $result = $this->subject->stdWrap_strftime($content, $conf);
1778
1779 // Reset timezone
1780 date_default_timezone_set($timezoneBackup);
1781
1782 $this->assertEquals('01-09-2012', $result);
1783 }
1784
1785 /**
1786 * Data provider for the stdWrap_strtotime test
1787 *
1788 * @return array
1789 * @see stdWrap_strtotime
1790 */
1791 public function stdWrap_strtotimeReturnsTimestampDataProvider()
1792 {
1793 return array(
1794 'date from content' => array(
1795 '2014-12-04',
1796 array(
1797 'strtotime' => '1',
1798 ),
1799 1417651200,
1800 ),
1801 'manipulation of date from content' => array(
1802 '2014-12-04',
1803 array(
1804 'strtotime' => '+ 2 weekdays',
1805 ),
1806 1417996800,
1807 ),
1808 'date from configuration' => array(
1809 '',
1810 array(
1811 'strtotime' => '2014-12-04',
1812 ),
1813 1417651200,
1814 ),
1815 'manipulation of date from configuration' => array(
1816 '',
1817 array(
1818 'strtotime' => '2014-12-04 + 2 weekdays',
1819 ),
1820 1417996800,
1821 ),
1822 'empty input' => array(
1823 '',
1824 array(
1825 'strtotime' => '1',
1826 ),
1827 false,
1828 ),
1829 'date from content and configuration' => array(
1830 '2014-12-04',
1831 array(
1832 'strtotime' => '2014-12-05',
1833 ),
1834 false,
1835 ),
1836 );
1837 }
1838
1839 /**
1840 * @param string|NULL $content
1841 * @param array $configuration
1842 * @param int $expected
1843 * @dataProvider stdWrap_strtotimeReturnsTimestampDataProvider
1844 * @test
1845 */
1846 public function stdWrap_strtotimeReturnsTimestamp($content, $configuration, $expected)
1847 {
1848 // Set exec_time to a hard timestamp
1849 $GLOBALS['EXEC_TIME'] = 1417392000;
1850 // Save current timezone and set to UTC to make the system under test behave
1851 // the same in all server timezone settings
1852 $timezoneBackup = date_default_timezone_get();
1853 date_default_timezone_set('UTC');
1854
1855 $result = $this->subject->stdWrap_strtotime($content, $configuration);
1856
1857 // Reset timezone
1858 date_default_timezone_set($timezoneBackup);
1859
1860 $this->assertEquals($expected, $result);
1861 }
1862
1863 /**
1864 * @test
1865 */
1866 public function stdWrap_ageCallsCalcAgeWithSubtractedTimestampAndSubPartOfArray()
1867 {
1868 $subject = $this->getMock(
1869 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
1870 array('calcAge')
1871 );
1872 // Set exec_time to a hard timestamp
1873 $GLOBALS['EXEC_TIME'] = 10;
1874 $subject->expects($this->once())->method('calcAge')->with(1, 'Min| Hrs| Days| Yrs');
1875 $subject->stdWrap_age(9, array('age' => 'Min| Hrs| Days| Yrs'));
1876 }
1877
1878 /**
1879 * Data provider for calcAgeCalculatesAgeOfTimestamp
1880 *
1881 * @return array
1882 * @see calcAge
1883 */
1884 public function calcAgeCalculatesAgeOfTimestampDataProvider()
1885 {
1886 return array(
1887 'minutes' => array(
1888 120,
1889 ' min| hrs| days| yrs',
1890 '2 min',
1891 ),
1892 'hours' => array(
1893 7200,
1894 ' min| hrs| days| yrs',
1895 '2 hrs',
1896 ),
1897 'days' => array(
1898 604800,
1899 ' min| hrs| days| yrs',
1900 '7 days',
1901 ),
1902 'day with provided singular labels' => array(
1903 86400,
1904 ' min| hrs| days| yrs| min| hour| day| year',
1905 '1 day',
1906 ),
1907 'years' => array(
1908 1417997800,
1909 ' min| hrs| days| yrs',
1910 '45 yrs',
1911 ),
1912 'different labels' => array(
1913 120,
1914 ' Minutes| Hrs| Days| Yrs',
1915 '2 Minutes',
1916 ),
1917 'negative values' => array(
1918 -604800,
1919 ' min| hrs| days| yrs',
1920 '-7 days',
1921 ),
1922 'default label values for wrong label input' => array(
1923 121,
1924 10,
1925 '2 min',
1926 ),
1927 'default singular label values for wrong label input' => array(
1928 31536000,
1929 10,
1930 '1 year',
1931 )
1932 );
1933 }
1934
1935 /**
1936 * @param int $timestamp
1937 * @param string $labels
1938 * @param int $expectation
1939 * @dataProvider calcAgeCalculatesAgeOfTimestampDataProvider
1940 * @test
1941 */
1942 public function calcAgeCalculatesAgeOfTimestamp($timestamp, $labels, $expectation)
1943 {
1944 $result = $this->subject->calcAge($timestamp, $labels);
1945 $this->assertEquals($result, $expectation);
1946 }
1947
1948 /**
1949 * Data provider for stdWrap_case test
1950 *
1951 * @return array
1952 */
1953 public function stdWrap_caseDataProvider()
1954 {
1955 return array(
1956 'lower case text to upper' => array(
1957 '<span>text</span>',
1958 array(
1959 'case' => 'upper',
1960 ),
1961 '<span>TEXT</span>',
1962 ),
1963 'upper case text to lower' => array(
1964 '<span>TEXT</span>',
1965 array(
1966 'case' => 'lower',
1967 ),
1968 '<span>text</span>',
1969 ),
1970 'capitalize text' => array(
1971 '<span>this is a text</span>',
1972 array(
1973 'case' => 'capitalize',
1974 ),
1975 '<span>This Is A Text</span>',
1976 ),
1977 'ucfirst text' => array(
1978 '<span>this is a text</span>',
1979 array(
1980 'case' => 'ucfirst',
1981 ),
1982 '<span>This is a text</span>',
1983 ),
1984 'lcfirst text' => array(
1985 '<span>This is a Text</span>',
1986 array(
1987 'case' => 'lcfirst',
1988 ),
1989 '<span>this is a Text</span>',
1990 ),
1991 'uppercamelcase text' => array(
1992 '<span>this_is_a_text</span>',
1993 array(
1994 'case' => 'uppercamelcase',
1995 ),
1996 '<span>ThisIsAText</span>',
1997 ),
1998 'lowercamelcase text' => array(
1999 '<span>this_is_a_text</span>',
2000 array(
2001 'case' => 'lowercamelcase',
2002 ),
2003 '<span>thisIsAText</span>',
2004 ),
2005 );
2006 }
2007
2008 /**
2009 * @param string|NULL $content
2010 * @param array $configuration
2011 * @param string $expected
2012 * @dataProvider stdWrap_caseDataProvider
2013 * @test
2014 */
2015 public function stdWrap_case($content, array $configuration, $expected)
2016 {
2017 $result = $this->subject->stdWrap_case($content, $configuration);
2018 $this->assertEquals($expected, $result);
2019 }
2020
2021 /**
2022 * Data provider for stdWrap_bytes test
2023 *
2024 * @return array
2025 */
2026 public function stdWrap_bytesDataProvider()
2027 {
2028 return array(
2029 'value 1234 default' => array(
2030 '1234',
2031 array(
2032 'bytes.' => array(
2033 'labels' => '',
2034 'base' => 0,
2035 ),
2036 ),
2037 '1.21 Ki',
2038 'en_US.UTF-8'
2039 ),
2040 'value 1234 si' => array(
2041 '1234',
2042 array(
2043 'bytes.' => array(
2044 'labels' => 'si',
2045 'base' => 0,
2046 ),
2047 ),
2048 '1.23 k',
2049 'en_US.UTF-8'
2050 ),
2051 'value 1234 iec' => array(
2052 '1234',
2053 array(
2054 'bytes.' => array(
2055 'labels' => 'iec',
2056 'base' => 0,
2057 ),
2058 ),
2059 '1.21 Ki',
2060 'en_US.UTF-8'
2061 ),
2062 'value 1234 a-i' => array(
2063 '1234',
2064 array(
2065 'bytes.' => array(
2066 'labels' => 'a|b|c|d|e|f|g|h|i',
2067 'base' => 1000,
2068 ),
2069 ),
2070 '1.23b',
2071 'en_US.UTF-8'
2072 ),
2073 'value 1234 a-i invalid base' => array(
2074 '1234',
2075 array(
2076 'bytes.' => array(
2077 'labels' => 'a|b|c|d|e|f|g|h|i',
2078 'base' => 54,
2079 ),
2080 ),
2081 '1.21b',
2082 'en_US.UTF-8'
2083 ),
2084 'value 1234567890 default' => array(
2085 '1234567890',
2086 array(
2087 'bytes.' => array(
2088 'labels' => '',
2089 'base' => 0,
2090 ),
2091 ),
2092 '1.15 Gi',
2093 'en_US.UTF-8'
2094 ),
2095 );
2096 }
2097
2098 /**
2099 * @param string|NULL $content
2100 * @param array $configuration
2101 * @param string $expected
2102 * @dataProvider stdWrap_bytesDataProvider
2103 * @test
2104 */
2105 public function stdWrap_bytes($content, array $configuration, $expected, $locale)
2106 {
2107 if (!setlocale(LC_NUMERIC, $locale)) {
2108 $this->markTestSkipped('Locale ' . $locale . ' is not available.');
2109 }
2110 $result = $this->subject->stdWrap_bytes($content, $configuration);
2111 $this->assertSame($expected, $result);
2112 }
2113
2114 /**
2115 * Data provider for stdWrap_substring test
2116 *
2117 * @return array
2118 */
2119 public function stdWrap_substringDataProvider()
2120 {
2121 return array(
2122 'sub -1' => array(
2123 'substring',
2124 array(
2125 'substring' => '-1',
2126 ),
2127 'g',
2128 ),
2129 'sub -1,0' => array(
2130 'substring',
2131 array(
2132 'substring' => '-1,0',
2133 ),
2134 'g',
2135 ),
2136 'sub -1,-1' => array(
2137 'substring',
2138 array(
2139 'substring' => '-1,-1',
2140 ),
2141 '',
2142 ),
2143 'sub -1,1' => array(
2144 'substring',
2145 array(
2146 'substring' => '-1,1',
2147 ),
2148 'g',
2149 ),
2150 'sub 0' => array(
2151 'substring',
2152 array(
2153 'substring' => '0',
2154 ),
2155 'substring',
2156 ),
2157 'sub 0,0' => array(
2158 'substring',
2159 array(
2160 'substring' => '0,0',
2161 ),
2162 'substring',
2163 ),
2164 'sub 0,-1' => array(
2165 'substring',
2166 array(
2167 'substring' => '0,-1',
2168 ),
2169 'substrin',
2170 ),
2171 'sub 0,1' => array(
2172 'substring',
2173 array(
2174 'substring' => '0,1',
2175 ),
2176 's',
2177 ),
2178 'sub 1' => array(
2179 'substring',
2180 array(
2181 'substring' => '1',
2182 ),
2183 'ubstring',
2184 ),
2185 'sub 1,0' => array(
2186 'substring',
2187 array(
2188 'substring' => '1,0',
2189 ),
2190 'ubstring',
2191 ),
2192 'sub 1,-1' => array(
2193 'substring',
2194 array(
2195 'substring' => '1,-1',
2196 ),
2197 'ubstrin',
2198 ),
2199 'sub 1,1' => array(
2200 'substring',
2201 array(
2202 'substring' => '1,1',
2203 ),
2204 'u',
2205 ),
2206 'sub' => array(
2207 'substring',
2208 array(
2209 'substring' => '',
2210 ),
2211 'substring',
2212 ),
2213 );
2214 }
2215
2216 /**
2217 * @param string $content
2218 * @param array $configuration
2219 * @param string $expected
2220 * @dataProvider stdWrap_substringDataProvider
2221 * @test
2222 */
2223 public function stdWrap_substring($content, array $configuration, $expected)
2224 {
2225 $result = $this->subject->stdWrap_substring($content, $configuration);
2226 $this->assertSame($expected, $result);
2227 }
2228
2229 /**
2230 * Data provider for stdWrap_stdWrapValue test
2231 *
2232 * @return array
2233 */
2234 public function stdWrap_stdWrapValueDataProvider()
2235 {
2236 return array(
2237 'only key returns value' => array(
2238 'ifNull',
2239 array(
2240 'ifNull' => '1',
2241 ),
2242 '',
2243 '1',
2244 ),
2245 'array without key returns empty string' => array(
2246 'ifNull',
2247 array(
2248 'ifNull.' => '1',
2249 ),
2250 '',
2251 '',
2252 ),
2253 'array without key returns default' => array(
2254 'ifNull',
2255 array(
2256 'ifNull.' => '1',
2257 ),
2258 'default',
2259 'default',
2260 ),
2261 'non existing key returns default' => array(
2262 'ifNull',
2263 array(
2264 'noTrimWrap' => 'test',
2265 'noTrimWrap.' => '1',
2266 ),
2267 'default',
2268 'default',
2269 ),
2270 'existing key and array returns stdWrap' => array(
2271 'test',
2272 array(
2273 'test' => 'value',
2274 'test.' => array('case' => 'upper'),
2275 ),
2276 'default',
2277 'VALUE'
2278 ),
2279 );
2280 }
2281
2282 /**
2283 * @param string $key
2284 * @param array $configuration
2285 * @param string $defaultValue
2286 * @param string $expected
2287 * @dataProvider stdWrap_stdWrapValueDataProvider
2288 * @test
2289 */
2290 public function stdWrap_stdWrapValue($key, array $configuration, $defaultValue, $expected)
2291 {
2292 $result = $this->subject->stdWrapValue($key, $configuration, $defaultValue);
2293 $this->assertEquals($expected, $result);
2294 }
2295
2296 /**
2297 * @param string|NULL $content
2298 * @param array $configuration
2299 * @param string $expected
2300 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
2301 * @test
2302 */
2303 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected)
2304 {
2305 $result = $this->subject->stdWrap_ifNull($content, $configuration);
2306 $this->assertEquals($expected, $result);
2307 }
2308
2309 /**
2310 * Data provider for stdWrap_ifNullDeterminesNullValues test
2311 *
2312 * @return array
2313 */
2314 public function stdWrap_ifNullDeterminesNullValuesDataProvider()
2315 {
2316 return array(
2317 'null value' => array(
2318 null,
2319 array(
2320 'ifNull' => '1',
2321 ),
2322 '1',
2323 ),
2324 'zero value' => array(
2325 '0',
2326 array(
2327 'ifNull' => '1',
2328 ),
2329 '0',
2330 ),
2331 );
2332 }
2333
2334 /**
2335 * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
2336 *
2337 * @return array
2338 */
2339 public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider()
2340 {
2341 return array(
2342 'null value' => array(
2343 null,
2344 array(
2345 'ifEmpty' => '1',
2346 ),
2347 '1',
2348 ),
2349 'empty value' => array(
2350 '',
2351 array(
2352 'ifEmpty' => '1',
2353 ),
2354 '1',
2355 ),
2356 'string value' => array(
2357 'string',
2358 array(
2359 'ifEmpty' => '1',
2360 ),
2361 'string',
2362 ),
2363 'empty string value' => array(
2364 ' ',
2365 array(
2366 'ifEmpty' => '1',
2367 ),
2368 '1',
2369 ),
2370 );
2371 }
2372
2373 /**
2374 * @param string|NULL $content
2375 * @param array $configuration
2376 * @param string $expected
2377 * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
2378 * @test
2379 */
2380 public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected)
2381 {
2382 $result = $this->subject->stdWrap_ifEmpty($content, $configuration);
2383 $this->assertEquals($expected, $result);
2384 }
2385
2386 /**
2387 * @param $content
2388 * @param array $configuration
2389 * @param $expected
2390 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
2391 * @test
2392 */
2393 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected)
2394 {
2395 $result = $this->subject->stdWrap_noTrimWrap($content, $configuration);
2396 $this->assertEquals($expected, $result);
2397 }
2398
2399 /**
2400 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
2401 *
2402 * @return array
2403 */
2404 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider()
2405 {
2406 return array(
2407 'No char given' => array(
2408 'middle',
2409 array(
2410 'noTrimWrap' => '| left | right |',
2411 ),
2412 ' left middle right '
2413 ),
2414 'Zero char given' => array(
2415 'middle',
2416 array(
2417 'noTrimWrap' => '0 left 0 right 0',
2418 'noTrimWrap.' => array('splitChar' => '0'),
2419
2420 ),
2421 ' left middle right '
2422 ),
2423 'Default char given' => array(
2424 'middle',
2425 array(
2426 'noTrimWrap' => '| left | right |',
2427 'noTrimWrap.' => array('splitChar' => '|'),
2428 ),
2429 ' left middle right '
2430 ),
2431 'Split char is a' => array(
2432 'middle',
2433 array(
2434 'noTrimWrap' => 'a left a right a',
2435 'noTrimWrap.' => array('splitChar' => 'a'),
2436 ),
2437 ' left middle right '
2438 ),
2439 'Split char is multi-char (ab)' => array(
2440 'middle',
2441 array(
2442 'noTrimWrap' => 'ab left ab right ab',
2443 'noTrimWrap.' => array('splitChar' => 'ab'),
2444 ),
2445 ' left middle right '
2446 ),
2447 'Split char accepts stdWrap' => array(
2448 'middle',
2449 array(
2450 'noTrimWrap' => 'abc left abc right abc',
2451 'noTrimWrap.' => array(
2452 'splitChar' => 'b',
2453 'splitChar.' => array('wrap' => 'a|c'),
2454 ),
2455 ),
2456 ' left middle right '
2457 ),
2458 );
2459 }
2460
2461 /**
2462 * @param array $expectedTags
2463 * @param array $configuration
2464 * @test
2465 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
2466 */
2467 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration)
2468 {
2469 $this->subject->stdWrap_addPageCacheTags('', $configuration);
2470 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock->_get('pageCacheTags'));
2471 }
2472
2473 /**
2474 * @return array
2475 */
2476 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider()
2477 {
2478 return array(
2479 'No Tag' => array(
2480 array(),
2481 array('addPageCacheTags' => ''),
2482 ),
2483 'Two expectedTags' => array(
2484 array('tag1', 'tag2'),
2485 array('addPageCacheTags' => 'tag1,tag2'),
2486 ),
2487 'Two expectedTags plus one with stdWrap' => array(
2488 array('tag1', 'tag2', 'tag3'),
2489 array(
2490 'addPageCacheTags' => 'tag1,tag2',
2491 'addPageCacheTags.' => array('wrap' => '|,tag3')
2492 ),
2493 ),
2494 );
2495 }
2496
2497 /**
2498 * Data provider for stdWrap_encodeForJavaScriptValue test
2499 *
2500 * @return array multi-dimensional array with the second level like this:
2501 * @see encodeForJavaScriptValue
2502 */
2503 public function stdWrap_encodeForJavaScriptValueDataProvider()
2504 {
2505 return array(
2506 'double quote in string' => array(
2507 'double quote"',
2508 array(),
2509 '\'double\u0020quote\u0022\''
2510 ),
2511 'backslash in string' => array(
2512 'backslash \\',
2513 array(),
2514 '\'backslash\u0020\u005C\''
2515 ),
2516 'exclamation mark' => array(
2517 'exclamation!',
2518 array(),
2519 '\'exclamation\u0021\''
2520 ),
2521 'whitespace tab, newline and carriage return' => array(
2522 "white\tspace\ns\r",
2523 array(),
2524 '\'white\u0009space\u000As\u000D\''
2525 ),
2526 'single quote in string' => array(
2527 'single quote \'',
2528 array(),
2529 '\'single\u0020quote\u0020\u0027\''
2530 ),
2531 'tag' => array(
2532 '<tag>',
2533 array(),
2534 '\'\u003Ctag\u003E\''
2535 ),
2536 'ampersand in string' => array(
2537 'amper&sand',
2538 array(),
2539 '\'amper\u0026sand\''
2540 ),
2541 );
2542 }
2543
2544 /**
2545 * Check if encodeForJavaScriptValue works properly
2546 *
2547 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
2548 * @test
2549 */
2550 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected)
2551 {
2552 $result = $this->subject->stdWrap_encodeForJavaScriptValue($input, $conf);
2553 $this->assertEquals($expected, $result);
2554 }
2555
2556 ///////////////////////////////
2557 // Tests concerning getData()
2558 ///////////////////////////////
2559
2560 /**
2561 * @return array
2562 */
2563 public function getDataWithTypeGpDataProvider()
2564 {
2565 return array(
2566 'Value in get-data' => array('onlyInGet', 'GetValue'),
2567 'Value in post-data' => array('onlyInPost', 'PostValue'),
2568 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
2569 );
2570 }
2571
2572 /**
2573 * Checks if getData() works with type "gp"
2574 *
2575 * @test
2576 * @dataProvider getDataWithTypeGpDataProvider
2577 */
2578 public function getDataWithTypeGp($key, $expectedValue)
2579 {
2580 $_GET = array(
2581 'onlyInGet' => 'GetValue',
2582 'inGetAndPost' => 'ValueInGet',
2583 );
2584 $_POST = array(
2585 'onlyInPost' => 'PostValue',
2586 'inGetAndPost' => 'ValueInPost',
2587 );
2588 $this->assertEquals($expectedValue, $this->subject->getData('gp:' . $key));
2589 }
2590
2591 /**
2592 * Checks if getData() works with type "tsfe"
2593 *
2594 * @test
2595 */
2596 public function getDataWithTypeTsfe()
2597 {
2598 $this->assertEquals($GLOBALS['TSFE']->metaCharset, $this->subject->getData('tsfe:metaCharset'));
2599 }
2600
2601 /**
2602 * Checks if getData() works with type "getenv"
2603 *
2604 * @test
2605 */
2606 public function getDataWithTypeGetenv()
2607 {
2608 $envName = $this->getUniqueId('frontendtest');
2609 $value = $this->getUniqueId('someValue');
2610 putenv($envName . '=' . $value);
2611 $this->assertEquals($value, $this->subject->getData('getenv:' . $envName));
2612 }
2613
2614 /**
2615 * Checks if getData() works with type "getindpenv"
2616 *
2617 * @test
2618 */
2619 public function getDataWithTypeGetindpenv()
2620 {
2621 $this->subject->expects($this->once())->method('getEnvironmentVariable')
2622 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
2623 $this->assertEquals('dummyPath', $this->subject->getData('getindpenv:SCRIPT_FILENAME'));
2624 }
2625
2626 /**
2627 * Checks if getData() works with type "field"
2628 *
2629 * @test
2630 */
2631 public function getDataWithTypeField()
2632 {
2633 $key = 'someKey';
2634 $value = 'someValue';
2635 $field = array($key => $value);
2636
2637 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2638 }
2639
2640 /**
2641 * Checks if getData() works with type "field" of the field content
2642 * is multi-dimensional (e.g. an array)
2643 *
2644 * @test
2645 */
2646 public function getDataWithTypeFieldAndFieldIsMultiDimensional()
2647 {
2648 $key = 'somekey|level1|level2';
2649 $value = 'somevalue';
2650 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
2651
2652 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2653 }
2654
2655 /**
2656 * Basic check if getData gets the uid of a file object
2657 *
2658 * @test
2659 */
2660 public function getDataWithTypeFileReturnsUidOfFileObject()
2661 {
2662 $uid = $this->getUniqueId();
2663 $file = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(), '', false);
2664 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
2665 $this->subject->setCurrentFile($file);
2666 $this->assertEquals($uid, $this->subject->getData('file:current:uid'));
2667 }
2668
2669 /**
2670 * Checks if getData() works with type "parameters"
2671 *
2672 * @test
2673 */
2674 public function getDataWithTypeParameters()
2675 {
2676 $key = $this->getUniqueId('someKey');
2677 $value = $this->getUniqueId('someValue');
2678 $this->subject->parameters[$key] = $value;
2679
2680 $this->assertEquals($value, $this->subject->getData('parameters:' . $key));
2681 }
2682
2683 /**
2684 * Checks if getData() works with type "register"
2685 *
2686 * @test
2687 */
2688 public function getDataWithTypeRegister()
2689 {
2690 $key = $this->getUniqueId('someKey');
2691 $value = $this->getUniqueId('someValue');
2692 $GLOBALS['TSFE']->register[$key] = $value;
2693
2694 $this->assertEquals($value, $this->subject->getData('register:' . $key));
2695 }
2696
2697 /**
2698 * Checks if getData() works with type "level"
2699 *
2700 * @test
2701 */
2702 public function getDataWithTypeLevel()
2703 {
2704 $rootline = array(
2705 0 => array('uid' => 1, 'title' => 'title1'),
2706 1 => array('uid' => 2, 'title' => 'title2'),
2707 2 => array('uid' => 3, 'title' => 'title3'),
2708 );
2709
2710 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2711 $this->assertEquals(2, $this->subject->getData('level'));
2712 }
2713
2714 /**
2715 * Checks if getData() works with type "global"
2716 *
2717 * @test
2718 */
2719 public function getDataWithTypeGlobal()
2720 {
2721 $this->assertEquals($GLOBALS['TSFE']->metaCharset, $this->subject->getData('global:TSFE|metaCharset'));
2722 }
2723
2724 /**
2725 * Checks if getData() works with type "leveltitle"
2726 *
2727 * @test
2728 */
2729 public function getDataWithTypeLeveltitle()
2730 {
2731 $rootline = array(
2732 0 => array('uid' => 1, 'title' => 'title1'),
2733 1 => array('uid' => 2, 'title' => 'title2'),
2734 2 => array('uid' => 3, 'title' => ''),
2735 );
2736
2737 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2738 $this->assertEquals('', $this->subject->getData('leveltitle:-1'));
2739 // since "title3" is not set, it will slide to "title2"
2740 $this->assertEquals('title2', $this->subject->getData('leveltitle:-1,slide'));
2741 }
2742
2743 /**
2744 * Checks if getData() works with type "levelmedia"
2745 *
2746 * @test
2747 */
2748 public function getDataWithTypeLevelmedia()
2749 {
2750 $rootline = array(
2751 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
2752 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
2753 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
2754 );
2755
2756 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2757 $this->assertEquals('', $this->subject->getData('levelmedia:-1'));
2758 // since "title3" is not set, it will slide to "title2"
2759 $this->assertEquals('media2', $this->subject->getData('levelmedia:-1,slide'));
2760 }
2761
2762 /**
2763 * Checks if getData() works with type "leveluid"
2764 *
2765 * @test
2766 */
2767 public function getDataWithTypeLeveluid()
2768 {
2769 $rootline = array(
2770 0 => array('uid' => 1, 'title' => 'title1'),
2771 1 => array('uid' => 2, 'title' => 'title2'),
2772 2 => array('uid' => 3, 'title' => 'title3'),
2773 );
2774
2775 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2776 $this->assertEquals(3, $this->subject->getData('leveluid:-1'));
2777 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
2778 $this->assertEquals(3, $this->subject->getData('leveluid:-1,slide'));
2779 }
2780
2781 /**
2782 * Checks if getData() works with type "levelfield"
2783 *
2784 * @test
2785 */
2786 public function getDataWithTypeLevelfield()
2787 {
2788 $rootline = array(
2789 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2790 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2791 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2792 );
2793
2794 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2795 $this->assertEquals('', $this->subject->getData('levelfield:-1,testfield'));
2796 $this->assertEquals('field2', $this->subject->getData('levelfield:-1,testfield,slide'));
2797 }
2798
2799 /**
2800 * Checks if getData() works with type "fullrootline"
2801 *
2802 * @test
2803 */
2804 public function getDataWithTypeFullrootline()
2805 {
2806 $rootline1 = array(
2807 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2808 );
2809 $rootline2 = array(
2810 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2811 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2812 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2813 );
2814
2815 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
2816 $GLOBALS['TSFE']->rootLine = $rootline2;
2817 $this->assertEquals('field2', $this->subject->getData('fullrootline:-1,testfield'));
2818 }
2819
2820 /**
2821 * Checks if getData() works with type "date"
2822 *
2823 * @test
2824 */
2825 public function getDataWithTypeDate()
2826 {
2827 $format = 'Y-M-D';
2828 $defaultFormat = 'd/m Y';
2829
2830 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject->getData('date:' . $format));
2831 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject->getData('date'));
2832 }
2833
2834 /**
2835 * Checks if getData() works with type "page"
2836 *
2837 * @test
2838 */
2839 public function getDataWithTypePage()
2840 {
2841 $uid = rand();
2842 $GLOBALS['TSFE']->page['uid'] = $uid;
2843 $this->assertEquals($uid, $this->subject->getData('page:uid'));
2844 }
2845
2846 /**
2847 * Checks if getData() works with type "current"
2848 *
2849 * @test
2850 */
2851 public function getDataWithTypeCurrent()
2852 {
2853 $key = $this->getUniqueId('someKey');
2854 $value = $this->getUniqueId('someValue');
2855 $this->subject->data[$key] = $value;
2856 $this->subject->currentValKey = $key;
2857 $this->assertEquals($value, $this->subject->getData('current'));
2858 }
2859
2860 /**
2861 * Checks if getData() works with type "db"
2862 *
2863 * @test
2864 */
2865 public function getDataWithTypeDb()
2866 {
2867 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2868
2869 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2870 $this->assertEquals($dummyRecord['title'], $this->subject->getData('db:tt_content:106:title'));
2871 }
2872
2873 /**
2874 * Checks if getData() works with type "lll"
2875 *
2876 * @test
2877 */
2878 public function getDataWithTypeLll()
2879 {
2880 $key = $this->getUniqueId('someKey');
2881 $value = $this->getUniqueId('someValue');
2882 $language = $this->getUniqueId('someLanguage');
2883 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
2884 $GLOBALS['TSFE']->lang = $language;
2885
2886 $this->assertEquals($value, $this->subject->getData('lll:' . $key));
2887 }
2888
2889 /**
2890 * Checks if getData() works with type "path"
2891 *
2892 * @test
2893 */
2894 public function getDataWithTypePath()
2895 {
2896 $filenameIn = $this->getUniqueId('someValue');
2897 $filenameOut = $this->getUniqueId('someValue');
2898 $this->templateServiceMock->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2899 $this->assertEquals($filenameOut, $this->subject->getData('path:' . $filenameIn));
2900 }
2901
2902 /**
2903 * Checks if getData() works with type "parentRecordNumber"
2904 *
2905 * @test
2906 */
2907 public function getDataWithTypeParentRecordNumber()
2908 {
2909 $recordNumber = rand();
2910 $this->subject->parentRecordNumber = $recordNumber;
2911 $this->assertEquals($recordNumber, $this->subject->getData('cobj:parentRecordNumber'));
2912 }
2913
2914 /**
2915 * Checks if getData() works with type "debug:rootLine"
2916 *
2917 * @test
2918 */
2919 public function getDataWithTypeDebugRootline()
2920 {
2921 $rootline = array(
2922 0 => array('uid' => 1, 'title' => 'title1'),
2923 1 => array('uid' => 2, 'title' => 'title2'),
2924 2 => array('uid' => 3, 'title' => ''),
2925 );
2926 $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)';
2927 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2928
2929 $result = $this->subject->getData('debug:rootLine');
2930 $cleanedResult = strip_tags($result);
2931 $cleanedResult = str_replace("\r", '', $cleanedResult);
2932 $cleanedResult = str_replace("\n", '', $cleanedResult);
2933 $cleanedResult = str_replace("\t", '', $cleanedResult);
2934 $cleanedResult = str_replace(' ', '', $cleanedResult);
2935
2936 $this->assertEquals($expectedResult, $cleanedResult);
2937 }
2938
2939 /**
2940 * Checks if getData() works with type "debug:fullRootLine"
2941 *
2942 * @test
2943 */
2944 public function getDataWithTypeDebugFullRootline()
2945 {
2946 $rootline = array(
2947 0 => array('uid' => 1, 'title' => 'title1'),
2948 1 => array('uid' => 2, 'title' => 'title2'),
2949 2 => array('uid' => 3, 'title' => ''),
2950 );
2951 $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)';
2952 $GLOBALS['TSFE']->rootLine = $rootline;
2953
2954 $result = $this->subject->getData('debug:fullRootLine');
2955 $cleanedResult = strip_tags($result);
2956 $cleanedResult = str_replace("\r", '', $cleanedResult);
2957 $cleanedResult = str_replace("\n", '', $cleanedResult);
2958 $cleanedResult = str_replace("\t", '', $cleanedResult);
2959 $cleanedResult = str_replace(' ', '', $cleanedResult);
2960
2961 $this->assertEquals($expectedResult, $cleanedResult);
2962 }
2963
2964 /**
2965 * Checks if getData() works with type "debug:data"
2966 *
2967 * @test
2968 */
2969 public function getDataWithTypeDebugData()
2970 {
2971 $key = $this->getUniqueId('someKey');
2972 $value = $this->getUniqueId('someValue');
2973 $this->subject->data = array($key => $value);
2974
2975 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2976
2977 $result = $this->subject->getData('debug:data');
2978 $cleanedResult = strip_tags($result);
2979 $cleanedResult = str_replace("\r", '', $cleanedResult);
2980 $cleanedResult = str_replace("\n", '', $cleanedResult);
2981 $cleanedResult = str_replace("\t", '', $cleanedResult);
2982 $cleanedResult = str_replace(' ', '', $cleanedResult);
2983
2984 $this->assertEquals($expectedResult, $cleanedResult);
2985 }
2986
2987 /**
2988 * Checks if getData() works with type "debug:register"
2989 *
2990 * @test
2991 */
2992 public function getDataWithTypeDebugRegister()
2993 {
2994 $key = $this->getUniqueId('someKey');
2995 $value = $this->getUniqueId('someValue');
2996 $GLOBALS['TSFE']->register = array($key => $value);
2997
2998 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2999
3000 $result = $this->subject->getData('debug:register');
3001 $cleanedResult = strip_tags($result);
3002 $cleanedResult = str_replace("\r", '', $cleanedResult);
3003 $cleanedResult = str_replace("\n", '', $cleanedResult);
3004 $cleanedResult = str_replace("\t", '', $cleanedResult);
3005 $cleanedResult = str_replace(' ', '', $cleanedResult);
3006
3007 $this->assertEquals($expectedResult, $cleanedResult);
3008 }
3009
3010 /**
3011 * Checks if getData() works with type "data:page"
3012 *
3013 * @test
3014 */
3015 public function getDataWithTypeDebugPage()
3016 {
3017 $uid = rand();
3018 $GLOBALS['TSFE']->page = array('uid' => $uid);
3019
3020 $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
3021
3022 $result = $this->subject->getData('debug:page');
<