[TASK] Add unit tests for stdWrap_numberFormat()
[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_trimDataProvider() {
987 return array(
988 'trimstring' => array(
989 'trimstring',
990 'trimstring',
991 ),
992 'trim string with space inside' => array(
993 'trim string',
994 'trim string',
995 ),
996 'trim string with space at the begin and end' => array(
997 ' trim string ',
998 'trim string',
999 ),
1000 );
1001 }
1002
1003 /**
1004 * Test for the stdWrap function "trim"
1005 *
1006 * @param string $content
1007 * @param string $expected
1008 *
1009 * @dataProvider stdWrap_trimDataProvider
1010 * @test
1011 */
1012 public function stdWrap_trim($content, $expected) {
1013 $result = $this->subject->stdWrap_trim($content);
1014 $this->assertEquals($expected, $result);
1015 }
1016
1017 /**
1018 * @return array
1019 */
1020 public function stdWrap_intvalDataProvider() {
1021 return array(
1022 'number' => array(
1023 '123',
1024 123,
1025 ),
1026 'float' => array(
1027 '123.45',
1028 123,
1029 ),
1030 'string' => array(
1031 'string',
1032 0,
1033 ),
1034 'zero' => array(
1035 '0',
1036 0,
1037 ),
1038 'empty' => array(
1039 '',
1040 0,
1041 ),
1042 'NULL' => array(
1043 NULL,
1044 0,
1045 ),
1046 'bool TRUE' => array(
1047 TRUE,
1048 1,
1049 ),
1050 'bool FALSE' => array(
1051 FALSE,
1052 0,
1053 ),
1054 );
1055 }
1056
1057 /**
1058 * Test for the stdWrap function "intval"
1059 *
1060 * @param string $content
1061 * @param int $expected
1062 *
1063 * @dataProvider stdWrap_intvalDataProvider
1064 * @test
1065 */
1066 public function stdWrap_intval($content, $expected) {
1067 $result = $this->subject->stdWrap_intval($content);
1068 $this->assertEquals($expected, $result);
1069 }
1070
1071 /**
1072 * @return array
1073 */
1074 public function stdWrap_strPadDataProvider() {
1075 return array(
1076 'pad string with default settings and length 10' => array(
1077 'Alien',
1078 array(
1079 'length' => '10',
1080 ),
1081 'Alien ',
1082 ),
1083 'pad string with padWith -= and type left and length 10' => array(
1084 'Alien',
1085 array(
1086 'length' => '10',
1087 'padWith' => '-=',
1088 'type' => 'left',
1089 ),
1090 '-=-=-Alien',
1091 ),
1092 'pad string with padWith _ and type both and length 10' => array(
1093 'Alien',
1094 array(
1095 'length' => '10',
1096 'padWith' => '_',
1097 'type' => 'both',
1098 ),
1099 '__Alien___',
1100 ),
1101 'pad string with padWith 0 and type both and length 10' => array(
1102 'Alien',
1103 array(
1104 'length' => '10',
1105 'padWith' => '0',
1106 'type' => 'both',
1107 ),
1108 '00Alien000',
1109 ),
1110 'pad string with padWith ___ and type both and length 6' => array(
1111 'Alien',
1112 array(
1113 'length' => '6',
1114 'padWith' => '___',
1115 'type' => 'both',
1116 ),
1117 'Alien_',
1118 ),
1119 'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
1120 'Alien',
1121 array(
1122 'length' => '1',
1123 'length.' => array(
1124 'wrap' => '|2',
1125 ),
1126 'padWith' => '_',
1127 'type' => 'both',
1128 ),
1129 '___Alien____',
1130 ),
1131 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
1132 'Alien',
1133 array(
1134 'length' => '12',
1135 'padWith' => '_',
1136 'padWith.' => array(
1137 'wrap' => '-|=',
1138 ),
1139 'type' => 'both',
1140 ),
1141 '-_=Alien-_=-',
1142 ),
1143 'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
1144 'Alien',
1145 array(
1146 'length' => '12',
1147 'padWith' => '_',
1148 'type' => 'both',
1149 // make type become "left"
1150 'type.' => array(
1151 'substring' => '2,1',
1152 'wrap' => 'lef|',
1153 ),
1154 ),
1155 '_______Alien',
1156 ),
1157 );
1158 }
1159
1160 /**
1161 * Test for the stdWrap function "strPad"
1162 *
1163 * @param string $content
1164 * @param array $conf
1165 * @param string $expected
1166 *
1167 * @dataProvider stdWrap_strPadDataProvider
1168 * @test
1169 */
1170 public function stdWrap_strPad($content, $conf, $expected) {
1171 $conf = array(
1172 'strPad.' => $conf
1173 );
1174 $result = $this->subject->stdWrap_strPad($content, $conf);
1175 $this->assertEquals($expected, $result);
1176 }
1177
1178 /**
1179 * Data provider for the hash test
1180 *
1181 * @return array multi-dimensional array with the second level like this:
1182 * @see hash
1183 */
1184 public function hashDataProvider() {
1185 $data = array(
1186 'testing md5' => array(
1187 'joh316',
1188 array(
1189 'hash' => 'md5'
1190 ),
1191 'bacb98acf97e0b6112b1d1b650b84971'
1192 ),
1193 'testing sha1' => array(
1194 'joh316',
1195 array(
1196 'hash' => 'sha1'
1197 ),
1198 '063b3d108bed9f88fa618c6046de0dccadcf3158'
1199 ),
1200 'testing non-existing hashing algorithm' => array(
1201 'joh316',
1202 array(
1203 'hash' => 'non-existing'
1204 ),
1205 ''
1206 ),
1207 'testing stdWrap capability' => array(
1208 'joh316',
1209 array(
1210 'hash.' => array(
1211 'cObject' => 'TEXT',
1212 'cObject.' => array(
1213 'value' => 'md5'
1214 )
1215 )
1216 ),
1217 'bacb98acf97e0b6112b1d1b650b84971'
1218 )
1219 );
1220 return $data;
1221 }
1222
1223 /**
1224 * Test for the stdWrap function "hash"
1225 *
1226 * @param string $text
1227 * @param array $conf
1228 * @param string $expected
1229 * @return void
1230 * @dataProvider hashDataProvider
1231 * @test
1232 */
1233 public function stdWrap_hash($text, array $conf, $expected) {
1234 $result = $this->subject->stdWrap_hash($text, $conf);
1235 $this->assertEquals($expected, $result);
1236 }
1237
1238 /**
1239 * @test
1240 */
1241 public function recursiveStdWrapProperlyRendersBasicString() {
1242 $stdWrapConfiguration = array(
1243 'noTrimWrap' => '|| 123|',
1244 'stdWrap.' => array(
1245 'wrap' => '<b>|</b>'
1246 )
1247 );
1248 $this->assertSame(
1249 '<b>Test</b> 123',
1250 $this->subject->stdWrap('Test', $stdWrapConfiguration)
1251 );
1252 }
1253
1254 /**
1255 * @test
1256 */
1257 public function recursiveStdWrapIsOnlyCalledOnce() {
1258 $stdWrapConfiguration = array(
1259 'append' => 'TEXT',
1260 'append.' => array(
1261 'data' => 'register:Counter'
1262 ),
1263 'stdWrap.' => array(
1264 'append' => 'LOAD_REGISTER',
1265 'append.' => array(
1266 'Counter.' => array(
1267 'prioriCalc' => 'intval',
1268 'cObject' => 'TEXT',
1269 'cObject.' => array(
1270 'data' => 'register:Counter',
1271 'wrap' => '|+1',
1272 )
1273 )
1274 )
1275 )
1276 );
1277 $this->assertSame(
1278 'Counter:1',
1279 $this->subject->stdWrap('Counter:', $stdWrapConfiguration)
1280 );
1281 }
1282
1283 /**
1284 * Data provider for the numberFormat test
1285 *
1286 * @return array multi-dimensional array with the second level like this:
1287 * @see numberFormat
1288 */
1289 public function numberFormatDataProvider() {
1290 $data = array(
1291 'testing decimals' => array(
1292 0.8,
1293 array(
1294 'decimals' => 2
1295 ),
1296 '0.80'
1297 ),
1298 'testing decimals with input as string' => array(
1299 '0.8',
1300 array(
1301 'decimals' => 2
1302 ),
1303 '0.80'
1304 ),
1305 'testing dec_point' => array(
1306 0.8,
1307 array(
1308 'decimals' => 1,
1309 'dec_point' => ','
1310 ),
1311 '0,8'
1312 ),
1313 'testing thousands_sep' => array(
1314 999.99,
1315 array(
1316 'decimals' => 0,
1317 'thousands_sep.' => array(
1318 'char' => 46
1319 )
1320 ),
1321 '1.000'
1322 ),
1323 'testing mixture' => array(
1324 1281731.45,
1325 array(
1326 'decimals' => 1,
1327 'dec_point.' => array(
1328 'char' => 44
1329 ),
1330 'thousands_sep.' => array(
1331 'char' => 46
1332 )
1333 ),
1334 '1.281.731,5'
1335 )
1336 );
1337 return $data;
1338 }
1339
1340 /**
1341 * Check if stdWrap.numberFormat and all of its properties work properly
1342 *
1343 * @dataProvider numberFormatDataProvider
1344 * @test
1345 */
1346 public function numberFormat($float, $formatConf, $expected) {
1347 $result = $this->subject->numberFormat($float, $formatConf);
1348 $this->assertEquals($expected, $result);
1349 }
1350
1351 /**
1352 * Data provider for the replacement test
1353 *
1354 * @return array multi-dimensional array with the second level like this:
1355 * @see replacement
1356 */
1357 public function replacementDataProvider() {
1358 $data = array(
1359 'multiple replacements, including regex' => array(
1360 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1361 array(
1362 'replacement.' => array(
1363 '120.' => array(
1364 'search' => 'in da hood',
1365 'replace' => 'around the block'
1366 ),
1367 '20.' => array(
1368 'search' => '_',
1369 'replace.' => array('char' => '32')
1370 ),
1371 '130.' => array(
1372 'search' => '#a (Cat|Dog|Tiger)#i',
1373 'replace' => 'an animal',
1374 'useRegExp' => '1'
1375 )
1376 )
1377 ),
1378 'There is an animal, an animal and an animal around the block! Yeah!'
1379 ),
1380 'replacement with optionSplit, normal pattern' => array(
1381 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1382 array(
1383 'replacement.' => array(
1384 '10.' => array(
1385 'search' => '_',
1386 'replace' => '1 || 2 || 3',
1387 'useOptionSplitReplace' => '1'
1388 ),
1389 )
1390 ),
1391 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1392 ),
1393 'replacement with optionSplit, using regex' => array(
1394 'There is a cat, a dog and a tiger in da hood! Yeah!',
1395 array(
1396 'replacement.' => array(
1397 '10.' => array(
1398 'search' => '#(a) (Cat|Dog|Tiger)#i',
1399 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1400 'useOptionSplitReplace' => '1',
1401 'useRegExp' => '1'
1402 )
1403 )
1404 ),
1405 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1406 ),
1407 );
1408 return $data;
1409 }
1410
1411 /**
1412 * Check if stdWrap.replacement and all of its properties work properly
1413 *
1414 * @dataProvider replacementDataProvider
1415 * @test
1416 */
1417 public function replacement($input, $conf, $expected) {
1418 $result = $this->subject->stdWrap_replacement($input, $conf);
1419 $this->assertEquals($expected, $result);
1420 }
1421
1422 /**
1423 * Data provider for the getQuery test
1424 *
1425 * @return array multi-dimensional array with the second level like this:
1426 * @see getQuery
1427 */
1428 public function getQueryDataProvider() {
1429 $data = array(
1430 'testing empty conf' => array(
1431 'tt_content',
1432 array(),
1433 array(
1434 'SELECT' => '*'
1435 )
1436 ),
1437 'testing #17284: adding uid/pid for workspaces' => array(
1438 'tt_content',
1439 array(
1440 'selectFields' => 'header,bodytext'
1441 ),
1442 array(
1443 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1444 )
1445 ),
1446 'testing #17284: no need to add' => array(
1447 'tt_content',
1448 array(
1449 'selectFields' => 'tt_content.*'
1450 ),
1451 array(
1452 'SELECT' => 'tt_content.*'
1453 )
1454 ),
1455 'testing #17284: no need to add #2' => array(
1456 'tt_content',
1457 array(
1458 'selectFields' => '*'
1459 ),
1460 array(
1461 'SELECT' => '*'
1462 )
1463 ),
1464 'testing #29783: joined tables, prefix tablename' => array(
1465 'tt_content',
1466 array(
1467 'selectFields' => 'tt_content.header,be_users.username',
1468 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1469 ),
1470 array(
1471 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1472 )
1473 ),
1474 'testing #34152: single count(*), add nothing' => array(
1475 'tt_content',
1476 array(
1477 'selectFields' => 'count(*)'
1478 ),
1479 array(
1480 'SELECT' => 'count(*)'
1481 )
1482 ),
1483 'testing #34152: single max(crdate), add nothing' => array(
1484 'tt_content',
1485 array(
1486 'selectFields' => 'max(crdate)'
1487 ),
1488 array(
1489 'SELECT' => 'max(crdate)'
1490 )
1491 ),
1492 'testing #34152: single min(crdate), add nothing' => array(
1493 'tt_content',
1494 array(
1495 'selectFields' => 'min(crdate)'
1496 ),
1497 array(
1498 'SELECT' => 'min(crdate)'
1499 )
1500 ),
1501 'testing #34152: single sum(is_siteroot), add nothing' => array(
1502 'tt_content',
1503 array(
1504 'selectFields' => 'sum(is_siteroot)'
1505 ),
1506 array(
1507 'SELECT' => 'sum(is_siteroot)'
1508 )
1509 ),
1510 'testing #34152: single avg(crdate), add nothing' => array(
1511 'tt_content',
1512 array(
1513 'selectFields' => 'avg(crdate)'
1514 ),
1515 array(
1516 'SELECT' => 'avg(crdate)'
1517 )
1518 )
1519 );
1520 return $data;
1521 }
1522
1523 /**
1524 * Check if sanitizeSelectPart works as expected
1525 *
1526 * @dataProvider getQueryDataProvider
1527 * @test
1528 */
1529 public function getQuery($table, $conf, $expected) {
1530 $GLOBALS['TCA'] = array(
1531 'pages' => array(
1532 'ctrl' => array(
1533 'enablecolumns' => array(
1534 'disabled' => 'hidden'
1535 )
1536 )
1537 ),
1538 'tt_content' => array(
1539 'ctrl' => array(
1540 'enablecolumns' => array(
1541 'disabled' => 'hidden'
1542 ),
1543 'versioningWS' => 2
1544 )
1545 ),
1546 );
1547 $result = $this->subject->getQuery($table, $conf, TRUE);
1548 foreach ($expected as $field => $value) {
1549 $this->assertEquals($value, $result[$field]);
1550 }
1551 }
1552
1553 /**
1554 * @test
1555 */
1556 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet() {
1557 $GLOBALS['TCA'] = array(
1558 'pages' => array(
1559 'ctrl' => array(
1560 'enablecolumns' => array(
1561 'disabled' => 'hidden'
1562 )
1563 )
1564 ),
1565 'tt_content' => array(
1566 'ctrl' => array(
1567 'enablecolumns' => array(
1568 'disabled' => 'hidden'
1569 )
1570 )
1571 ),
1572 );
1573 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array('getTreeList'));
1574 $this->subject->start(array(), 'tt_content');
1575 $conf = array(
1576 'recursive' => '15',
1577 'pidInList' => '16, -35'
1578 );
1579 $this->subject->expects($this->at(0))
1580 ->method('getTreeList')
1581 ->with(-16, 15)
1582 ->will($this->returnValue('15,16'));
1583 $this->subject->expects($this->at(1))
1584 ->method('getTreeList')
1585 ->with(-35, 15)
1586 ->will($this->returnValue('15,35'));
1587 $this->subject->getQuery('tt_content', $conf, TRUE);
1588 }
1589
1590 /**
1591 * @test
1592 */
1593 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet() {
1594 $GLOBALS['TCA'] = array(
1595 'pages' => array(
1596 'ctrl' => array(
1597 'enablecolumns' => array(
1598 'disabled' => 'hidden'
1599 )
1600 )
1601 ),
1602 'tt_content' => array(
1603 'ctrl' => array(
1604 'enablecolumns' => array(
1605 'disabled' => 'hidden'
1606 )
1607 )
1608 ),
1609 );
1610 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array('getTreeList'));
1611 $GLOBALS['TSFE']->id = 27;
1612 $this->subject->start(array(), 'tt_content');
1613 $conf = array(
1614 'pidInList' => 'this',
1615 'recursive' => '4'
1616 );
1617 $this->subject->expects($this->once())
1618 ->method('getTreeList')
1619 ->with(-27)
1620 ->will($this->returnValue('27'));
1621 $this->subject->getQuery('tt_content', $conf, TRUE);
1622 }
1623
1624 /**
1625 * Data provider for the stdWrap_strftime test
1626 *
1627 * @return array multi-dimensional array with the second level like this:
1628 * @see stdWrap_strftime
1629 */
1630 public function stdWrap_strftimeReturnsFormattedStringDataProvider() {
1631 $data = array(
1632 'given timestamp' => array(
1633 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1634 array(
1635 'strftime' => '%d-%m-%Y',
1636 ),
1637 ),
1638 'empty string' => array(
1639 '',
1640 array(
1641 'strftime' => '%d-%m-%Y',
1642 ),
1643 ),
1644 'testing null' => array(
1645 NULL,
1646 array(
1647 'strftime' => '%d-%m-%Y',
1648 ),
1649 ),
1650 );
1651 return $data;
1652 }
1653
1654 /**
1655 * @test
1656 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1657 */
1658 public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1659 // Set exec_time to a hard timestamp
1660 $GLOBALS['EXEC_TIME'] = 1346500800;
1661 // Save current timezone and set to UTC to make the system under test behave
1662 // the same in all server timezone settings
1663 $timezoneBackup = date_default_timezone_get();
1664 date_default_timezone_set('UTC');
1665
1666 $result = $this->subject->stdWrap_strftime($content, $conf);
1667
1668 // Reset timezone
1669 date_default_timezone_set($timezoneBackup);
1670
1671 $this->assertEquals('01-09-2012', $result);
1672 }
1673
1674 /**
1675 * Data provider for the stdWrap_strtotime test
1676 *
1677 * @return array
1678 * @see stdWrap_strtotime
1679 */
1680 public function stdWrap_strtotimeReturnsTimestampDataProvider() {
1681 return array(
1682 'date from content' => array(
1683 '2014-12-04',
1684 array(
1685 'strtotime' => '1',
1686 ),
1687 1417651200,
1688 ),
1689 'manipulation of date from content' => array(
1690 '2014-12-04',
1691 array(
1692 'strtotime' => '+ 2 weekdays',
1693 ),
1694 1417996800,
1695 ),
1696 'date from configuration' => array(
1697 '',
1698 array(
1699 'strtotime' => '2014-12-04',
1700 ),
1701 1417651200,
1702 ),
1703 'manipulation of date from configuration' => array(
1704 '',
1705 array(
1706 'strtotime' => '2014-12-04 + 2 weekdays',
1707 ),
1708 1417996800,
1709 ),
1710 'empty input' => array(
1711 '',
1712 array(
1713 'strtotime' => '1',
1714 ),
1715 FALSE,
1716 ),
1717 'date from content and configuration' => array(
1718 '2014-12-04',
1719 array(
1720 'strtotime' => '2014-12-05',
1721 ),
1722 FALSE,
1723 ),
1724 );
1725 }
1726
1727 /**
1728 * @param string|NULL $content
1729 * @param array $configuration
1730 * @param int $expected
1731 * @dataProvider stdWrap_strtotimeReturnsTimestampDataProvider
1732 * @test
1733 */
1734 public function stdWrap_strtotimeReturnsTimestamp($content, $configuration, $expected) {
1735 // Set exec_time to a hard timestamp
1736 $GLOBALS['EXEC_TIME'] = 1417392000;
1737 // Save current timezone and set to UTC to make the system under test behave
1738 // the same in all server timezone settings
1739 $timezoneBackup = date_default_timezone_get();
1740 date_default_timezone_set('UTC');
1741
1742 $result = $this->subject->stdWrap_strtotime($content, $configuration);
1743
1744 // Reset timezone
1745 date_default_timezone_set($timezoneBackup);
1746
1747 $this->assertEquals($expected, $result);
1748 }
1749
1750 /**
1751 * Data provider for stdWrap_stdWrapValue test
1752 *
1753 * @return array
1754 */
1755 public function stdWrap_stdWrapValueDataProvider() {
1756 return array(
1757 'only key returns value' => array(
1758 'ifNull',
1759 array(
1760 'ifNull' => '1',
1761 ),
1762 '',
1763 '1',
1764 ),
1765 'array without key returns empty string' => array(
1766 'ifNull',
1767 array(
1768 'ifNull.' => '1',
1769 ),
1770 '',
1771 '',
1772 ),
1773 'array without key returns default' => array(
1774 'ifNull',
1775 array(
1776 'ifNull.' => '1',
1777 ),
1778 'default',
1779 'default',
1780 ),
1781 'non existing key returns default' => array(
1782 'ifNull',
1783 array(
1784 'noTrimWrap' => 'test',
1785 'noTrimWrap.' => '1',
1786 ),
1787 'default',
1788 'default',
1789 ),
1790 'existing key and array returns stdWrap' => array(
1791 'test',
1792 array(
1793 'test' => 'value',
1794 'test.' => array('case' => 'upper'),
1795 ),
1796 'default',
1797 'VALUE'
1798 ),
1799 );
1800 }
1801
1802 /**
1803 * @param string $key
1804 * @param array $configuration
1805 * @param string $defaultValue
1806 * @param string $expected
1807 * @dataProvider stdWrap_stdWrapValueDataProvider
1808 * @test
1809 */
1810 public function stdWrap_stdWrapValue($key, array $configuration, $defaultValue, $expected) {
1811 $result = $this->subject->stdWrapValue($key, $configuration, $defaultValue);
1812 $this->assertEquals($expected, $result);
1813 }
1814
1815 /**
1816 * @param string|NULL $content
1817 * @param array $configuration
1818 * @param string $expected
1819 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
1820 * @test
1821 */
1822 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1823 $result = $this->subject->stdWrap_ifNull($content, $configuration);
1824 $this->assertEquals($expected, $result);
1825 }
1826
1827 /**
1828 * Data provider for stdWrap_ifNullDeterminesNullValues test
1829 *
1830 * @return array
1831 */
1832 public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
1833 return array(
1834 'null value' => array(
1835 NULL,
1836 array(
1837 'ifNull' => '1',
1838 ),
1839 '1',
1840 ),
1841 'zero value' => array(
1842 '0',
1843 array(
1844 'ifNull' => '1',
1845 ),
1846 '0',
1847 ),
1848 );
1849 }
1850
1851 /**
1852 * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
1853 *
1854 * @return array
1855 */
1856 public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider() {
1857 return array(
1858 'null value' => array(
1859 NULL,
1860 array(
1861 'ifEmpty' => '1',
1862 ),
1863 '1',
1864 ),
1865 'empty value' => array(
1866 '',
1867 array(
1868 'ifEmpty' => '1',
1869 ),
1870 '1',
1871 ),
1872 'string value' => array(
1873 'string',
1874 array(
1875 'ifEmpty' => '1',
1876 ),
1877 'string',
1878 ),
1879 'empty string value' => array(
1880 ' ',
1881 array(
1882 'ifEmpty' => '1',
1883 ),
1884 '1',
1885 ),
1886 );
1887 }
1888
1889 /**
1890 * @param string|NULL $content
1891 * @param array $configuration
1892 * @param string $expected
1893 * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
1894 * @test
1895 */
1896 public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected) {
1897 $result = $this->subject->stdWrap_ifEmpty($content, $configuration);
1898 $this->assertEquals($expected, $result);
1899 }
1900
1901 /**
1902 * @param $content
1903 * @param array $configuration
1904 * @param $expected
1905 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
1906 * @test
1907 */
1908 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1909 $result = $this->subject->stdWrap_noTrimWrap($content, $configuration);
1910 $this->assertEquals($expected, $result);
1911 }
1912
1913 /**
1914 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
1915 *
1916 * @return array
1917 */
1918 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
1919 return array(
1920 'No char given' => array(
1921 'middle',
1922 array(
1923 'noTrimWrap' => '| left | right |',
1924 ),
1925 ' left middle right '
1926 ),
1927 'Zero char given' => array(
1928 'middle',
1929 array(
1930 'noTrimWrap' => '0 left 0 right 0',
1931 'noTrimWrap.' => array('splitChar' => '0'),
1932
1933 ),
1934 ' left middle right '
1935 ),
1936 'Default char given' => array(
1937 'middle',
1938 array(
1939 'noTrimWrap' => '| left | right |',
1940 'noTrimWrap.' => array('splitChar' => '|'),
1941 ),
1942 ' left middle right '
1943 ),
1944 'Split char is a' => array(
1945 'middle',
1946 array(
1947 'noTrimWrap' => 'a left a right a',
1948 'noTrimWrap.' => array('splitChar' => 'a'),
1949 ),
1950 ' left middle right '
1951 ),
1952 'Split char is multi-char (ab)' => array(
1953 'middle',
1954 array(
1955 'noTrimWrap' => 'ab left ab right ab',
1956 'noTrimWrap.' => array('splitChar' => 'ab'),
1957 ),
1958 ' left middle right '
1959 ),
1960 'Split char accepts stdWrap' => array(
1961 'middle',
1962 array(
1963 'noTrimWrap' => 'abc left abc right abc',
1964 'noTrimWrap.' => array(
1965 'splitChar' => 'b',
1966 'splitChar.' => array('wrap' => 'a|c'),
1967 ),
1968 ),
1969 ' left middle right '
1970 ),
1971 );
1972 }
1973
1974 /**
1975 * @param array $expectedTags
1976 * @param array $configuration
1977 * @test
1978 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
1979 */
1980 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
1981 $this->subject->stdWrap_addPageCacheTags('', $configuration);
1982 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock->_get('pageCacheTags'));
1983 }
1984
1985 /**
1986 * @return array
1987 */
1988 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
1989 return array(
1990 'No Tag' => array(
1991 array(),
1992 array('addPageCacheTags' => ''),
1993 ),
1994 'Two expectedTags' => array(
1995 array('tag1', 'tag2'),
1996 array('addPageCacheTags' => 'tag1,tag2'),
1997 ),
1998 'Two expectedTags plus one with stdWrap' => array(
1999 array('tag1', 'tag2', 'tag3'),
2000 array(
2001 'addPageCacheTags' => 'tag1,tag2',
2002 'addPageCacheTags.' => array('wrap' => '|,tag3')
2003 ),
2004 ),
2005 );
2006 }
2007
2008 /**
2009 * Data provider for stdWrap_encodeForJavaScriptValue test
2010 *
2011 * @return array multi-dimensional array with the second level like this:
2012 * @see encodeForJavaScriptValue
2013 */
2014 public function stdWrap_encodeForJavaScriptValueDataProvider() {
2015 return array(
2016 'double quote in string' => array(
2017 'double quote"',
2018 array(),
2019 '\'double\u0020quote\u0022\''
2020 ),
2021 'backslash in string' => array(
2022 'backslash \\',
2023 array(),
2024 '\'backslash\u0020\u005C\''
2025 ),
2026 'exclamation mark' => array(
2027 'exclamation!',
2028 array(),
2029 '\'exclamation\u0021\''
2030 ),
2031 'whitespace tab, newline and carriage return' => array(
2032 "white\tspace\ns\r",
2033 array(),
2034 '\'white\u0009space\u000As\u000D\''
2035 ),
2036 'single quote in string' => array(
2037 'single quote \'',
2038 array(),
2039 '\'single\u0020quote\u0020\u0027\''
2040 ),
2041 'tag' => array(
2042 '<tag>',
2043 array(),
2044 '\'\u003Ctag\u003E\''
2045 ),
2046 'ampersand in string' => array(
2047 'amper&sand',
2048 array(),
2049 '\'amper\u0026sand\''
2050 ),
2051 );
2052 }
2053
2054 /**
2055 * Check if encodeForJavaScriptValue works properly
2056 *
2057 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
2058 * @test
2059 */
2060 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected) {
2061 $result = $this->subject->stdWrap_encodeForJavaScriptValue($input, $conf);
2062 $this->assertEquals($expected, $result);
2063 }
2064
2065
2066 ///////////////////////////////
2067 // Tests concerning getData()
2068 ///////////////////////////////
2069
2070 /**
2071 * @return array
2072 */
2073 public function getDataWithTypeGpDataProvider() {
2074 return array(
2075 'Value in get-data' => array('onlyInGet', 'GetValue'),
2076 'Value in post-data' => array('onlyInPost', 'PostValue'),
2077 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
2078 );
2079 }
2080
2081 /**
2082 * Checks if getData() works with type "gp"
2083 *
2084 * @test
2085 * @dataProvider getDataWithTypeGpDataProvider
2086 */
2087 public function getDataWithTypeGp($key, $expectedValue) {
2088 $_GET = array(
2089 'onlyInGet' => 'GetValue',
2090 'inGetAndPost' => 'ValueInGet',
2091 );
2092 $_POST = array(
2093 'onlyInPost' => 'PostValue',
2094 'inGetAndPost' => 'ValueInPost',
2095 );
2096 $this->assertEquals($expectedValue, $this->subject->getData('gp:' . $key));
2097 }
2098
2099 /**
2100 * Checks if getData() works with type "tsfe"
2101 *
2102 * @test
2103 */
2104 public function getDataWithTypeTsfe() {
2105 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('tsfe:renderCharset'));
2106 }
2107
2108 /**
2109 * Checks if getData() works with type "getenv"
2110 *
2111 * @test
2112 */
2113 public function getDataWithTypeGetenv() {
2114 $envName = $this->getUniqueId('frontendtest');
2115 $value = $this->getUniqueId('someValue');
2116 putenv($envName . '=' . $value);
2117 $this->assertEquals($value, $this->subject->getData('getenv:' . $envName));
2118 }
2119
2120 /**
2121 * Checks if getData() works with type "getindpenv"
2122 *
2123 * @test
2124 */
2125 public function getDataWithTypeGetindpenv() {
2126 $this->subject->expects($this->once())->method('getEnvironmentVariable')
2127 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
2128 $this->assertEquals('dummyPath', $this->subject->getData('getindpenv:SCRIPT_FILENAME'));
2129 }
2130
2131 /**
2132 * Checks if getData() works with type "field"
2133 *
2134 * @test
2135 */
2136 public function getDataWithTypeField() {
2137 $key = 'someKey';
2138 $value = 'someValue';
2139 $field = array($key => $value);
2140
2141 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2142 }
2143
2144 /**
2145 * Checks if getData() works with type "field" of the field content
2146 * is multi-dimensional (e.g. an array)
2147 *
2148 * @test
2149 */
2150 public function getDataWithTypeFieldAndFieldIsMultiDimensional() {
2151 $key = 'somekey|level1|level2';
2152 $value = 'somevalue';
2153 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
2154
2155 $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
2156 }
2157
2158 /**
2159 * Basic check if getData gets the uid of a file object
2160 *
2161 * @test
2162 */
2163 public function getDataWithTypeFileReturnsUidOfFileObject() {
2164 $uid = $this->getUniqueId();
2165 $file = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(), '', FALSE);
2166 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
2167 $this->subject->setCurrentFile($file);
2168 $this->assertEquals($uid, $this->subject->getData('file:current:uid'));
2169 }
2170
2171 /**
2172 * Checks if getData() works with type "parameters"
2173 *
2174 * @test
2175 */
2176 public function getDataWithTypeParameters() {
2177 $key = $this->getUniqueId('someKey');
2178 $value = $this->getUniqueId('someValue');
2179 $this->subject->parameters[$key] = $value;
2180
2181 $this->assertEquals($value, $this->subject->getData('parameters:' . $key));
2182 }
2183
2184 /**
2185 * Checks if getData() works with type "register"
2186 *
2187 * @test
2188 */
2189 public function getDataWithTypeRegister() {
2190 $key = $this->getUniqueId('someKey');
2191 $value = $this->getUniqueId('someValue');
2192 $GLOBALS['TSFE']->register[$key] = $value;
2193
2194 $this->assertEquals($value, $this->subject->getData('register:' . $key));
2195 }
2196
2197 /**
2198 * Checks if getData() works with type "level"
2199 *
2200 * @test
2201 */
2202 public function getDataWithTypeLevel() {
2203 $rootline = array(
2204 0 => array('uid' => 1, 'title' => 'title1'),
2205 1 => array('uid' => 2, 'title' => 'title2'),
2206 2 => array('uid' => 3, 'title' => 'title3'),
2207 );
2208
2209 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2210 $this->assertEquals(2, $this->subject->getData('level'));
2211 }
2212
2213 /**
2214 * Checks if getData() works with type "global"
2215 *
2216 * @test
2217 */
2218 public function getDataWithTypeGlobal() {
2219 $this->assertEquals($GLOBALS['TSFE']->renderCharset, $this->subject->getData('global:TSFE|renderCharset'));
2220 }
2221
2222 /**
2223 * Checks if getData() works with type "leveltitle"
2224 *
2225 * @test
2226 */
2227 public function getDataWithTypeLeveltitle() {
2228 $rootline = array(
2229 0 => array('uid' => 1, 'title' => 'title1'),
2230 1 => array('uid' => 2, 'title' => 'title2'),
2231 2 => array('uid' => 3, 'title' => ''),
2232 );
2233
2234 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2235 $this->assertEquals('', $this->subject->getData('leveltitle:-1'));
2236 // since "title3" is not set, it will slide to "title2"
2237 $this->assertEquals('title2', $this->subject->getData('leveltitle:-1,slide'));
2238 }
2239
2240 /**
2241 * Checks if getData() works with type "levelmedia"
2242 *
2243 * @test
2244 */
2245 public function getDataWithTypeLevelmedia() {
2246 $rootline = array(
2247 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
2248 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
2249 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
2250 );
2251
2252 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2253 $this->assertEquals('', $this->subject->getData('levelmedia:-1'));
2254 // since "title3" is not set, it will slide to "title2"
2255 $this->assertEquals('media2', $this->subject->getData('levelmedia:-1,slide'));
2256 }
2257
2258 /**
2259 * Checks if getData() works with type "leveluid"
2260 *
2261 * @test
2262 */
2263 public function getDataWithTypeLeveluid() {
2264 $rootline = array(
2265 0 => array('uid' => 1, 'title' => 'title1'),
2266 1 => array('uid' => 2, 'title' => 'title2'),
2267 2 => array('uid' => 3, 'title' => 'title3'),
2268 );
2269
2270 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2271 $this->assertEquals(3, $this->subject->getData('leveluid:-1'));
2272 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
2273 $this->assertEquals(3, $this->subject->getData('leveluid:-1,slide'));
2274 }
2275
2276 /**
2277 * Checks if getData() works with type "levelfield"
2278 *
2279 * @test
2280 */
2281 public function getDataWithTypeLevelfield() {
2282 $rootline = array(
2283 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2284 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2285 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2286 );
2287
2288 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2289 $this->assertEquals('', $this->subject->getData('levelfield:-1,testfield'));
2290 $this->assertEquals('field2', $this->subject->getData('levelfield:-1,testfield,slide'));
2291 }
2292
2293 /**
2294 * Checks if getData() works with type "fullrootline"
2295 *
2296 * @test
2297 */
2298 public function getDataWithTypeFullrootline() {
2299 $rootline1 = array(
2300 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2301 );
2302 $rootline2 = array(
2303 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2304 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2305 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2306 );
2307
2308 $GLOBALS['TSFE']->tmpl->rootLine = $rootline1;
2309 $GLOBALS['TSFE']->rootLine = $rootline2;
2310 $this->assertEquals('field2', $this->subject->getData('fullrootline:-1,testfield'));
2311 }
2312
2313 /**
2314 * Checks if getData() works with type "date"
2315 *
2316 * @test
2317 */
2318 public function getDataWithTypeDate() {
2319 $format = 'Y-M-D';
2320 $defaultFormat = 'd/m Y';
2321
2322 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject->getData('date:' . $format));
2323 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject->getData('date'));
2324 }
2325
2326 /**
2327 * Checks if getData() works with type "page"
2328 *
2329 * @test
2330 */
2331 public function getDataWithTypePage() {
2332 $uid = rand();
2333 $GLOBALS['TSFE']->page['uid'] = $uid;
2334 $this->assertEquals($uid, $this->subject->getData('page:uid'));
2335 }
2336
2337 /**
2338 * Checks if getData() works with type "current"
2339 *
2340 * @test
2341 */
2342 public function getDataWithTypeCurrent() {
2343 $key = $this->getUniqueId('someKey');
2344 $value = $this->getUniqueId('someValue');
2345 $this->subject->data[$key] = $value;
2346 $this->subject->currentValKey = $key;
2347 $this->assertEquals($value, $this->subject->getData('current'));
2348 }
2349
2350 /**
2351 * Checks if getData() works with type "db"
2352 *
2353 * @test
2354 */
2355 public function getDataWithTypeDb() {
2356 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2357
2358 $GLOBALS['TSFE']->sys_page->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2359 $this->assertEquals($dummyRecord['title'], $this->subject->getData('db:tt_content:106:title'));
2360 }
2361
2362 /**
2363 * Checks if getData() works with type "lll"
2364 *
2365 * @test
2366 */
2367 public function getDataWithTypeLll() {
2368 $key = $this->getUniqueId('someKey');
2369 $value = $this->getUniqueId('someValue');
2370 $language = $this->getUniqueId('someLanguage');
2371 $GLOBALS['TSFE']->LL_labels_cache[$language]['LLL:' . $key] = $value;
2372 $GLOBALS['TSFE']->lang = $language;
2373
2374 $this->assertEquals($value, $this->subject->getData('lll:' . $key));
2375 }
2376
2377 /**
2378 * Checks if getData() works with type "path"
2379 *
2380 * @test
2381 */
2382 public function getDataWithTypePath() {
2383 $filenameIn = $this->getUniqueId('someValue');
2384 $filenameOut = $this->getUniqueId('someValue');
2385 $this->templateServiceMock->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2386 $this->assertEquals($filenameOut, $this->subject->getData('path:' . $filenameIn));
2387 }
2388
2389 /**
2390 * Checks if getData() works with type "parentRecordNumber"
2391 *
2392 * @test
2393 */
2394 public function getDataWithTypeParentRecordNumber() {
2395 $recordNumber = rand();
2396 $this->subject->parentRecordNumber = $recordNumber;
2397 $this->assertEquals($recordNumber, $this->subject->getData('cobj:parentRecordNumber'));
2398 }
2399
2400 /**
2401 * Checks if getData() works with type "debug:rootLine"
2402 *
2403 * @test
2404 */
2405 public function getDataWithTypeDebugRootline() {
2406 $rootline = array(
2407 0 => array('uid' => 1, 'title' => 'title1'),
2408 1 => array('uid' => 2, 'title' => 'title2'),
2409 2 => array('uid' => 3, 'title' => ''),
2410 );
2411 $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)';
2412 $GLOBALS['TSFE']->tmpl->rootLine = $rootline;
2413
2414 $result = $this->subject->getData('debug:rootLine');
2415 $cleanedResult = strip_tags($result);
2416 $cleanedResult = str_replace("\r", '', $cleanedResult);
2417 $cleanedResult = str_replace("\n", '', $cleanedResult);
2418 $cleanedResult = str_replace("\t", '', $cleanedResult);
2419 $cleanedResult = str_replace(' ', '', $cleanedResult);
2420
2421 $this->assertEquals($expectedResult, $cleanedResult);
2422 }
2423
2424 /**
2425 * Checks if getData() works with type "debug:fullRootLine"
2426 *
2427 * @test
2428 */
2429 public function getDataWithTypeDebugFullRootline() {
2430 $rootline = array(
2431 0 => array('uid' => 1, 'title' => 'title1'),
2432 1 => array('uid' => 2, 'title' => 'title2'),
2433 2 => array('uid' => 3, 'title' => ''),
2434 );
2435 $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)';
2436 $GLOBALS['TSFE']->rootLine = $rootline;
2437
2438 $result = $this->subject->getData('debug:fullRootLine');
2439 $cleanedResult = strip_tags($result);
2440 $cleanedResult = str_replace("\r", '', $cleanedResult);
2441 $cleanedResult = str_replace("\n", '', $cleanedResult);
2442 $cleanedResult = str_replace("\t", '', $cleanedResult);
2443 $cleanedResult = str_replace(' ', '', $cleanedResult);
2444
2445 $this->assertEquals($expectedResult, $cleanedResult);
2446 }
2447
2448 /**
2449 * Checks if getData() works with type "debug:data"
2450 *
2451 * @test
2452 */
2453 public function getDataWithTypeDebugData() {
2454 $key = $this->getUniqueId('someKey');
2455 $value = $this->getUniqueId('someValue');
2456 $this->subject->data = array($key => $value);
2457
2458 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2459
2460 $result = $this->subject->getData('debug:data');
2461 $cleanedResult = strip_tags($result);
2462 $cleanedResult = str_replace("\r", '', $cleanedResult);
2463 $cleanedResult = str_replace("\n", '', $cleanedResult);
2464 $cleanedResult = str_replace("\t", '', $cleanedResult);
2465 $cleanedResult = str_replace(' ', '', $cleanedResult);
2466
2467 $this->assertEquals($expectedResult, $cleanedResult);
2468 }
2469
2470 /**
2471 * Checks if getData() works with type "debug:register"
2472 *
2473 * @test
2474 */
2475 public function getDataWithTypeDebugRegister() {
2476 $key = $this->getUniqueId('someKey');
2477 $value = $this->getUniqueId('someValue');
2478 $GLOBALS['TSFE']->register = array($key => $value);
2479
2480 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2481
2482 $result = $this->subject->getData('debug:register');
2483 $cleanedResult = strip_tags($result);
2484 $cleanedResult = str_replace("\r", '', $cleanedResult);
2485 $cleanedResult = str_replace("\n", '', $cleanedResult);
2486 $cleanedResult = str_replace("\t", '', $cleanedResult);
2487 $cleanedResult = str_replace(' ', '', $cleanedResult);
2488
2489 $this->assertEquals($expectedResult, $cleanedResult);
2490 }
2491
2492 /**
2493 * Checks if getData() works with type "data:page"
2494 *
2495 * @test
2496 */
2497 public function getDataWithTypeDebugPage() {
2498 $uid = rand();
2499 $GLOBALS['TSFE']->page = array('uid' => $uid);
2500
2501 $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
2502
2503 $result = $this->subject->getData('debug:page');
2504 $cleanedResult = strip_tags($result);
2505 $cleanedResult = str_replace("\r", '', $cleanedResult);
2506 $cleanedResult = str_replace("\n", '', $cleanedResult);
2507 $cleanedResult = str_replace("\t", '', $cleanedResult);
2508 $cleanedResult = str_replace(' ', '', $cleanedResult);
2509
2510 $this->assertEquals($expectedResult, $cleanedResult);
2511 }
2512
2513 /**
2514 * @test
2515 */
2516 public function getTreeListReturnsChildPageUids() {
2517 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2518 $GLOBALS['TSFE']->sys_page
2519 ->expects($this->any())
2520 ->method('getRawRecord')
2521 ->will(
2522 $this->onConsecutiveCalls(
2523 array('uid' => 17),
2524 array('uid' => 321),
2525 array('uid' => 719),
2526 array('uid' => 42)
2527 )
2528 );
2529
2530 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2531 $GLOBALS['TYPO3_DB']
2532 ->expects($this->any())
2533 ->method('exec_SELECTgetRows')
2534 ->will(
2535 $this->onConsecutiveCalls(
2536 array(
2537 array('uid' => 321)
2538 ),
2539 array(
2540 array('uid' => 719)
2541 ),
2542 array(
2543 array('uid' => 42)
2544 )
2545 )
2546 );
2547 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2548 // 17 is positive, we expect 17 NOT to be included in result
2549 $result = $this->subject->getTreeList(17, 5, 0, TRUE);
2550 $expectedResult = '42,719,321';
2551 $this->assertEquals($expectedResult, $result);
2552 }
2553
2554 /**
2555 * @test
2556 */
2557 public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue() {
2558 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2559 $GLOBALS['TSFE']->sys_page
2560 ->expects($this->any())
2561 ->method('getRawRecord')
2562 ->will(
2563 $this->onConsecutiveCalls(
2564 array('uid' => 17),
2565 array('uid' => 321),
2566 array('uid' => 719),
2567 array('uid' => 42)
2568 )
2569 );
2570
2571 $GLOBALS['TSFE']->sys_page->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2572 $GLOBALS['TYPO3_DB']
2573 ->expects($this->any())
2574 ->method('exec_SELECTgetRows')
2575 ->will(
2576 $this->onConsecutiveCalls(
2577 array(
2578 array('uid' => 321)
2579 ),
2580 array(
2581 array('uid' => 719)
2582 ),
2583 array(
2584 array('uid' => 42)
2585 )
2586 )
2587 );
2588 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2589 // 17 is negative, we expect 17 to be included in result
2590 $result = $this->subject->getTreeList(-17, 5, 0, TRUE);
2591 $expectedResult = '42,719,321,17';
2592 $this->assertEquals($expectedResult, $result);
2593 }
2594
2595 /**
2596 * @test
2597 */
2598 public function aTagParamsHasLeadingSpaceIfNotEmpty() {
2599 $aTagParams = $this->subject->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2600 $this->assertEquals(' data-test="testdata"', $aTagParams );
2601 }
2602
2603 /**
2604 * @test
2605 */
2606 public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams() {
2607 $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
2608 $aTagParams = $this->subject->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2609 $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
2610 }
2611
2612 /**
2613 * @test
2614 */
2615 public function aTagParamsHasNoLeadingSpaceIfEmpty() {
2616 // make sure global ATagParams are empty
2617 $GLOBALS['TSFE']->ATagParams = '';
2618 $aTagParams = $this->subject->getATagParams(array('ATagParams' => ''));
2619 $this->assertEquals('', $aTagParams);
2620 }
2621
2622 /**
2623 * @return array
2624 */
2625 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider() {
2626 return array(
2627 array(NULL, NULL),
2628 array('', NULL),
2629 array('', array()),
2630 array('fooo', array('foo' => 'bar'))
2631 );
2632 }
2633
2634 /**
2635 * Make sure that the rendering falls back to the classic <img style if nothing else is found
2636 *
2637 * @test
2638 * @dataProvider getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider
2639 * @param string $key
2640 * @param array $configuration
2641 */
2642 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFound($key, $configuration) {
2643 $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
2644 $result = $this->subject->getImageTagTemplate($key, $configuration);
2645 $this->assertEquals($result, $defaultImgTagTemplate);
2646 }
2647
2648 /**
2649 * @return array
2650 */
2651 public function getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider() {
2652 return array(
2653 array(
2654 'foo',
2655 array(
2656 'layout.' => array(
2657 'foo.' => array(
2658 'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2659 )
2660 )
2661 ),
2662 '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2663 )
2664
2665 );
2666 }
2667
2668 /**
2669 * Assure if a layoutKey and layout is given the selected layout is returned
2670 *
2671 * @test
2672 * @dataProvider getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider
2673 * @param string $key
2674 * @param array $configuration
2675 * @param string $expectation
2676 */
2677 public function getImageTagTemplateReturnTemplateElementIdentifiedByKey($key, $configuration, $expectation) {
2678 $result = $this->subject->getImageTagTemplate($key, $configuration);
2679 $this->assertEquals($result, $expectation);
2680 }
2681
2682 /**
2683 * @return array
2684 */
2685 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider() {
2686 return array(
2687 array(NULL, NULL, NULL),
2688 array('foo', NULL, NULL),
2689 array('foo', array('sourceCollection.' => 1), 'bar')
2690 );
2691 }
2692
2693 /**
2694 * Make sure the source collection is empty if no valid configuration or source collection is defined
2695 *
2696 * @test
2697 * @dataProvider getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider
2698 * @param string $layoutKey
2699 * @param array $configuration
2700 * @param string $file
2701 */
2702 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefined($layoutKey, $configuration, $file) {
2703 $result = $this->subject->getImageSourceCollection($layoutKey, $configuration, $file);
2704 $this->assertSame($result, '');
2705 }
2706
2707 /**
2708 * Make sure the generation of subimages calls the generation of the subimages and uses the layout -> source template
2709 *
2710 * @test
2711 */
2712 public function getImageSourceCollectionRendersDefinedSources() {
2713 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2714 $cObj = $this->getMock(
2715 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
2716 array('stdWrap','getImgResource')
2717 );
2718 $cObj->start(array(), 'tt_content');
2719
2720 $layoutKey = 'test';
2721
2722 $configuration = array(
2723 'layoutKey' => 'test',
2724 'layout.' => array (
2725 'test.' => array(
2726 'element' => '<img ###SRC### ###SRCCOLLECTION### ###SELFCLOSINGTAGSLASH###>',
2727 'source' => '---###SRC###---'
2728 )
2729 ),
2730 'sourceCollection.' => array(
2731 '1.' => array(
2732 'width' => '200'
2733 )
2734 )
2735 );
2736
2737 $file = 'testImageName';
2738
2739 // Avoid calling of stdWrap
2740 $cObj
2741 ->expects($this->any())
2742 ->method('stdWrap')
2743 ->will($this->returnArgument(0));
2744
2745 // Avoid calling of imgResource
2746 $cObj
2747 ->expects($this->exactly(1))
2748 ->method('getImgResource')
2749 ->with($this->equalTo('testImageName'))
2750 ->will($this->returnValue(array(100, 100, NULL, 'bar')));
2751
2752 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2753
2754 $this->assertEquals('---bar---', $result);
2755 }
2756
2757 /**
2758 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyDefault test
2759 *
2760 * @return array multi-dimensional array with the second level like this:
2761 * @see getImageSourceCollectionRendersDefinedLayoutKeyDefault
2762 */
2763 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider() {
2764 /**
2765 * @see css_styled_content/static/setup.txt
2766 */
2767 $sourceCollectionArray = array(
2768 'small.' => array(
2769 'width' => '200',
2770 'srcsetCandidate' => '600w',
2771 'mediaQuery' => '(max-device-width: 600px)',
2772 'dataKey' => 'small',
2773 ),
2774 'smallRetina.' => array(
2775 'if.directReturn' => 0,
2776 'width' => '200',
2777 'pixelDensity' => '2',
2778 'srcsetCandidate' => '600w 2x',
2779 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2780 'dataKey' => 'smallRetina',
2781 )
2782 );
2783 return array(
2784 array(
2785 'default',
2786 array(
2787 'layoutKey' => 'default',
2788 'layout.' => array (
2789 'default.' => array(
2790 'element' => '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>',
2791 'source' => ''
2792 )
2793 ),
2794 'sourceCollection.' => $sourceCollectionArray
2795 )
2796 ),
2797 );
2798 }
2799
2800 /**
2801 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2802 *
2803 * @test
2804 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider
2805 * @param string $layoutKey
2806 * @param array $configuration
2807 */
2808 public function getImageSourceCollectionRendersDefinedLayoutKeyDefault($layoutKey , $configuration) {
2809 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2810 $cObj = $this->getMock(
2811 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class,
2812 array('stdWrap','getImgResource')
2813 );
2814 $cObj->start(array(), 'tt_content');
2815
2816 $file = 'testImageName';
2817
2818 // Avoid calling of stdWrap
2819 $cObj
2820 ->expects($this->any())
2821 ->method('stdWrap')
2822 ->will($this->returnArgument(0));
2823
2824 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2825
2826 $this->assertEmpty($result);
2827 }
2828
2829 /**
2830 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyData test
2831 *
2832 * @return array multi-dimensional array with the second level like this:
2833 * @see getImageSourceCollectionRendersDefinedLayoutKeyData
2834 */
2835 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider() {
2836 /**
2837 * @see css_styled_content/static/setup.txt
2838 */
2839 $sourceCollectionArray = array(
2840 'small.' => array(
2841 'width' => '200',
2842 'srcsetCandidate' => '600w',
2843 'mediaQuery' => '(max-device-width: 600px)',
2844 'dataKey' => 'small',
2845 ),
2846 'smallRetina.' => array(
2847 'if.directReturn' => 1,
2848 'width' => '200',
2849 'pixelDensity' => '2',
2850 'srcsetCandidate' => '600w 2x',
2851 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2852 'dataKey' => 'smallRetina',
2853 )
2854 );</