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