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