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