e2bf614fd851bf35e3ef23fe18fac6bbcd86ac47
[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_strftime test
1660 *
1661 * @return array multi-dimensional array with the second level like this:
1662 * @see stdWrap_strftime
1663 */
1664 public function stdWrap_strftimeReturnsFormattedStringDataProvider() {
1665 $data = array(
1666 'given timestamp' => array(
1667 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1668 array(
1669 'strftime' => '%d-%m-%Y',
1670 ),
1671 ),
1672 'empty string' => array(
1673 '',
1674 array(
1675 'strftime' => '%d-%m-%Y',
1676 ),
1677 ),
1678 'testing null' => array(
1679 NULL,
1680 array(
1681 'strftime' => '%d-%m-%Y',
1682 ),
1683 ),
1684 );
1685 return $data;
1686 }
1687
1688 /**
1689 * @test
1690 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1691 */
1692 public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1693 // Set exec_time to a hard timestamp
1694 $GLOBALS['EXEC_TIME'] = 1346500800;
1695 // Save current timezone and set to UTC to make the system under test behave
1696 // the same in all server timezone settings
1697 $timezoneBackup = date_default_timezone_get();
1698 date_default_timezone_set('UTC');
1699
1700 $result = $this->subject->stdWrap_strftime($content, $conf);
1701
1702 // Reset timezone
1703 date_default_timezone_set($timezoneBackup);
1704
1705 $this->assertEquals('01-09-2012', $result);
1706 }
1707
1708 /**
1709 * Data provider for the stdWrap_strtotime test
1710 *
1711 * @return array
1712 * @see stdWrap_strtotime
1713 */
1714 public function stdWrap_strtotimeReturnsTimestampDataProvider() {
1715 return array(
1716 'date from content' => array(
1717 '2014-12-04',
1718 array(
1719 'strtotime' => '1',
1720 ),
1721 1417651200,
1722 ),
1723 'manipulation of date from content' => array(
1724 '2014-12-04',
1725 array(
1726 'strtotime' => '+ 2 weekdays',
1727 ),
1728 1417996800,
1729 ),
1730 'date from configuration' => array(
1731 '',
1732 array(
1733 'strtotime' => '2014-12-04',
1734 ),
1735 1417651200,
1736 ),
1737 'manipulation of date from configuration' => array(
1738 '',
1739 array(
1740 'strtotime' => '2014-12-04 + 2 weekdays',
1741 ),
1742 1417996800,
1743 ),
1744 'empty input' => array(
1745 '',
1746 array(
1747 'strtotime' => '1',
1748 ),
1749 FALSE,
1750 ),
1751 'date from content and configuration' => array(
1752 '2014-12-04',
1753 array(
1754 'strtotime' => '2014-12-05',
1755 ),
1756 FALSE,
1757 ),
1758 );
1759 }
1760
1761 /**
1762 * @param string|NULL $content
1763 * @param array $configuration
1764 * @param int $expected
1765 * @dataProvider stdWrap_strtotimeReturnsTimestampDataProvider
1766 * @test
1767 */
1768 public function stdWrap_strtotimeReturnsTimestamp($content, $configuration, $expected) {
1769 // Set exec_time to a hard timestamp
1770 $GLOBALS['EXEC_TIME'] = 1417392000;
1771 // Save current timezone and set to UTC to make the system under test behave
1772 // the same in all server timezone settings
1773 $timezoneBackup = date_default_timezone_get();
1774 date_default_timezone_set('UTC');
1775
1776 $result = $this->subject->stdWrap_strtotime($content, $configuration);
1777
1778 // Reset timezone
1779 date_default_timezone_set($timezoneBackup);
1780
1781 $this->assertEquals($expected, $result);
1782 }
1783
1784 /**
1785 * Data provider for stdWrap_stdWrapValue test
1786 *
1787 * @return array
1788 */
1789 public function stdWrap_stdWrapValueDataProvider() {
1790 return array(
1791 'only key returns value' => array(
1792 'ifNull',
1793 array(
1794 'ifNull' => '1',
1795 ),
1796 '',
1797 '1',
1798 ),
1799 'array without key returns empty string' => array(
1800 'ifNull',
1801 array(
1802 'ifNull.' => '1',
1803 ),
1804 '',
1805 '',
1806 ),
1807 'array without key returns default' => array(
1808 'ifNull',
1809 array(
1810 'ifNull.' => '1',
1811 ),
1812 'default',
1813 'default',
1814 ),
1815 'non existing key returns default' => array(
1816 'ifNull',
1817 array(
1818 'noTrimWrap' => 'test',
1819 'noTrimWrap.' => '1',
1820 ),
1821 'default',
1822 'default',
1823 ),
1824 'existing key and array returns stdWrap' => array(
1825 'test',
1826 array(
1827 'test' => 'value',
1828 'test.' => array('case' => 'upper'),
1829 ),
1830 'default',
1831 'VALUE'
1832 ),
1833 );
1834 }
1835
1836 /**
1837 * @param string $key
1838 * @param array $configuration
1839 * @param string $defaultValue
1840 * @param string $expected
1841 * @dataProvider stdWrap_stdWrapValueDataProvider
1842 * @test
1843 */
1844 public function stdWrap_stdWrapValue($key, array $configuration, $defaultValue, $expected) {
1845 $result = $this->subject->stdWrapValue($key, $configuration, $defaultValue);
1846 $this->assertEquals($expected, $result);
1847 }
1848
1849 /**
1850 * @param string|NULL $content
1851 * @param array $configuration
1852 * @param string $expected
1853 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
1854 * @test
1855 */
1856 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1857 $result = $this->subject->stdWrap_ifNull($content, $configuration);
1858 $this->assertEquals($expected, $result);
1859 }
1860
1861 /**
1862 * Data provider for stdWrap_ifNullDeterminesNullValues test
1863 *
1864 * @return array
1865 */
1866 public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
1867 return array(
1868 'null value' => array(
1869 NULL,
1870 array(
1871 'ifNull' => '1',
1872 ),
1873 '1',
1874 ),
1875 'zero value' => array(
1876 '0',
1877 array(
1878 'ifNull' => '1',
1879 ),
1880 '0',
1881 ),
1882 );
1883 }
1884
1885 /**
1886 * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
1887 *
1888 * @return array
1889 */
1890 public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider() {
1891 return array(
1892 'null value' => array(
1893 NULL,
1894 array(
1895 'ifEmpty' => '1',
1896 ),
1897 '1',
1898 ),
1899 'empty value' => array(
1900 '',
1901 array(
1902 'ifEmpty' => '1',
1903 ),
1904 '1',
1905 ),
1906 'string value' => array(
1907 'string',
1908 array(
1909 'ifEmpty' => '1',
1910 ),
1911 'string',
1912 ),
1913 'empty string value' => array(
1914 ' ',
1915 array(
1916 'ifEmpty' => '1',
1917 ),
1918 '1',
1919 ),
1920 );
1921 }
1922
1923 /**
1924 * @param string|NULL $content
1925 * @param array $configuration
1926 * @param string $expected
1927 * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
1928 * @test
1929 */
1930 public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected) {
1931 $result = $this->subject->stdWrap_ifEmpty($content, $configuration);
1932 $this->assertEquals($expected, $result);
1933 }
1934
1935 /**
1936 * @param $content
1937 * @param array $configuration
1938 * @param $expected
1939 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
1940 * @test
1941 */
1942 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1943 $result = $this->subject->stdWrap_noTrimWrap($content, $configuration);
1944 $this->assertEquals($expected, $result);
1945 }
1946
1947 /**
1948 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
1949 *
1950 * @return array
1951 */
1952 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
1953 return array(
1954 'No char given' => array(
1955 'middle',
1956 array(
1957 'noTrimWrap' => '| left | right |',
1958 ),
1959 ' left middle right '
1960 ),
1961 'Zero char given' => array(
1962 'middle',
1963 array(
1964 'noTrimWrap' => '0 left 0 right 0',
1965 'noTrimWrap.' => array('splitChar' => '0'),
1966
1967 ),
1968 ' left middle right '
1969 ),
1970 'Default char given' => array(
1971 'middle',
1972 array(
1973 'noTrimWrap' => '| left | right |',
1974 'noTrimWrap.' => array('splitChar' => '|'),
1975 ),
1976 ' left middle right '
1977 ),
1978 'Split char is a' => array(
1979 'middle',
1980 array(
1981 'noTrimWrap' => 'a left a right a',
1982 'noTrimWrap.' => array('splitChar' => 'a'),
1983 ),
1984 ' left middle right '
1985 ),
1986 'Split char is multi-char (ab)' => array(
1987 'middle',
1988 array(
1989 'noTrimWrap' => 'ab left ab right ab',
1990 'noTrimWrap.' => array('splitChar' => 'ab'),
1991 ),
1992 ' left middle right '
1993 ),
1994 'Split char accepts stdWrap' => array(
1995 'middle',
1996 array(
1997 'noTrimWrap' => 'abc left abc right abc',
1998 'noTrimWrap.' => array(
1999 'splitChar' => 'b',
2000 'splitChar.' => array('wrap' => 'a|c'),
2001 ),
2002 ),
2003 ' left middle right '
2004 ),
2005 );
2006 }
2007
2008 /**
2009 * @param array $expectedTags
2010 * @param array $configuration
2011 * @test
2012 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
2013 */
2014 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
2015 $this->subject->stdWrap_addPageCacheTags('', $configuration);
2016 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock->_get('pageCacheTags'));
2017 }
2018
2019 /**
2020 * @return array
2021 */
2022 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
2023 return array(
2024 'No Tag' => array(
2025 array(),
2026 array('addPageCacheTags' => ''),
2027 ),
2028 'Two expectedTags' => array(
2029 array('tag1', 'tag2'),
2030 array('addPageCacheTags' => 'tag1,tag2'),
2031 ),
2032 'Two expectedTags plus one with stdWrap' => array(
2033 array('tag1', 'tag2', 'tag3'),
2034 array(
2035 'addPageCacheTags' => 'tag1,tag2',
2036 'addPageCacheTags.' => array('wrap' => '|,tag3')
2037 ),
2038 ),
2039 );
2040 }
2041
2042 /**
2043 * Data provider for stdWrap_encodeForJavaScriptValue test
2044 *
2045 * @return array multi-dimensional array with the second level like this:
2046 * @see encodeForJavaScriptValue
2047 */
2048 public function stdWrap_encodeForJavaScriptValueDataProvider() {
2049 return array(
2050 'double quote in string' => array(
2051 'double quote"',
2052 array(),
2053 '\'double\u0020quote\u0022\''
2054 ),
2055 'backslash in string' => array(
2056 'backslash \\',
2057 array(),
2058 '\'backslash\u0020\u005C\''
2059 ),
2060 'exclamation mark' => array(
2061 'exclamation!',
2062 array(),
2063 '\'exclamation\u0021\''
2064 ),
2065 'whitespace tab, newline and carriage return' => array(
2066 "white\tspace\ns\r",
2067 array(),
2068 '\'white\u0009space\u000As\u000D\''
2069 ),
2070 'single quote in string' => array(
2071 'single quote \'',
2072 array(),
2073 '\'single\u0020quote\u0020\u0027\''
2074 ),
2075 'tag' => array(
2076 '<tag>',
2077 array(),
2078 '\'\u003Ctag\u003E\''
2079 ),
2080 'ampersand in string' => array(
2081 'amper&sand',
2082 array(),
2083 '\'amper\u0026sand\''
2084 ),
2085 );
2086 }
2087
2088 /**
2089 * Check if encodeForJavaScriptValue works properly
2090 *
2091 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
2092 * @test
2093 */
2094 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected) {
2095 $result = $this->subject->stdWrap_encodeForJavaScriptValue($input, $conf);
2096 $this->assertEquals($expected, $result);
2097 }
2098
2099
2100 ///////////////////////////////
2101 // Tests concerning getData()
2102 ///////////////////////////////
2103
2104 /**
2105 * @return array
2106 */
2107 public function getDataWithTypeGpDataProvider() {
2108 return array(
2109 'Value in get-data' => array('onlyInGet', 'GetValue'),
2110 'Value in post-data' => array('onlyInPost', 'PostValue'),
2111 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
2112 );
2113 }
2114
2115 /**
2116 * Checks if getData() works with type "gp"
2117 *
2118 * @test
2119 * @dataProvider getDataWithTypeGpDataProvider
2120 */
2121 public function getDataWithTypeGp($key, $expectedValue) {
2122 $_GET = array(
2123 'onlyInGet' => 'GetValue',
2124 'inGetAndPost' => 'ValueInGet',
2125 );
2126 $_POST = array(
2127 'onlyInPost' => 'PostValue',
2128 'inGetAndPost' => 'ValueInPost',
2129 );
2130 $this->assertEquals($expectedValue, $this->subject->getData('gp:' . $key));
2131 }
2132
2133 /**
2134 * Checks if getData() works with type "tsfe"
2135 *
2136 * @test
2137 */
2138 public function getDataWithTypeTsfe() {
2139 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('tsfe:renderCharset'));
2140 }
2141
2142 /**
2143 * Checks if getData() works with type "getenv"
2144 *
2145 * @test
2146 */
2147 public function getDataWithTypeGetenv() {
2148 $envName = $this->getUniqueId('frontendtest');
2149 $value = $this->getUniqueId('someValue');
2150 putenv($envName . '=' . $value);
2151 $this->assertEquals($value, $this->subject->getData('getenv:' . $envName));
2152 }
2153
2154 /**
2155 * Checks if getData() works with type "getindpenv"
2156 *
2157 * @test
2158 */
2159 public function getDataWithTypeGetindpenv() {
2160 $this->subject->expects($this->once())->method('getEnvironmentVariable')
2161 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
2162 $this->assertEquals('dummyPath', $this->subject->getData('getindpenv:SCRIPT_FILENAME'));
2163 }
2164
2165 /**
2166 * Checks if getData() works with type "field"
2167 *
2168 * @test
2169 */
2170 public function getDataWithTypeField() {
2171 $key = 'someKey';
2172 $value = 'someValue';
2173 $field = array($key => $value);
2174
2175 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2176 }
2177
2178 /**
2179 * Checks if getData() works with type "field" of the field content
2180 * is multi-dimensional (e.g. an array)
2181 *
2182 * @test
2183 */
2184 public function getDataWithTypeFieldAndFieldIsMultiDimensional() {
2185 $key = 'somekey|level1|level2';
2186 $value = 'somevalue';
2187 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
2188
2189 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2190 }
2191
2192 /**
2193 * Basic check if getData gets the uid of a file object
2194 *
2195 * @test
2196 */
2197 public function getDataWithTypeFileReturnsUidOfFileObject() {
2198 $uid = $this->getUniqueId();
2199 $file = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(), '', FALSE);
2200 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
2201 $this->subject->setCurrentFile($file);
2202 $this->assertEquals($uid, $this->subject->getData('file:current:uid'));
2203 }
2204
2205 /**
2206 * Checks if getData() works with type "parameters"
2207 *
2208 * @test
2209 */
2210 public function getDataWithTypeParameters() {
2211 $key = $this->getUniqueId('someKey');
2212 $value = $this->getUniqueId('someValue');
2213 $this->subject->parameters[$key] = $value;
2214
2215 $this->assertEquals($value, $this->subject->getData('parameters:' . $key));
2216 }
2217
2218 /**
2219 * Checks if getData() works with type "register"
2220 *
2221 * @test
2222 */
2223 public function getDataWithTypeRegister() {
2224 $key = $this->getUniqueId('someKey');
2225 $value = $this->getUniqueId('someValue');
2226 $GLOBALS['TSFE']->register[$key] = $value;
2227
2228 $this->assertEquals($value, $this->subject->getData('register:' . $key));
2229 }
2230
2231 /**
2232 * Checks if getData() works with type "level"
2233 *
2234 * @test
2235 */
2236 public function getDataWithTypeLevel() {
2237 $rootline = array(
2238 0 => array('uid' => 1, 'title' => 'title1'),
2239 1 => array('uid' => 2, 'title' => 'title2'),
2240 2 => array('uid' => 3, 'title' => 'title3'),
2241 );
2242
2243 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2244 $this->assertEquals(2, $this->subject->getData('level'));
2245 }
2246
2247 /**
2248 * Checks if getData() works with type "global"
2249 *
2250 * @test
2251 */
2252 public function getDataWithTypeGlobal() {
2253 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('global:TSFE|renderCharset'));
2254 }
2255
2256 /**
2257 * Checks if getData() works with type "leveltitle"
2258 *
2259 * @test
2260 */
2261 public function getDataWithTypeLeveltitle() {
2262 $rootline = array(
2263 0 => array('uid' => 1, 'title' => 'title1'),
2264 1 => array('uid' => 2, 'title' => 'title2'),
2265 2 => array('uid' => 3, 'title' => ''),
2266 );
2267
2268 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2269 $this->assertEquals('', $this->subject->getData('leveltitle:-1'));
2270 // since "title3" is not set, it will slide to "title2"
2271 $this->assertEquals('title2', $this->subject->getData('leveltitle:-1,slide'));
2272 }
2273
2274 /**
2275 * Checks if getData() works with type "levelmedia"
2276 *
2277 * @test
2278 */
2279 public function getDataWithTypeLevelmedia() {
2280 $rootline = array(
2281 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
2282 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
2283 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
2284 );
2285
2286 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2287 $this->assertEquals('', $this->subject->getData('levelmedia:-1'));
2288 // since "title3" is not set, it will slide to "title2"
2289 $this->assertEquals('media2', $this->subject->getData('levelmedia:-1,slide'));
2290 }
2291
2292 /**
2293 * Checks if getData() works with type "leveluid"
2294 *
2295 * @test
2296 */
2297 public function getDataWithTypeLeveluid() {
2298 $rootline = array(
2299 0 => array('uid' => 1, 'title' => 'title1'),
2300 1 => array('uid' => 2, 'title' => 'title2'),
2301 2 => array('uid' => 3, 'title' => 'title3'),
2302 );
2303
2304 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2305 $this->assertEquals(3, $this->subject->getData('leveluid:-1'));
2306 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
2307 $this->assertEquals(3, $this->subject->getData('leveluid:-1,slide'));
2308 }
2309
2310 /**
2311 * Checks if getData() works with type "levelfield"
2312 *
2313 * @test
2314 */
2315 public function getDataWithTypeLevelfield() {
2316 $rootline = array(
2317 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2318 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2319 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2320 );
2321
2322 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2323 $this->assertEquals('', $this->subject->getData('levelfield:-1,testfield'));
2324 $this->assertEquals('field2', $this->subject->getData('levelfield:-1,testfield,slide'));
2325 }
2326
2327 /**
2328 * Checks if getData() works with type "fullrootline"
2329 *
2330 * @test
2331 */
2332 public function getDataWithTypeFullrootline() {
2333 $rootline1 = array(
2334 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2335 );
2336 $rootline2 = array(
2337 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2338 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2339 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2340 );
2341
2342 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
2343 $GLOBALS['TSFE']->rootLine = $rootline2;
2344 $this->assertEquals('field2', $this->subject->getData('fullrootline:-1,testfield'));
2345 }
2346
2347 /**
2348 * Checks if getData() works with type "date"
2349 *
2350 * @test
2351 */
2352 public function getDataWithTypeDate() {
2353 $format = 'Y-M-D';
2354 $defaultFormat = 'd/m Y';
2355
2356 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject->getData('date:' . $format));
2357 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject->getData('date'));
2358 }
2359
2360 /**
2361 * Checks if getData() works with type "page"
2362 *
2363 * @test
2364 */
2365 public function getDataWithTypePage() {
2366 $uid = rand();
2367 $GLOBALS['TSFE']->page['uid'] = $uid;
2368 $this->assertEquals($uid, $this->subject->getData('page:uid'));
2369 }
2370
2371 /**
2372 * Checks if getData() works with type "current"
2373 *
2374 * @test
2375 */
2376 public function getDataWithTypeCurrent() {
2377 $key = $this->getUniqueId('someKey');
2378 $value = $this->getUniqueId('someValue');
2379 $this->subject->data[$key] = $value;
2380 $this->subject->currentValKey = $key;
2381 $this->assertEquals($value, $this->subject->getData('current'));
2382 }
2383
2384 /**
2385 * Checks if getData() works with type "db"
2386 *
2387 * @test
2388 */
2389 public function getDataWithTypeDb() {
2390 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2391
2392 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2393 $this->assertEquals($dummyRecord['title'], $this->subject->getData('db:tt_content:106:title'));
2394 }
2395
2396 /**
2397 * Checks if getData() works with type "lll"
2398 *
2399 * @test
2400 */
2401 public function getDataWithTypeLll() {
2402 $key = $this->getUniqueId('someKey');
2403 $value = $this->getUniqueId('someValue');
2404 $language = $this->getUniqueId('someLanguage');
2405 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
2406 $GLOBALS['TSFE']->lang = $language;
2407
2408 $this->assertEquals($value, $this->subject->getData('lll:' . $key));
2409 }
2410
2411 /**
2412 * Checks if getData() works with type "path"
2413 *
2414 * @test
2415 */
2416 public function getDataWithTypePath() {
2417 $filenameIn = $this->getUniqueId('someValue');
2418 $filenameOut = $this->getUniqueId('someValue');
2419 $this->templateServiceMock->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2420 $this->assertEquals($filenameOut, $this->subject->getData('path:' . $filenameIn));
2421 }
2422
2423 /**
2424 * Checks if getData() works with type "parentRecordNumber"
2425 *
2426 * @test
2427 */
2428 public function getDataWithTypeParentRecordNumber() {
2429 $recordNumber = rand();
2430 $this->subject->parentRecordNumber = $recordNumber;
2431 $this->assertEquals($recordNumber, $this->subject->getData('cobj:parentRecordNumber'));
2432 }
2433
2434 /**
2435 * Checks if getData() works with type "debug:rootLine"
2436 *
2437 * @test
2438 */
2439 public function getDataWithTypeDebugRootline() {
2440 $rootline = array(
2441 0 => array('uid' => 1, 'title' => 'title1'),
2442 1 => array('uid' => 2, 'title' => 'title2'),
2443 2 => array('uid' => 3, 'title' => ''),
2444 );
2445 $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)';
2446 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2447
2448 $result = $this->subject->getData('debug:rootLine');
2449 $cleanedResult = strip_tags($result);
2450 $cleanedResult = str_replace("\r", '', $cleanedResult);
2451 $cleanedResult = str_replace("\n", '', $cleanedResult);
2452 $cleanedResult = str_replace("\t", '', $cleanedResult);
2453 $cleanedResult = str_replace(' ', '', $cleanedResult);
2454
2455 $this->assertEquals($expectedResult, $cleanedResult);
2456 }
2457
2458 /**
2459 * Checks if getData() works with type "debug:fullRootLine"
2460 *
2461 * @test
2462 */
2463 public function getDataWithTypeDebugFullRootline() {
2464 $rootline = array(
2465 0 => array('uid' => 1, 'title' => 'title1'),
2466 1 => array('uid' => 2, 'title' => 'title2'),
2467 2 => array('uid' => 3, 'title' => ''),
2468 );
2469 $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)';
2470 $GLOBALS['TSFE']->rootLine = $rootline;
2471
2472 $result = $this->subject->getData('debug:fullRootLine');
2473 $cleanedResult = strip_tags($result);
2474 $cleanedResult = str_replace("\r", '', $cleanedResult);
2475 $cleanedResult = str_replace("\n", '', $cleanedResult);
2476 $cleanedResult = str_replace("\t", '', $cleanedResult);
2477 $cleanedResult = str_replace(' ', '', $cleanedResult);
2478
2479 $this->assertEquals($expectedResult, $cleanedResult);
2480 }
2481
2482 /**
2483 * Checks if getData() works with type "debug:data"
2484 *
2485 * @test
2486 */
2487 public function getDataWithTypeDebugData() {
2488 $key = $this->getUniqueId('someKey');
2489 $value = $this->getUniqueId('someValue');
2490 $this->subject->data = array($key => $value);
2491
2492 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2493
2494 $result = $this->subject->getData('debug:data');
2495 $cleanedResult = strip_tags($result);
2496 $cleanedResult = str_replace("\r", '', $cleanedResult);
2497 $cleanedResult = str_replace("\n", '', $cleanedResult);
2498 $cleanedResult = str_replace("\t", '', $cleanedResult);
2499 $cleanedResult = str_replace(' ', '', $cleanedResult);
2500
2501 $this->assertEquals($expectedResult, $cleanedResult);
2502 }
2503
2504 /**
2505 * Checks if getData() works with type "debug:register"
2506 *
2507 * @test
2508 */
2509 public function getDataWithTypeDebugRegister() {
2510 $key = $this->getUniqueId('someKey');
2511 $value = $this->getUniqueId('someValue');
2512 $GLOBALS['TSFE']->register = array($key => $value);
2513
2514 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2515
2516 $result = $this->subject->getData('debug:register');
2517 $cleanedResult = strip_tags($result);
2518 $cleanedResult = str_replace("\r", '', $cleanedResult);
2519 $cleanedResult = str_replace("\n", '', $cleanedResult);
2520 $cleanedResult = str_replace("\t", '', $cleanedResult);
2521 $cleanedResult = str_replace(' ', '', $cleanedResult);
2522
2523 $this->assertEquals($expectedResult, $cleanedResult);
2524 }
2525
2526 /**
2527 * Checks if getData() works with type "data:page"
2528 *
2529 * @test
2530 */
2531 public function getDataWithTypeDebugPage() {
2532 $uid = rand();
2533 $GLOBALS['TSFE']->page = array('uid' => $uid);
2534
2535 $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
2536
2537 $result = $this->subject->getData('debug:page');
2538 $cleanedResult = strip_tags($result);
2539 $cleanedResult = str_replace("\r", '', $cleanedResult);
2540 $cleanedResult = str_replace("\n", '', $cleanedResult);
2541 $cleanedResult = str_replace("\t", '', $cleanedResult);
2542 $cleanedResult = str_replace(' ', '', $cleanedResult);
2543
2544 $this->assertEquals($expectedResult, $cleanedResult);
2545 }
2546
2547 /**
2548 * @test
2549 */
2550 public function getTreeListReturnsChildPageUids() {
2551 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2552 $GLOBALS['TSFE']->sys_page
2553 ->expects($this->any())
2554 ->method('getRawRecord')
2555 ->will(
2556 $this->onConsecutiveCalls(
2557 array('uid' => 17),
2558 array('uid' => 321),
2559 array('uid' => 719),
2560 array('uid' => 42)
2561 )
2562 );
2563
2564 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2565 $GLOBALS['TYPO3_DB']
2566 ->expects($this->any())
2567 ->method('exec_SELECTgetRows')
2568 ->will(
2569 $this->onConsecutiveCalls(
2570 array(
2571 array('uid' => 321)
2572 ),
2573 array(
2574 array('uid' => 719)
2575 ),
2576 array(
2577 array('uid' => 42)
2578 )
2579 )
2580 );
2581 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2582 // 17 is positive, we expect 17 NOT to be included in result
2583 $result = $this->subject->getTreeList(17, 5, 0, TRUE);
2584 $expectedResult = '42,719,321';
2585 $this->assertEquals($expectedResult, $result);
2586 }
2587
2588 /**
2589 * @test
2590 */
2591 public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue() {
2592 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2593 $GLOBALS['TSFE']->sys_page
2594 ->expects($this->any())
2595 ->method('getRawRecord')
2596 ->will(
2597 $this->onConsecutiveCalls(
2598 array('uid' => 17),
2599 array('uid' => 321),
2600 array('uid' => 719),
2601 array('uid' => 42)
2602 )
2603 );
2604
2605 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2606 $GLOBALS['TYPO3_DB']
2607 ->expects($this->any())
2608 ->method('exec_SELECTgetRows')
2609 ->will(
2610 $this->onConsecutiveCalls(
2611 array(
2612 array('uid' => 321)
2613 ),
2614 array(
2615 array('uid' => 719)
2616 ),
2617 array(
2618 array('uid' => 42)
2619 )
2620 )
2621 );
2622 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2623 // 17 is negative, we expect 17 to be included in result
2624 $result = $this->subject->getTreeList(-17, 5, 0, TRUE);
2625 $expectedResult = '42,719,321,17';
2626 $this->assertEquals($expectedResult, $result);
2627 }
2628
2629 /**
2630 * @test
2631 */
2632 public function aTagParamsHasLeadingSpaceIfNotEmpty() {
2633 $aTagParams = $this->subject->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2634 $this->assertEquals(' data-test="testdata"', $aTagParams );
2635 }
2636
2637 /**
2638 * @test
2639 */
2640 public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams() {
2641 $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
2642 $aTagParams = $this->subject->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2643 $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
2644 }
2645
2646 /**
2647 * @test
2648 */
2649 public function aTagParamsHasNoLeadingSpaceIfEmpty() {
2650 // make sure global ATagParams are empty
2651 $GLOBALS['TSFE']->ATagParams = '';
2652 $aTagParams = $this->subject->getATagParams(array('ATagParams' => ''));
2653 $this->assertEquals('', $aTagParams);
2654 }
2655
2656 /**
2657 * @return array
2658 */
2659 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider() {
2660 return array(
2661 array(NULL, NULL),
2662 array('', NULL),
2663 array('', array()),
2664 array('fooo', array('foo' => 'bar'))
2665 );
2666 }
2667
2668 /**
2669 * Make sure that the rendering falls back to the classic <img style if nothing else is found
2670 *
2671 * @test
2672 * @dataProvider getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider
2673 * @param string $key
2674 * @param array $configuration
2675 */
2676 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFound($key, $configuration) {
2677 $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
2678 $result = $this->subject->getImageTagTemplate($key, $configuration);
2679 $this->assertEquals($result, $defaultImgTagTemplate);
2680 }
2681
2682 /**
2683 * @return array
2684 */
2685 public function getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider() {
2686 return array(
2687 array(
2688 'foo',
2689 array(
2690 'layout.' => array(
2691 'foo.' => array(
2692 'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2693 )
2694 )
2695 ),
2696 '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2697 )
2698
2699 );
2700 }
2701
2702 /**
2703 * Assure if a layoutKey and layout is given the selected layout is returned
2704 *
2705 * @test
2706 * @dataProvider getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider
2707 * @param string $key
2708 * @param array $configuration
2709 * @param string $expectation
2710 */
2711 public function getImageTagTemplateReturnTemplateElementIdentifiedByKey($key, $configuration, $expectation) {
2712 $result = $this->subject->getImageTagTemplate($key, $configuration);
2713 $this->assertEquals($result, $expectation);
2714 }
2715
2716 /**
2717 * @return array
2718 */
2719 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider() {
2720 return array(
2721 array(NULL, NULL, NULL),
2722 array('foo', NULL, NULL),
2723 array('foo', array('sourceCollection.' => 1), 'bar')
2724 );
2725 }
2726
2727 /**
2728 * Make sure the source collection is empty if no valid configuration or source collection is defined
2729 *
2730 * @test
2731 * @dataProvider getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider
2732 * @param string $layoutKey
2733 * @param array $configuration
2734 * @param string $file
2735 */
2736 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefined($layoutKey, $configuration, $file) {
2737 $result = $this->subject->getImageSourceCollection($layoutKey, $configuration, $file);
2738 $this->assertSame($result, '');
2739 }
2740
2741 /**
2742 * Make sure the generation of subimages calls the generation of the subimages and uses the layout -> source template
2743 *
2744 * @test
2745 */
2746 public function getImageSourceCollectionRendersDefinedSources() {
2747 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2748 $cObj = $this->getMock(
2749 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
2750 array('stdWrap','getImgResource')
2751 );
2752 $cObj->start(array(), 'tt_content');
2753
2754 $layoutKey = 'test';
2755
2756 $configuration = array(
2757 'layoutKey' => 'test',
2758 'layout.' => array (
2759 'test.' => array(
2760 'element' => '<img ###SRC### ###SRCCOLLECTION### ###SELFCLOSINGTAGSLASH###>',
2761 'source' => '---###SRC###---'
2762 )
2763 ),
2764 'sourceCollection.' => array(
2765 '1.' => array(
2766 'width' => '200'
2767 )
2768 )
2769 );
2770
2771 $file = 'testImageName';
2772
2773 // Avoid calling of stdWrap
2774 $cObj
2775 ->expects($this->any())
2776 ->method('stdWrap')
2777 ->will($this->returnArgument(0));
2778
2779 // Avoid calling of imgResource
2780 $cObj
2781 ->expects($this->exactly(1))
2782 ->method('getImgResource')
2783 ->with($this->equalTo('testImageName'))
2784 ->will($this->returnValue(array(100, 100, NULL, 'bar')));
2785
2786 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2787
2788 $this->assertEquals('---bar---', $result);
2789 }
2790
2791 /**
2792 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyDefault test
2793 *
2794 * @return array multi-dimensional array with the second level like this:
2795 * @see getImageSourceCollectionRendersDefinedLayoutKeyDefault
2796 */
2797 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider() {
2798 /**
2799 * @see css_styled_content/static/setup.txt
2800 */
2801 $sourceCollectionArray = array(
2802 'small.' => array(
2803 'width' => '200',
2804 'srcsetCandidate' => '600w',
2805 'mediaQuery' => '(max-device-width: 600px)',
2806 'dataKey' => 'small',
2807 ),
2808 'smallRetina.' => array(
2809 'if.directReturn' => 0,
2810 'width' => '200',
2811 'pixelDensity' => '2',
2812 'srcsetCandidate' => '600w 2x',
2813 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2814 'dataKey' => 'smallRetina',
2815 )
2816 );
2817 return array(
2818 array(
2819 'default',
2820 array(
2821 'layoutKey' => 'default',
2822 'layout.' => array (
2823 'default.' => array(
2824 'element' => '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>',
2825 'source' => ''
2826 )
2827 ),
2828 'sourceCollection.' => $sourceCollectionArray
2829 )
2830 ),
2831 );
2832 }
2833
2834 /**
2835 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2836 *
2837 * @test
2838 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider
2839 * @param string $layoutKey
2840 * @param array $configuration
2841 */
2842 public function getImageSourceCollectionRendersDefinedLayoutKeyDefault($layoutKey , $configuration) {
2843 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2844 $cObj = $this->getMock(
2845 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
2846 array('stdWrap','getImgResource')
2847 );
2848 $cObj->start(array(), 'tt_content');
2849
2850 $file = 'testImageName';
2851
2852 // Avoid calling of stdWrap
2853 $cObj
2854 ->expects($this->