[TASK] Removes extra empty lines
[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_stdWrapValue test
2064 *
2065 * @return array
2066 */
2067 public function stdWrap_stdWrapValueDataProvider()
2068 {
2069 return array(
2070 'only key returns value' => array(
2071 'ifNull',
2072 array(
2073 'ifNull' => '1',
2074 ),
2075 '',
2076 '1',
2077 ),
2078 'array without key returns empty string' => array(
2079 'ifNull',
2080 array(
2081 'ifNull.' => '1',
2082 ),
2083 '',
2084 '',
2085 ),
2086 'array without key returns default' => array(
2087 'ifNull',
2088 array(
2089 'ifNull.' => '1',
2090 ),
2091 'default',
2092 'default',
2093 ),
2094 'non existing key returns default' => array(
2095 'ifNull',
2096 array(
2097 'noTrimWrap' => 'test',
2098 'noTrimWrap.' => '1',
2099 ),
2100 'default',
2101 'default',
2102 ),
2103 'existing key and array returns stdWrap' => array(
2104 'test',
2105 array(
2106 'test' => 'value',
2107 'test.' => array('case' => 'upper'),
2108 ),
2109 'default',
2110 'VALUE'
2111 ),
2112 );
2113 }
2114
2115 /**
2116 * @param string $key
2117 * @param array $configuration
2118 * @param string $defaultValue
2119 * @param string $expected
2120 * @dataProvider stdWrap_stdWrapValueDataProvider
2121 * @test
2122 */
2123 public function stdWrap_stdWrapValue($key, array $configuration, $defaultValue, $expected)
2124 {
2125 $result = $this->subject->stdWrapValue($key, $configuration, $defaultValue);
2126 $this->assertEquals($expected, $result);
2127 }
2128
2129 /**
2130 * @param string|NULL $content
2131 * @param array $configuration
2132 * @param string $expected
2133 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
2134 * @test
2135 */
2136 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected)
2137 {
2138 $result = $this->subject->stdWrap_ifNull($content, $configuration);
2139 $this->assertEquals($expected, $result);
2140 }
2141
2142 /**
2143 * Data provider for stdWrap_ifNullDeterminesNullValues test
2144 *
2145 * @return array
2146 */
2147 public function stdWrap_ifNullDeterminesNullValuesDataProvider()
2148 {
2149 return array(
2150 'null value' => array(
2151 null,
2152 array(
2153 'ifNull' => '1',
2154 ),
2155 '1',
2156 ),
2157 'zero value' => array(
2158 '0',
2159 array(
2160 'ifNull' => '1',
2161 ),
2162 '0',
2163 ),
2164 );
2165 }
2166
2167 /**
2168 * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
2169 *
2170 * @return array
2171 */
2172 public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider()
2173 {
2174 return array(
2175 'null value' => array(
2176 null,
2177 array(
2178 'ifEmpty' => '1',
2179 ),
2180 '1',
2181 ),
2182 'empty value' => array(
2183 '',
2184 array(
2185 'ifEmpty' => '1',
2186 ),
2187 '1',
2188 ),
2189 'string value' => array(
2190 'string',
2191 array(
2192 'ifEmpty' => '1',
2193 ),
2194 'string',
2195 ),
2196 'empty string value' => array(
2197 ' ',
2198 array(
2199 'ifEmpty' => '1',
2200 ),
2201 '1',
2202 ),
2203 );
2204 }
2205
2206 /**
2207 * @param string|NULL $content
2208 * @param array $configuration
2209 * @param string $expected
2210 * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
2211 * @test
2212 */
2213 public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected)
2214 {
2215 $result = $this->subject->stdWrap_ifEmpty($content, $configuration);
2216 $this->assertEquals($expected, $result);
2217 }
2218
2219 /**
2220 * @param $content
2221 * @param array $configuration
2222 * @param $expected
2223 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
2224 * @test
2225 */
2226 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected)
2227 {
2228 $result = $this->subject->stdWrap_noTrimWrap($content, $configuration);
2229 $this->assertEquals($expected, $result);
2230 }
2231
2232 /**
2233 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
2234 *
2235 * @return array
2236 */
2237 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider()
2238 {
2239 return array(
2240 'No char given' => array(
2241 'middle',
2242 array(
2243 'noTrimWrap' => '| left | right |',
2244 ),
2245 ' left middle right '
2246 ),
2247 'Zero char given' => array(
2248 'middle',
2249 array(
2250 'noTrimWrap' => '0 left 0 right 0',
2251 'noTrimWrap.' => array('splitChar' => '0'),
2252
2253 ),
2254 ' left middle right '
2255 ),
2256 'Default char given' => array(
2257 'middle',
2258 array(
2259 'noTrimWrap' => '| left | right |',
2260 'noTrimWrap.' => array('splitChar' => '|'),
2261 ),
2262 ' left middle right '
2263 ),
2264 'Split char is a' => array(
2265 'middle',
2266 array(
2267 'noTrimWrap' => 'a left a right a',
2268 'noTrimWrap.' => array('splitChar' => 'a'),
2269 ),
2270 ' left middle right '
2271 ),
2272 'Split char is multi-char (ab)' => array(
2273 'middle',
2274 array(
2275 'noTrimWrap' => 'ab left ab right ab',
2276 'noTrimWrap.' => array('splitChar' => 'ab'),
2277 ),
2278 ' left middle right '
2279 ),
2280 'Split char accepts stdWrap' => array(
2281 'middle',
2282 array(
2283 'noTrimWrap' => 'abc left abc right abc',
2284 'noTrimWrap.' => array(
2285 'splitChar' => 'b',
2286 'splitChar.' => array('wrap' => 'a|c'),
2287 ),
2288 ),
2289 ' left middle right '
2290 ),
2291 );
2292 }
2293
2294 /**
2295 * @param array $expectedTags
2296 * @param array $configuration
2297 * @test
2298 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
2299 */
2300 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration)
2301 {
2302 $this->subject->stdWrap_addPageCacheTags('', $configuration);
2303 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock->_get('pageCacheTags'));
2304 }
2305
2306 /**
2307 * @return array
2308 */
2309 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider()
2310 {
2311 return array(
2312 'No Tag' => array(
2313 array(),
2314 array('addPageCacheTags' => ''),
2315 ),
2316 'Two expectedTags' => array(
2317 array('tag1', 'tag2'),
2318 array('addPageCacheTags' => 'tag1,tag2'),
2319 ),
2320 'Two expectedTags plus one with stdWrap' => array(
2321 array('tag1', 'tag2', 'tag3'),
2322 array(
2323 'addPageCacheTags' => 'tag1,tag2',
2324 'addPageCacheTags.' => array('wrap' => '|,tag3')
2325 ),
2326 ),
2327 );
2328 }
2329
2330 /**
2331 * Data provider for stdWrap_encodeForJavaScriptValue test
2332 *
2333 * @return array multi-dimensional array with the second level like this:
2334 * @see encodeForJavaScriptValue
2335 */
2336 public function stdWrap_encodeForJavaScriptValueDataProvider()
2337 {
2338 return array(
2339 'double quote in string' => array(
2340 'double quote"',
2341 array(),
2342 '\'double\u0020quote\u0022\''
2343 ),
2344 'backslash in string' => array(
2345 'backslash \\',
2346 array(),
2347 '\'backslash\u0020\u005C\''
2348 ),
2349 'exclamation mark' => array(
2350 'exclamation!',
2351 array(),
2352 '\'exclamation\u0021\''
2353 ),
2354 'whitespace tab, newline and carriage return' => array(
2355 "white\tspace\ns\r",
2356 array(),
2357 '\'white\u0009space\u000As\u000D\''
2358 ),
2359 'single quote in string' => array(
2360 'single quote \'',
2361 array(),
2362 '\'single\u0020quote\u0020\u0027\''
2363 ),
2364 'tag' => array(
2365 '<tag>',
2366 array(),
2367 '\'\u003Ctag\u003E\''
2368 ),
2369 'ampersand in string' => array(
2370 'amper&sand',
2371 array(),
2372 '\'amper\u0026sand\''
2373 ),
2374 );
2375 }
2376
2377 /**
2378 * Check if encodeForJavaScriptValue works properly
2379 *
2380 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
2381 * @test
2382 */
2383 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected)
2384 {
2385 $result = $this->subject->stdWrap_encodeForJavaScriptValue($input, $conf);
2386 $this->assertEquals($expected, $result);
2387 }
2388
2389 ///////////////////////////////
2390 // Tests concerning getData()
2391 ///////////////////////////////
2392
2393 /**
2394 * @return array
2395 */
2396 public function getDataWithTypeGpDataProvider()
2397 {
2398 return array(
2399 'Value in get-data' => array('onlyInGet', 'GetValue'),
2400 'Value in post-data' => array('onlyInPost', 'PostValue'),
2401 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
2402 );
2403 }
2404
2405 /**
2406 * Checks if getData() works with type "gp"
2407 *
2408 * @test
2409 * @dataProvider getDataWithTypeGpDataProvider
2410 */
2411 public function getDataWithTypeGp($key, $expectedValue)
2412 {
2413 $_GET = array(
2414 'onlyInGet' => 'GetValue',
2415 'inGetAndPost' => 'ValueInGet',
2416 );
2417 $_POST = array(
2418 'onlyInPost' => 'PostValue',
2419 'inGetAndPost' => 'ValueInPost',
2420 );
2421 $this->assertEquals($expectedValue, $this->subject->getData('gp:' . $key));
2422 }
2423
2424 /**
2425 * Checks if getData() works with type "tsfe"
2426 *
2427 * @test
2428 */
2429 public function getDataWithTypeTsfe()
2430 {
2431 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('tsfe:renderCharset'));
2432 }
2433
2434 /**
2435 * Checks if getData() works with type "getenv"
2436 *
2437 * @test
2438 */
2439 public function getDataWithTypeGetenv()
2440 {
2441 $envName = $this->getUniqueId('frontendtest');
2442 $value = $this->getUniqueId('someValue');
2443 putenv($envName . '=' . $value);
2444 $this->assertEquals($value, $this->subject->getData('getenv:' . $envName));
2445 }
2446
2447 /**
2448 * Checks if getData() works with type "getindpenv"
2449 *
2450 * @test
2451 */
2452 public function getDataWithTypeGetindpenv()
2453 {
2454 $this->subject->expects($this->once())->method('getEnvironmentVariable')
2455 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
2456 $this->assertEquals('dummyPath', $this->subject->getData('getindpenv:SCRIPT_FILENAME'));
2457 }
2458
2459 /**
2460 * Checks if getData() works with type "field"
2461 *
2462 * @test
2463 */
2464 public function getDataWithTypeField()
2465 {
2466 $key = 'someKey';
2467 $value = 'someValue';
2468 $field = array($key => $value);
2469
2470 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2471 }
2472
2473 /**
2474 * Checks if getData() works with type "field" of the field content
2475 * is multi-dimensional (e.g. an array)
2476 *
2477 * @test
2478 */
2479 public function getDataWithTypeFieldAndFieldIsMultiDimensional()
2480 {
2481 $key = 'somekey|level1|level2';
2482 $value = 'somevalue';
2483 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
2484
2485 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2486 }
2487
2488 /**
2489 * Basic check if getData gets the uid of a file object
2490 *
2491 * @test
2492 */
2493 public function getDataWithTypeFileReturnsUidOfFileObject()
2494 {
2495 $uid = $this->getUniqueId();
2496 $file = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(), '', false);
2497 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
2498 $this->subject->setCurrentFile($file);
2499 $this->assertEquals($uid, $this->subject->getData('file:current:uid'));
2500 }
2501
2502 /**
2503 * Checks if getData() works with type "parameters"
2504 *
2505 * @test
2506 */
2507 public function getDataWithTypeParameters()
2508 {
2509 $key = $this->getUniqueId('someKey');
2510 $value = $this->getUniqueId('someValue');
2511 $this->subject->parameters[$key] = $value;
2512
2513 $this->assertEquals($value, $this->subject->getData('parameters:' . $key));
2514 }
2515
2516 /**
2517 * Checks if getData() works with type "register"
2518 *
2519 * @test
2520 */
2521 public function getDataWithTypeRegister()
2522 {
2523 $key = $this->getUniqueId('someKey');
2524 $value = $this->getUniqueId('someValue');
2525 $GLOBALS['TSFE']->register[$key] = $value;
2526
2527 $this->assertEquals($value, $this->subject->getData('register:' . $key));
2528 }
2529
2530 /**
2531 * Checks if getData() works with type "level"
2532 *
2533 * @test
2534 */
2535 public function getDataWithTypeLevel()
2536 {
2537 $rootline = array(
2538 0 => array('uid' => 1, 'title' => 'title1'),
2539 1 => array('uid' => 2, 'title' => 'title2'),
2540 2 => array('uid' => 3, 'title' => 'title3'),
2541 );
2542
2543 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2544 $this->assertEquals(2, $this->subject->getData('level'));
2545 }
2546
2547 /**
2548 * Checks if getData() works with type "global"
2549 *
2550 * @test
2551 */
2552 public function getDataWithTypeGlobal()
2553 {
2554 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('global:TSFE|renderCharset'));
2555 }
2556
2557 /**
2558 * Checks if getData() works with type "leveltitle"
2559 *
2560 * @test
2561 */
2562 public function getDataWithTypeLeveltitle()
2563 {
2564 $rootline = array(
2565 0 => array('uid' => 1, 'title' => 'title1'),
2566 1 => array('uid' => 2, 'title' => 'title2'),
2567 2 => array('uid' => 3, 'title' => ''),
2568 );
2569
2570 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2571 $this->assertEquals('', $this->subject->getData('leveltitle:-1'));
2572 // since "title3" is not set, it will slide to "title2"
2573 $this->assertEquals('title2', $this->subject->getData('leveltitle:-1,slide'));
2574 }
2575
2576 /**
2577 * Checks if getData() works with type "levelmedia"
2578 *
2579 * @test
2580 */
2581 public function getDataWithTypeLevelmedia()
2582 {
2583 $rootline = array(
2584 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
2585 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
2586 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
2587 );
2588
2589 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2590 $this->assertEquals('', $this->subject->getData('levelmedia:-1'));
2591 // since "title3" is not set, it will slide to "title2"
2592 $this->assertEquals('media2', $this->subject->getData('levelmedia:-1,slide'));
2593 }
2594
2595 /**
2596 * Checks if getData() works with type "leveluid"
2597 *
2598 * @test
2599 */
2600 public function getDataWithTypeLeveluid()
2601 {
2602 $rootline = array(
2603 0 => array('uid' => 1, 'title' => 'title1'),
2604 1 => array('uid' => 2, 'title' => 'title2'),
2605 2 => array('uid' => 3, 'title' => 'title3'),
2606 );
2607
2608 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2609 $this->assertEquals(3, $this->subject->getData('leveluid:-1'));
2610 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
2611 $this->assertEquals(3, $this->subject->getData('leveluid:-1,slide'));
2612 }
2613
2614 /**
2615 * Checks if getData() works with type "levelfield"
2616 *
2617 * @test
2618 */
2619 public function getDataWithTypeLevelfield()
2620 {
2621 $rootline = array(
2622 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2623 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2624 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2625 );
2626
2627 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2628 $this->assertEquals('', $this->subject->getData('levelfield:-1,testfield'));
2629 $this->assertEquals('field2', $this->subject->getData('levelfield:-1,testfield,slide'));
2630 }
2631
2632 /**
2633 * Checks if getData() works with type "fullrootline"
2634 *
2635 * @test
2636 */
2637 public function getDataWithTypeFullrootline()
2638 {
2639 $rootline1 = array(
2640 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2641 );
2642 $rootline2 = array(
2643 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2644 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2645 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2646 );
2647
2648 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
2649 $GLOBALS['TSFE']->rootLine = $rootline2;
2650 $this->assertEquals('field2', $this->subject->getData('fullrootline:-1,testfield'));
2651 }
2652
2653 /**
2654 * Checks if getData() works with type "date"
2655 *
2656 * @test
2657 */
2658 public function getDataWithTypeDate()
2659 {
2660 $format = 'Y-M-D';
2661 $defaultFormat = 'd/m Y';
2662
2663 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject->getData('date:' . $format));
2664 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject->getData('date'));
2665 }
2666
2667 /**
2668 * Checks if getData() works with type "page"
2669 *
2670 * @test
2671 */
2672 public function getDataWithTypePage()
2673 {
2674 $uid = rand();
2675 $GLOBALS['TSFE']->page['uid'] = $uid;
2676 $this->assertEquals($uid, $this->subject->getData('page:uid'));
2677 }
2678
2679 /**
2680 * Checks if getData() works with type "current"
2681 *
2682 * @test
2683 */
2684 public function getDataWithTypeCurrent()
2685 {
2686 $key = $this->getUniqueId('someKey');
2687 $value = $this->getUniqueId('someValue');
2688 $this->subject->data[$key] = $value;
2689 $this->subject->currentValKey = $key;
2690 $this->assertEquals($value, $this->subject->getData('current'));
2691 }
2692
2693 /**
2694 * Checks if getData() works with type "db"
2695 *
2696 * @test
2697 */
2698 public function getDataWithTypeDb()
2699 {
2700 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2701
2702 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2703 $this->assertEquals($dummyRecord['title'], $this->subject->getData('db:tt_content:106:title'));
2704 }
2705
2706 /**
2707 * Checks if getData() works with type "lll"
2708 *
2709 * @test
2710 */
2711 public function getDataWithTypeLll()
2712 {
2713 $key = $this->getUniqueId('someKey');
2714 $value = $this->getUniqueId('someValue');
2715 $language = $this->getUniqueId('someLanguage');
2716 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
2717 $GLOBALS['TSFE']->lang = $language;
2718
2719 $this->assertEquals($value, $this->subject->getData('lll:' . $key));
2720 }
2721
2722 /**
2723 * Checks if getData() works with type "path"
2724 *
2725 * @test
2726 */
2727 public function getDataWithTypePath()
2728 {
2729 $filenameIn = $this->getUniqueId('someValue');
2730 $filenameOut = $this->getUniqueId('someValue');
2731 $this->templateServiceMock->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2732 $this->assertEquals($filenameOut, $this->subject->getData('path:' . $filenameIn));
2733 }
2734
2735 /**
2736 * Checks if getData() works with type "parentRecordNumber"
2737 *
2738 * @test
2739 */
2740 public function getDataWithTypeParentRecordNumber()
2741 {
2742 $recordNumber = rand();
2743 $this->subject->parentRecordNumber = $recordNumber;
2744 $this->assertEquals($recordNumber, $this->subject->getData('cobj:parentRecordNumber'));
2745 }
2746
2747 /**
2748 * Checks if getData() works with type "debug:rootLine"
2749 *
2750 * @test
2751 */
2752 public function getDataWithTypeDebugRootline()
2753 {
2754 $rootline = array(
2755 0 => array('uid' => 1, 'title' => 'title1'),
2756 1 => array('uid' => 2, 'title' => 'title2'),
2757 2 => array('uid' => 3, 'title' => ''),
2758 );
2759 $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)';
2760 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2761
2762 $result = $this->subject->getData('debug:rootLine');
2763 $cleanedResult = strip_tags($result);
2764 $cleanedResult = str_replace("\r", '', $cleanedResult);
2765 $cleanedResult = str_replace("\n", '', $cleanedResult);
2766 $cleanedResult = str_replace("\t", '', $cleanedResult);
2767 $cleanedResult = str_replace(' ', '', $cleanedResult);
2768
2769 $this->assertEquals($expectedResult, $cleanedResult);
2770 }
2771
2772 /**
2773 * Checks if getData() works with type "debug:fullRootLine"
2774 *
2775 * @test
2776 */
2777 public function getDataWithTypeDebugFullRootline()
2778 {
2779 $rootline = array(
2780 0 => array('uid' => 1, 'title' => 'title1'),
2781 1 => array('uid' => 2, 'title' => 'title2'),
2782 2 => array('uid' => 3, 'title' => ''),
2783 );
2784 $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)';
2785 $GLOBALS['TSFE']->rootLine = $rootline;
2786
2787 $result = $this->subject->getData('debug:fullRootLine');
2788 $cleanedResult = strip_tags($result);
2789 $cleanedResult = str_replace("\r", '', $cleanedResult);
2790 $cleanedResult = str_replace("\n", '', $cleanedResult);
2791 $cleanedResult = str_replace("\t", '', $cleanedResult);
2792 $cleanedResult = str_replace(' ', '', $cleanedResult);
2793
2794 $this->assertEquals($expectedResult, $cleanedResult);
2795 }
2796
2797 /**
2798 * Checks if getData() works with type "debug:data"
2799 *
2800 * @test
2801 */
2802 public function getDataWithTypeDebugData()
2803 {
2804 $key = $this->getUniqueId('someKey');
2805 $value = $this->getUniqueId('someValue');
2806 $this->subject->data = array($key => $value);
2807
2808 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2809
2810 $result = $this->subject->getData('debug:data');
2811 $cleanedResult = strip_tags($result);
2812 $cleanedResult = str_replace("\r", '', $cleanedResult);
2813 $cleanedResult = str_replace("\n", '', $cleanedResult);
2814 $cleanedResult = str_replace("\t", '', $cleanedResult);
2815 $cleanedResult = str_replace(' ', '', $cleanedResult);
2816
2817 $this->assertEquals($expectedResult, $cleanedResult);
2818 }
2819
2820 /**
2821 * Checks if getData() works with type "debug:register"
2822 *
2823 * @test
2824 */
2825 public function getDataWithTypeDebugRegister()
2826 {
2827 $key = $this->getUniqueId('someKey');
2828 $value = $this->getUniqueId('someValue');
2829 $GLOBALS['TSFE']->register = array($key => $value);
2830
2831 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2832
2833 $result = $this->subject->getData('debug:register');
2834 $cleanedResult = strip_tags($result);
2835 $cleanedResult = str_replace("\r", '', $cleanedResult);
2836 $cleanedResult = str_replace("\n", '', $cleanedResult);
2837 $cleanedResult = str_replace("\t", '', $cleanedResult);
2838 $cleanedResult = str_replace(' ', '', $cleanedResult);
2839
2840 $this->assertEquals($expectedResult, $cleanedResult);
2841 }
2842
2843 /**
2844 * Checks if getData() works with type "data:page"
2845 *
2846 * @test
2847 */
2848 public function getDataWithTypeDebugPage()
2849 {
2850 $uid = rand();
2851 $GLOBALS['TSFE']->page = array('uid' => $uid);
2852
2853 $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
2854
2855 $result = $this->subject->getData('debug:page');
2856 $cleanedResult = strip_tags($result);
2857 $cleanedResult = str_replace("\r", '', $cleanedResult);
2858 $cleanedResult = str_replace("\n", '', $cleanedResult);
2859 $cleanedResult = str_replace("\t", '', $cleanedResult);
2860 $cleanedResult = str_replace(' ', '', $cleanedResult);
2861
2862 $this->assertEquals($expectedResult, $cleanedResult);
2863 }
2864
2865 /**
2866 * @test
2867 */
2868 public function getTreeListReturnsChildPageUids()
2869 {
2870 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(null));
2871 $GLOBALS['TSFE']->sys_page
2872 ->expects($this->any())
2873 ->method('getRawRecord')
2874 ->will(
2875 $this->onConsecutiveCalls(
2876 array('uid' => 17),
2877 array('uid' => 321),
2878 array('uid' => 719),
2879 array('uid' => 42)
2880 )
2881 );
2882
2883 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(null));
2884 $GLOBALS['TYPO3_DB']
2885 ->expects($this->any())
2886 ->method('exec_SELECTgetRows')
2887 ->will(
2888 $this->onConsecutiveCalls(
2889 array(
2890 array('uid' => 321)
2891 ),
2892 array(
2893 array('uid' => 719)
2894 ),
2895 array(
2896 array('uid' => 42)
2897 )
2898 )
2899 );
2900 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2901 // 17 is positive, we expect 17 NOT to be included in result
2902 $result = $this->subject->getTreeList(17, 5, 0, true);
2903 $expectedResult = '42,719,321';
2904 $this->assertEquals($expectedResult, $result);
2905 }
2906
2907 /**
2908 * @test
2909 */
2910 public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue()
2911 {
2912 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(null));
2913 $GLOBALS['TSFE']->sys_page
2914 ->expects($this->any())
2915 ->method('getRawRecord')
2916 ->will(
2917 $this->onConsecutiveCalls(
2918 array('uid' => 17),
2919 array('uid' => 321),
2920 array('uid' => 719),
2921 array('uid' => 42)
2922 )
2923 );
2924
2925 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(null));
2926 $GLOBALS['TYPO3_DB']
2927 ->expects($this->any())
2928 ->method('exec_SELECTgetRows')
2929 ->will(
2930 $this->onConsecutiveCalls(
2931 array(
2932 array('uid' => 321)
2933 ),
2934 array(
2935 array('uid' => 719)
2936 ),
2937 array(
2938 array('uid' => 42)
2939 )
2940 )
2941 );
2942 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2943 // 17 is negative, we expect 17 to be included in result
2944 $result = $this->subject->getTreeList(-17, 5, 0, true);
2945 $expectedResult = '42,719,321,17';
2946 $this->assertEquals($expectedResult, $result);
2947 }
2948
2949 /**
2950 * @test
2951 */
2952 public function aTagParamsHasLeadingSpaceIfNotEmpty()
2953 {
2954 $aTagParams = $this->subject->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2955 $this->assertEquals(' data-test="testdata"', $aTagParams);
2956 }
2957
2958 /**
2959 * @test
2960 */
2961 public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams()
2962 {
2963 $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
2964 $aTagParams = $this->subject->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2965 $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams);
2966 }
2967
2968 /**
2969 * @test
2970 */
2971 public function aTagParamsHasNoLeadingSpaceIfEmpty()
2972 {
2973 // make sure global ATagParams are empty
2974 $GLOBALS['TSFE']->ATagParams = '';
2975 $aTagParams = $this->subject->getATagParams(array('ATagParams' => ''));
2976 $this->assertEquals('', $aTagParams);
2977 }
2978
2979 /**
2980 * @return array
2981 */
2982 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider()
2983 {
2984 return array(
2985 array(null, null),
2986 array('', null),
2987 array('', array()),
2988 array('fooo', array('foo' => 'bar'))
2989 );
2990 }
2991
2992 /**
2993 * Make sure that the rendering falls back to the classic <img style if nothing else is found
2994 *
2995 * @test
2996 * @dataProvider getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider
2997 * @param string $key
2998 * @param array $configuration
2999 */
3000 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFound($key, $configuration)
3001 {
3002 $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
3003 $result = $this->subject->getImageTagTemplate($key, $configuration);
3004 $this->assertEquals($result, $defaultImgTagTemplate);
3005 }
3006
3007 /**
3008 * @return array
3009 */
3010 public function getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider()
3011 {
3012 return array(
3013 array(
3014 'foo',
3015 array(
3016 'layout.' => array(
3017 'foo.' => array(
3018 'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
3019 )
3020 )
3021 ),
3022 '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
3023 )
3024
3025 );
3026 }
3027