2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
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\GeneralUtility
;
23 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
;
24 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
;
25 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
26 use TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Fixtures\PageRepositoryFixture
;
29 * Testcase for TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
31 class ContentObjectRendererTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
36 protected $currentLocale;
39 * @var array A backup of registered singleton instances
41 protected $singletonInstances = array();
44 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
46 protected $subject = null;
49 * @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
51 protected $typoScriptFrontendControllerMock = null;
54 * @var \PHPUnit_Framework_MockObject_MockObject|TemplateService
56 protected $templateServiceMock = null;
59 * Default content object name -> class name map, shipped with TYPO3 CMS
63 protected $contentObjectMap = array(
64 'TEXT' => \TYPO3\CMS\Frontend\ContentObject\TextContentObject
::class,
65 'CASE' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject
::class,
66 'COBJ_ARRAY' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
::class,
67 'COA' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
::class,
68 'COA_INT' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayInternalContentObject
::class,
69 'USER' => \TYPO3\CMS\Frontend\ContentObject\UserContentObject
::class,
70 'USER_INT' => \TYPO3\CMS\Frontend\ContentObject\UserInternalContentObject
::class,
71 'FILE' => \TYPO3\CMS\Frontend\ContentObject\FileContentObject
::class,
72 'FILES' => \TYPO3\CMS\Frontend\ContentObject\FilesContentObject
::class,
73 'IMAGE' => \TYPO3\CMS\Frontend\ContentObject\ImageContentObject
::class,
74 'IMG_RESOURCE' => \TYPO3\CMS\Frontend\ContentObject\ImageResourceContentObject
::class,
75 'CONTENT' => \TYPO3\CMS\Frontend\ContentObject\ContentContentObject
::class,
76 'RECORDS' => \TYPO3\CMS\Frontend\ContentObject\RecordsContentObject
::class,
77 'HMENU' => \TYPO3\CMS\Frontend\ContentObject\HierarchicalMenuContentObject
::class,
78 'CASEFUNC' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject
::class,
79 'LOAD_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\LoadRegisterContentObject
::class,
80 'RESTORE_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\RestoreRegisterContentObject
::class,
81 'TEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\TemplateContentObject
::class,
82 'FLUIDTEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject
::class,
83 'SVG' => \TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject
::class,
84 'EDITPANEL' => \TYPO3\CMS\Frontend\ContentObject\EditPanelContentObject
::class
90 protected function setUp()
92 $this->currentLocale
= setlocale(LC_NUMERIC
, 0);
94 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
95 $this->createMockedLoggerAndLogManager();
97 $this->templateServiceMock
= $this->getMock(TemplateService
::class, array('getFileName', 'linkData'));
98 $pageRepositoryMock = $this->getMock(PageRepositoryFixture
::class, array('getRawRecord', 'getMountPointInfo'));
100 $this->typoScriptFrontendControllerMock
= $this->getAccessibleMock(TypoScriptFrontendController
::class, array('dummy'), array(), '', false);
101 $this->typoScriptFrontendControllerMock
->tmpl
= $this->templateServiceMock
;
102 $this->typoScriptFrontendControllerMock
->config
= array();
103 $this->typoScriptFrontendControllerMock
->page
= array();
104 $this->typoScriptFrontendControllerMock
->sys_page
= $pageRepositoryMock;
105 $GLOBALS['TSFE'] = $this->typoScriptFrontendControllerMock
;
106 $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection
::class, array());
108 $this->subject
= $this->getAccessibleMock(
109 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
110 array('getResourceFactory', 'getEnvironmentVariable'),
111 array($this->typoScriptFrontendControllerMock
)
113 $this->subject
->setContentObjectClassMap($this->contentObjectMap
);
114 $this->subject
->start(array(), 'tt_content');
117 protected function tearDown()
119 setlocale(LC_NUMERIC
, $this->currentLocale
);
120 GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
124 //////////////////////
126 //////////////////////
129 * Avoid logging to the file system (file writer is currently the only configured writer)
131 protected function createMockedLoggerAndLogManager()
133 $logManagerMock = $this->getMock(LogManager
::class);
134 $loggerMock = $this->getMock(LoggerInterface
::class);
135 $logManagerMock->expects($this->any())
136 ->method('getLogger')
137 ->willReturn($loggerMock);
138 GeneralUtility
::setSingletonInstance(LogManager
::class, $logManagerMock);
142 * Converts the subject and the expected result into utf-8.
144 * @param string $subject the subject, will be modified
145 * @param string $expected the expected result, will be modified
147 protected function handleCharset(&$subject, &$expected)
149 $charsetConverter = new CharsetConverter();
150 $subject = $charsetConverter->conv($subject, 'iso-8859-1', 'utf-8');
151 $expected = $charsetConverter->conv($expected, 'iso-8859-1', 'utf-8');
154 /////////////////////////////////////////////
155 // Tests concerning the getImgResource hook
156 /////////////////////////////////////////////
160 public function getImgResourceCallsGetImgResourcePostProcessHook()
162 $this->templateServiceMock
163 ->expects($this->atLeastOnce())
164 ->method('getFileName')
165 ->with('typo3/clear.gif')
166 ->will($this->returnValue('typo3/clear.gif'));
168 $resourceFactory = $this->getMock(\TYPO3\CMS\Core\
Resource\ResourceFactory
::class, array(), array(), '', false);
169 $this->subject
->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
171 $className = $this->getUniqueId('tx_coretest');
172 $getImgResourceHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectGetImageResourceHookInterface
::class, array('getImgResourcePostProcess'), array(), $className);
173 $getImgResourceHookMock
174 ->expects($this->once())
175 ->method('getImgResourcePostProcess')
176 ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
177 $getImgResourceHookObjects = array($getImgResourceHookMock);
178 $this->subject
->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
179 $this->subject
->getImgResource('typo3/clear.gif', array());
183 * Handles the arguments that have been sent to the getImgResource hook.
185 * @param string $file
186 * @param array $fileArray
187 * @param $imageResource
188 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $parent
190 * @see getImgResourceHookGetsCalled
192 public function isGetImgResourceHookCalledCallback($file, $fileArray, $imageResource, $parent)
194 $this->assertEquals('typo3/clear.gif', $file);
195 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
196 $this->assertTrue(is_array($fileArray));
197 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
);
198 return $imageResource;
201 //////////////////////////////////////
202 // Tests concerning getContentObject
203 //////////////////////////////////////
205 public function getContentObjectValidContentObjectsDataProvider()
207 $dataProvider = array();
208 foreach ($this->contentObjectMap
as $name => $className) {
209 $dataProvider[] = array($name, $className);
211 return $dataProvider;
216 * @dataProvider getContentObjectValidContentObjectsDataProvider
217 * @param string $name TypoScript name of content object
218 * @param string $fullClassName Expected class name
220 public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $fullClassName)
222 $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', false);
223 \TYPO3\CMS\Core\Utility\GeneralUtility
::addInstance($fullClassName, $contentObjectInstance);
224 $this->assertSame($contentObjectInstance, $this->subject
->getContentObject($name));
227 /////////////////////////////////////////
228 // Tests concerning getQueryArguments()
229 /////////////////////////////////////////
233 public function getQueryArgumentsExcludesParameters()
235 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
236 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
238 $getQueryArgumentsConfiguration = array();
239 $getQueryArgumentsConfiguration['exclude'] = array();
240 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
241 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
242 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
243 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
244 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
245 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
246 $this->assertEquals($expectedResult, $actualResult);
252 public function getQueryArgumentsExcludesGetParameters()
258 'key31' => 'value31',
260 'key321' => 'value321',
261 'key322' => 'value322'
265 $getQueryArgumentsConfiguration = array();
266 $getQueryArgumentsConfiguration['method'] = 'GET';
267 $getQueryArgumentsConfiguration['exclude'] = array();
268 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
269 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
270 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
271 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
272 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
273 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
274 $this->assertEquals($expectedResult, $actualResult);
280 public function getQueryArgumentsOverrulesSingleParameter()
282 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
283 $this->returnValue('key1=value1')
285 $getQueryArgumentsConfiguration = array();
286 $overruleArguments = array(
287 // Should be overridden
288 'key1' => 'value1Overruled',
289 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
290 'key2' => 'value2Overruled'
292 $expectedResult = '&key1=value1Overruled';
293 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
294 $this->assertEquals($expectedResult, $actualResult);
300 public function getQueryArgumentsOverrulesMultiDimensionalParameters()
306 'key31' => 'value31',
308 'key321' => 'value321',
309 'key322' => 'value322'
313 $getQueryArgumentsConfiguration = array();
314 $getQueryArgumentsConfiguration['method'] = 'POST';
315 $getQueryArgumentsConfiguration['exclude'] = array();
316 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
317 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
318 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
319 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
320 $overruleArguments = array(
321 // Should be overriden
322 'key2' => 'value2Overruled',
325 // Shouldn't be set: Parameter is excluded and not forced
326 'key321' => 'value321Overruled',
327 // Should be overriden: Parameter is not excluded
328 'key322' => 'value322Overruled',
329 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
330 'key323' => 'value323Overruled'
334 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
335 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
336 $this->assertEquals($expectedResult, $actualResult);
342 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters()
344 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
345 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
351 'key31' => 'value31',
353 'key321' => 'value321',
354 'key322' => 'value322'
358 $getQueryArgumentsConfiguration = array();
359 $getQueryArgumentsConfiguration['exclude'] = array();
360 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
361 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
362 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
363 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
364 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
365 $overruleArguments = array(
366 // Should be overriden
367 'key2' => 'value2Overruled',
370 // Should be set: Parameter is excluded but forced
371 'key321' => 'value321Overruled',
372 // Should be set: Parameter doesn't exist in source array but is forced
373 'key323' => 'value323Overruled'
377 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
378 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, true);
379 $this->assertEquals($expectedResult, $actualResult);
380 $getQueryArgumentsConfiguration['method'] = 'POST';
381 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, true);
382 $this->assertEquals($expectedResult, $actualResult);
388 public function getQueryArgumentsWithMethodPostGetMergesParameters()
397 'key331' => 'POST331',
398 'key332' => 'POST332',
407 'key331' => 'GET331',
411 $getQueryArgumentsConfiguration = array();
412 $getQueryArgumentsConfiguration['method'] = 'POST,GET';
413 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
414 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
415 $this->assertEquals($expectedResult, $actualResult);
421 public function getQueryArgumentsWithMethodGetPostMergesParameters()
430 'key331' => 'GET331',
431 'key332' => 'GET332',
440 'key331' => 'POST331',
444 $getQueryArgumentsConfiguration = array();
445 $getQueryArgumentsConfiguration['method'] = 'GET,POST';
446 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
447 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
448 $this->assertEquals($expectedResult, $actualResult);
452 * Encodes square brackets in URL.
454 * @param string $string
457 private function rawUrlEncodeSquareBracketsInUrl($string)
459 return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
462 //////////////////////////
463 // Tests concerning crop
464 //////////////////////////
468 public function cropIsMultibyteSafe()
470 $this->assertEquals('бла', $this->subject
->crop('бла', '3|...'));
473 //////////////////////////////
474 // Tests concerning cropHTML
475 //////////////////////////////
477 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
478 * of charset, text type, and configuration options to be tested.
480 * @return array two-dimensional array with the second level like this:
481 * @see cropHtmlWithDataProvider
483 public function cropHtmlDataProvider()
485 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
486 $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.';
487 $textWithEntities = 'Kasper Skårhøj implemented the; original ' . 'version of the crop function.';
489 'plain text; 11|...' => array(
492 'Kasper Sk' . chr(229) . 'r...'
494 'plain text; -58|...' => array(
497 '...h' . chr(248) . 'j implemented the original version of the crop function.'
499 'plain text; 4|...|1' => array(
504 'plain text; 20|...|1' => array(
507 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...'
509 'plain text; -5|...|1' => array(
514 'plain text; -49|...|1' => array(
517 '...the original version of the crop function.'
519 'text with markup; 11|...' => array(
522 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>'
524 'text with markup; 13|...' => array(
527 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>'
529 'text with markup; 14|...' => array(
532 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>'
534 'text with markup; 15|...' => array(
537 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>'
539 'text with markup; 29|...' => array(
542 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...'
544 'text with markup; -58|...' => array(
547 '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.'
549 'text with markup 4|...|1' => array(
552 '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>'
554 'text with markup; 11|...|1' => array(
557 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>'
559 'text with markup; 13|...|1' => array(
562 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>'
564 'text with markup; 14|...|1' => array(
567 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>'
569 'text with markup; 15|...|1' => array(
572 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>'
574 'text with markup; 29|...|1' => array(
577 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...'
579 'text with markup; -66|...|1' => array(
582 '<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 'text with entities 9|...' => array(
589 'text with entities 10|...' => array(
592 'Kasper Skå...'
594 'text with entities 11|...' => array(
597 'Kasper Skår...'
599 'text with entities 13|...' => array(
602 'Kasper Skårhø...'
604 'text with entities 14|...' => array(
607 'Kasper Skårhøj...'
609 'text with entities 15|...' => array(
612 'Kasper Skårhøj ...'
614 'text with entities 16|...' => array(
617 'Kasper Skårhøj i...'
619 'text with entities -57|...' => array(
622 '...j implemented the; original version of the crop function.'
624 'text with entities -58|...' => array(
627 '...øj implemented the; original version of the crop function.'
629 'text with entities -59|...' => array(
632 '...høj implemented the; original version of the crop function.'
634 'text with entities 4|...|1' => array(
639 'text with entities 9|...|1' => array(
644 'text with entities 10|...|1' => array(
649 'text with entities 11|...|1' => array(
654 'text with entities 13|...|1' => array(
659 'text with entities 14|...|1' => array(
662 'Kasper Skårhøj...'
664 'text with entities 15|...|1' => array(
667 'Kasper Skårhøj...'
669 'text with entities 16|...|1' => array(
672 'Kasper Skårhøj...'
674 'text with entities -57|...|1' => array(
677 '...implemented the; original version of the crop function.'
679 'text with entities -58|...|1' => array(
682 '...implemented the; original version of the crop function.'
684 'text with entities -59|...|1' => array(
687 '...implemented the; original version of the crop function.'
689 'text with dash in html-element 28|...|1' => array(
691 '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',
692 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>'
694 'html elements with dashes in attributes' => array(
696 '<em data-foo="x">foobar</em>foobaz',
697 '<em data-foo="x">foobar</em>foo'
699 'html elements with iframe embedded 24|...|1' => array(
701 'Text with iframe <iframe src="//what.ever/"></iframe> and text after it',
702 'Text with iframe <iframe src="//what.ever/"></iframe> and...'
704 'html elements with script tag embedded 24|...|1' => array(
706 'Text with script <script>alert(\'foo\');</script> and text after it',
707 'Text with script <script>alert(\'foo\');</script> and...'
714 * Checks if stdWrap.cropHTML works with plain text cropping from left
717 * @dataProvider cropHtmlDataProvider
718 * @param string $settings
719 * @param string $subject the string to crop
720 * @param string $expected the expected cropped result
722 public function cropHtmlWithDataProvider($settings, $subject, $expected)
724 $this->handleCharset($subject, $expected);
725 $this->assertEquals($expected, $this->subject
->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '"');
729 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
730 * counts multiple invisible characters not as one (as the browser will output the content).
734 public function cropHtmlWorksWithComplexContent()
737 '<h1>Blog Example</h1>' . LF
.
739 '<div class="csc-header csc-header-n1">' . LF
.
740 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF
.
742 '<p class="bodytext">' . LF
.
743 ' 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 '<div class="tx-blogexample-list-container">' . LF
.
746 ' <p class="bodytext">' . LF
.
747 ' Below are the most recent posts:' . LF
.
750 ' <li data-element="someId">' . LF
.
752 ' <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[blog]=&tx_blogexample_pi1[action]=show&tx_blogexample_pi1[controller]=Post&cHash=003b0131ed">The Post #1</a>' . LF
.
754 ' <p class="bodytext">' . LF
.
755 ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...' . LF
.
757 ' <p class="metadata">' . LF
.
758 ' Published on 26.08.2009 by Jochen Rau' . LF
.
761 ' Tags: [MVC] [Domain Driven Design] <br>' . LF
.
762 ' <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[action]=show&tx_blogexample_pi1[controller]=Post&cHash=f982643bc3">read more >></a><br>' . LF
.
763 ' <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[blog][uid]=70&tx_blogexample_pi1[action]=edit&tx_blogexample_pi1[controller]=Post&cHash=5b481bc8f0">Edit</a> <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[blog][uid]=70&tx_blogexample_pi1[action]=delete&tx_blogexample_pi1[controller]=Post&cHash=4e52879656">Delete</a>' . LF
.
768 ' <a href="index.php?id=99&tx_blogexample_pi1[blog][uid]=70&tx_blogexample_pi1[action]=new&tx_blogexample_pi1[controller]=Post&cHash=2718a4b1a0">Create a new Post</a>' . LF
.
773 ' ? TYPO3 Association' . LF
.
776 $result = $this->subject
->cropHTML($input, '300');
779 '<h1>Blog Example</h1>' . LF
.
781 '<div class="csc-header csc-header-n1">' . LF
.
782 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF
.
784 '<p class="bodytext">' . LF
.
785 ' 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 '<div class="tx-blogexample-list-container">' . LF
.
788 ' <p class="bodytext">' . LF
.
789 ' Below are the most recent posts:' . LF
.
792 ' <li data-element="someId">' . LF
.
794 ' <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[blog]=&tx_blogexample_pi1[action]=show&tx_blogexample_pi1[controller]=Post&cHash=003b0131ed">The Post</a></h3></li></ul></div>';
796 $this->assertEquals($expected, $result);
798 $result = $this->subject
->cropHTML($input, '-100');
801 '<div class="tx-blogexample-list-container"><ul><li data-element="someId"><p> Design] <br>' . LF
.
802 ' <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[action]=show&tx_blogexample_pi1[controller]=Post&cHash=f982643bc3">read more >></a><br>' . LF
.
803 ' <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[blog][uid]=70&tx_blogexample_pi1[action]=edit&tx_blogexample_pi1[controller]=Post&cHash=5b481bc8f0">Edit</a> <a href="index.php?id=99&tx_blogexample_pi1[post][uid]=211&tx_blogexample_pi1[blog][uid]=70&tx_blogexample_pi1[action]=delete&tx_blogexample_pi1[controller]=Post&cHash=4e52879656">Delete</a>' . LF
.
808 ' <a href="index.php?id=99&tx_blogexample_pi1[blog][uid]=70&tx_blogexample_pi1[action]=new&tx_blogexample_pi1[controller]=Post&cHash=2718a4b1a0">Create a new Post</a>' . LF
.
813 ' ? TYPO3 Association' . LF
.
816 $this->assertEquals($expected, $result);
820 * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
824 public function cropHtmlWorksWithLinebreaks()
826 $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
827 $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
828 $result = $this->subject
->cropHTML($subject, '121');
829 $this->assertEquals($expected, $result);
835 public function stdWrap_roundDataProvider()
838 'rounding off without any configuration' => array(
843 'rounding up without any configuration' => array(
848 'regular rounding (off) to two decimals' => array(
855 'regular rounding (up) to two decimals' => array(
862 'rounding up to integer with type ceil' => array(
865 'roundType' => 'ceil'
869 'rounding down to integer with type floor' => array(
872 'roundType' => 'floor'
880 * Test for the stdWrap function "round"
882 * @param float $float
884 * @param float $expected
886 * @dataProvider stdWrap_roundDataProvider
889 public function stdWrap_round($float, $conf, $expected)
894 $result = $this->subject
->stdWrap_round($float, $conf);
895 $this->assertEquals($expected, $result);
901 public function stdWrap_numberFormatDataProvider()
904 'testing decimals' => array(
907 'numberFormat.' => array(
913 'testing decimals with input as string' => array(
916 'numberFormat.' => array(
922 'testing dec_point' => array(
925 'numberFormat.' => array(
932 'testing thousands_sep' => array(
935 'numberFormat.' => array(
937 'thousands_sep.' => array(
944 'testing mixture' => array(
947 'numberFormat.' => array(
949 'dec_point.' => array(
952 'thousands_sep.' => array(
963 * Test for the stdWrap function "round"
965 * @param float $float
967 * @param string $expected
969 * @dataProvider stdWrap_numberFormatDataProvider
972 public function stdWrap_numberFormat($float, $conf, $expected)
974 $result = $this->subject
->stdWrap_numberFormat($float, $conf);
975 $this->assertEquals($expected, $result);
981 public function stdWrap_expandListDataProvider()
992 'numbers and range' => array(
1000 * Test for the stdWrap function "expandList"
1002 * @param string $content
1003 * @param string $expected
1005 * @dataProvider stdWrap_expandListDataProvider
1008 public function stdWrap_expandList($content, $expected)
1010 $result = $this->subject
->stdWrap_expandList($content);
1011 $this->assertEquals($expected, $result);
1017 public function stdWrap_trimDataProvider()
1020 'trimstring' => array(
1024 'trim string with space inside' => array(
1028 'trim string with space at the begin and end' => array(
1036 * Test for the stdWrap function "trim"
1038 * @param string $content
1039 * @param string $expected
1041 * @dataProvider stdWrap_trimDataProvider
1044 public function stdWrap_trim($content, $expected)
1046 $result = $this->subject
->stdWrap_trim($content);
1047 $this->assertEquals($expected, $result);
1053 public function stdWrap_intvalDataProvider()
1080 'bool TRUE' => array(
1084 'bool FALSE' => array(
1092 * Test for the stdWrap function "intval"
1094 * @param string $content
1095 * @param int $expected
1097 * @dataProvider stdWrap_intvalDataProvider
1100 public function stdWrap_intval($content, $expected)
1102 $result = $this->subject
->stdWrap_intval($content);
1103 $this->assertEquals($expected, $result);
1109 public function stdWrap_strPadDataProvider()
1112 'pad string with default settings and length 10' => array(
1119 'pad string with padWith -= and type left and length 10' => array(
1128 'pad string with padWith _ and type both and length 10' => array(
1137 'pad string with padWith 0 and type both and length 10' => array(
1146 'pad string with padWith ___ and type both and length 6' => array(
1155 'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
1167 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
1172 'padWith.' => array(
1179 'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
1185 // make type become "left"
1187 'substring' => '2,1',
1197 * Test for the stdWrap function "strPad"
1199 * @param string $content
1200 * @param array $conf
1201 * @param string $expected
1203 * @dataProvider stdWrap_strPadDataProvider
1206 public function stdWrap_strPad($content, $conf, $expected)
1211 $result = $this->subject
->stdWrap_strPad($content, $conf);
1212 $this->assertEquals($expected, $result);
1216 * Data provider for the hash test
1218 * @return array multi-dimensional array with the second level like this:
1221 public function hashDataProvider()
1224 'testing md5' => array(
1229 'bacb98acf97e0b6112b1d1b650b84971'
1231 'testing sha1' => array(
1236 '063b3d108bed9f88fa618c6046de0dccadcf3158'
1238 'testing non-existing hashing algorithm' => array(
1241 'hash' => 'non-existing'
1245 'testing stdWrap capability' => array(
1249 'cObject' => 'TEXT',
1250 'cObject.' => array(
1255 'bacb98acf97e0b6112b1d1b650b84971'
1262 * Test for the stdWrap function "hash"
1264 * @param string $text
1265 * @param array $conf
1266 * @param string $expected
1268 * @dataProvider hashDataProvider
1271 public function stdWrap_hash($text, array $conf, $expected)
1273 $result = $this->subject
->stdWrap_hash($text, $conf);
1274 $this->assertEquals($expected, $result);
1280 public function recursiveStdWrapProperlyRendersBasicString()
1282 $stdWrapConfiguration = array(
1283 'noTrimWrap' => '|| 123|',
1284 'stdWrap.' => array(
1285 'wrap' => '<b>|</b>'
1290 $this->subject
->stdWrap('Test', $stdWrapConfiguration)
1297 public function recursiveStdWrapIsOnlyCalledOnce()
1299 $stdWrapConfiguration = array(
1302 'data' => 'register:Counter'
1304 'stdWrap.' => array(
1305 'append' => 'LOAD_REGISTER',
1307 'Counter.' => array(
1308 'prioriCalc' => 'intval',
1309 'cObject' => 'TEXT',
1310 'cObject.' => array(
1311 'data' => 'register:Counter',
1320 $this->subject
->stdWrap('Counter:', $stdWrapConfiguration)
1325 * Data provider for the numberFormat test
1327 * @return array multi-dimensional array with the second level like this:
1330 public function numberFormatDataProvider()
1333 'testing decimals' => array(
1340 'testing decimals with input as string' => array(
1347 'testing dec_point' => array(
1355 'testing thousands_sep' => array(
1359 'thousands_sep.' => array(
1365 'testing mixture' => array(
1369 'dec_point.' => array(
1372 'thousands_sep.' => array(
1383 * Check if stdWrap.numberFormat and all of its properties work properly
1385 * @dataProvider numberFormatDataProvider
1388 public function numberFormat($float, $formatConf, $expected)
1390 $result = $this->subject
->numberFormat($float, $formatConf);
1391 $this->assertEquals($expected, $result);
1395 * Data provider for the replacement test
1397 * @return array multi-dimensional array with the second level like this:
1400 public function replacementDataProvider()
1403 'multiple replacements, including regex' => array(
1404 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1406 'replacement.' => array(
1408 'search' => 'in da hood',
1409 'replace' => 'around the block'
1413 'replace.' => array('char' => '32')
1416 'search' => '#a (Cat|Dog|Tiger)#i',
1417 'replace' => 'an animal',
1422 'There is an animal, an animal and an animal around the block! Yeah!'
1424 'replacement with optionSplit, normal pattern' => array(
1425 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1427 'replacement.' => array(
1430 'replace' => '1 || 2 || 3',
1431 'useOptionSplitReplace' => '1'
1435 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1437 'replacement with optionSplit, using regex' => array(
1438 'There is a cat, a dog and a tiger in da hood! Yeah!',
1440 'replacement.' => array(
1442 'search' => '#(a) (Cat|Dog|Tiger)#i',
1443 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1444 'useOptionSplitReplace' => '1',
1449 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1456 * Check if stdWrap.replacement and all of its properties work properly
1458 * @dataProvider replacementDataProvider
1461 public function replacement($input, $conf, $expected)
1463 $result = $this->subject
->stdWrap_replacement($input, $conf);
1464 $this->assertEquals($expected, $result);
1468 * Data provider for the getQuery test
1470 * @return array multi-dimensional array with the second level like this:
1473 public function getQueryDataProvider()
1476 'testing empty conf' => array(
1483 'testing #17284: adding uid/pid for workspaces' => array(
1486 'selectFields' => 'header,bodytext'
1489 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1492 'testing #17284: no need to add' => array(
1495 'selectFields' => 'tt_content.*'
1498 'SELECT' => 'tt_content.*'
1501 'testing #17284: no need to add #2' => array(
1504 'selectFields' => '*'
1510 'testing #29783: joined tables, prefix tablename' => array(
1513 'selectFields' => 'tt_content.header,be_users.username',
1514 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1517 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1520 'testing #34152: single count(*), add nothing' => array(
1523 'selectFields' => 'count(*)'
1526 'SELECT' => 'count(*)'
1529 'testing #34152: single max(crdate), add nothing' => array(
1532 'selectFields' => 'max(crdate)'
1535 'SELECT' => 'max(crdate)'
1538 'testing #34152: single min(crdate), add nothing' => array(
1541 'selectFields' => 'min(crdate)'
1544 'SELECT' => 'min(crdate)'
1547 'testing #34152: single sum(is_siteroot), add nothing' => array(
1550 'selectFields' => 'sum(is_siteroot)'
1553 'SELECT' => 'sum(is_siteroot)'
1556 'testing #34152: single avg(crdate), add nothing' => array(
1559 'selectFields' => 'avg(crdate)'
1562 'SELECT' => 'avg(crdate)'
1570 * Check if sanitizeSelectPart works as expected
1572 * @dataProvider getQueryDataProvider
1575 public function getQuery($table, $conf, $expected)
1577 $GLOBALS['TCA'] = array(
1580 'enablecolumns' => array(
1581 'disabled' => 'hidden'
1585 'tt_content' => array(
1587 'enablecolumns' => array(
1588 'disabled' => 'hidden'
1590 'versioningWS' => true
1594 $result = $this->subject
->getQuery($table, $conf, true);
1595 foreach ($expected as $field => $value) {
1596 $this->assertEquals($value, $result[$field]);
1603 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet()
1605 $GLOBALS['TCA'] = array(
1608 'enablecolumns' => array(
1609 'disabled' => 'hidden'
1613 'tt_content' => array(
1615 'enablecolumns' => array(
1616 'disabled' => 'hidden'
1621 $this->subject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class, array('getTreeList'));
1622 $this->subject
->start(array(), 'tt_content');
1624 'recursive' => '15',
1625 'pidInList' => '16, -35'
1627 $this->subject
->expects($this->at(0))
1628 ->method('getTreeList')
1630 ->will($this->returnValue('15,16'));
1631 $this->subject
->expects($this->at(1))
1632 ->method('getTreeList')
1634 ->will($this->returnValue('15,35'));
1635 $this->subject
->getQuery('tt_content', $conf, true);
1641 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet()
1643 $GLOBALS['TCA'] = array(
1646 'enablecolumns' => array(
1647 'disabled' => 'hidden'
1651 'tt_content' => array(
1653 'enablecolumns' => array(
1654 'disabled' => 'hidden'
1659 $this->subject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class, array('getTreeList'));
1660 $GLOBALS['TSFE']->id
= 27;
1661 $this->subject
->start(array(), 'tt_content');
1663 'pidInList' => 'this',
1666 $this->subject
->expects($this->once())
1667 ->method('getTreeList')
1669 ->will($this->returnValue('27'));
1670 $this->subject
->getQuery('tt_content', $conf, true);
1674 * Data provider for the stdWrap_date test
1676 * @return array multi-dimensional array with the second level like this:
1679 public function stdWrap_dateDataProvider()
1682 'given timestamp' => array(
1683 1443780000, // This is 2015-10-02 12:00
1689 'empty string' => array(
1696 'testing null' => array(
1703 'given timestamp return GMT' => array(
1704 1443780000, // This is 2015-10-02 12:00
1706 'date' => 'd.m.Y H:i:s',
1711 '02.10.2015 10:00:00',
1718 * @dataProvider stdWrap_dateDataProvider
1719 * @param string|int|NULL $content
1720 * @param array $conf
1721 * @param string $expected
1723 public function stdWrap_date($content, $conf, $expected)
1725 // Set exec_time to a hard timestamp
1726 $GLOBALS['EXEC_TIME'] = 1443780000;
1728 $result = $this->subject
->stdWrap_date($content, $conf);
1730 $this->assertEquals($expected, $result);
1734 * Data provider for the stdWrap_strftime test
1736 * @return array multi-dimensional array with the second level like this:
1737 * @see stdWrap_strftime
1739 public function stdWrap_strftimeReturnsFormattedStringDataProvider()
1742 'given timestamp' => array(
1743 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1745 'strftime' => '%d-%m-%Y',
1748 'empty string' => array(
1751 'strftime' => '%d-%m-%Y',
1754 'testing null' => array(
1757 'strftime' => '%d-%m-%Y',
1766 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1768 public function stdWrap_strftimeReturnsFormattedString($content, $conf)
1770 // Set exec_time to a hard timestamp
1771 $GLOBALS['EXEC_TIME'] = 1346500800;
1772 // Save current timezone and set to UTC to make the system under test behave
1773 // the same in all server timezone settings
1774 $timezoneBackup = date_default_timezone_get();
1775 date_default_timezone_set('UTC');
1777 $result = $this->subject
->stdWrap_strftime($content, $conf);
1780 date_default_timezone_set($timezoneBackup);
1782 $this->assertEquals('01-09-2012', $result);
1786 * Data provider for the stdWrap_strtotime test
1789 * @see stdWrap_strtotime
1791 public function stdWrap_strtotimeReturnsTimestampDataProvider()
1794 'date from content' => array(
1801 'manipulation of date from content' => array(
1804 'strtotime' => '+ 2 weekdays',
1808 'date from configuration' => array(
1811 'strtotime' => '2014-12-04',
1815 'manipulation of date from configuration' => array(
1818 'strtotime' => '2014-12-04 + 2 weekdays',
1822 'empty input' => array(
1829 'date from content and configuration' => array(
1832 'strtotime' => '2014-12-05',
1840 * @param string|NULL $content
1841 * @param array $configuration
1842 * @param int $expected
1843 * @dataProvider stdWrap_strtotimeReturnsTimestampDataProvider
1846 public function stdWrap_strtotimeReturnsTimestamp($content, $configuration, $expected)
1848 // Set exec_time to a hard timestamp
1849 $GLOBALS['EXEC_TIME'] = 1417392000;
1850 // Save current timezone and set to UTC to make the system under test behave
1851 // the same in all server timezone settings
1852 $timezoneBackup = date_default_timezone_get();
1853 date_default_timezone_set('UTC');
1855 $result = $this->subject
->stdWrap_strtotime($content, $configuration);
1858 date_default_timezone_set($timezoneBackup);
1860 $this->assertEquals($expected, $result);
1866 public function stdWrap_ageCallsCalcAgeWithSubtractedTimestampAndSubPartOfArray()
1868 $subject = $this->getMock(
1869 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
1872 // Set exec_time to a hard timestamp
1873 $GLOBALS['EXEC_TIME'] = 10;
1874 $subject->expects($this->once())->method('calcAge')->with(1, 'Min| Hrs| Days| Yrs');
1875 $subject->stdWrap_age(9, array('age' => 'Min| Hrs| Days| Yrs'));
1879 * Data provider for calcAgeCalculatesAgeOfTimestamp
1884 public function calcAgeCalculatesAgeOfTimestampDataProvider()
1889 ' min| hrs| days| yrs',
1894 ' min| hrs| days| yrs',
1899 ' min| hrs| days| yrs',
1902 'day with provided singular labels' => array(
1904 ' min| hrs| days| yrs| min| hour| day| year',
1909 ' min| hrs| days| yrs',
1912 'different labels' => array(
1914 ' Minutes| Hrs| Days| Yrs',
1917 'negative values' => array(
1919 ' min| hrs| days| yrs',
1922 'default label values for wrong label input' => array(
1927 'default singular label values for wrong label input' => array(
1936 * @param int $timestamp
1937 * @param string $labels
1938 * @param int $expectation
1939 * @dataProvider calcAgeCalculatesAgeOfTimestampDataProvider
1942 public function calcAgeCalculatesAgeOfTimestamp($timestamp, $labels, $expectation)
1944 $result = $this->subject
->calcAge($timestamp, $labels);
1945 $this->assertEquals($result, $expectation);
1949 * Data provider for stdWrap_case test
1953 public function stdWrap_caseDataProvider()
1956 'lower case text to upper' => array(
1957 '<span>text</span>',
1961 '<span>TEXT</span>',
1963 'upper case text to lower' => array(
1964 '<span>TEXT</span>',
1968 '<span>text</span>',
1970 'capitalize text' => array(
1971 '<span>this is a text</span>',
1973 'case' => 'capitalize',
1975 '<span>This Is A Text</span>',
1977 'ucfirst text' => array(
1978 '<span>this is a text</span>',
1980 'case' => 'ucfirst',
1982 '<span>This is a text</span>',
1984 'lcfirst text' => array(
1985 '<span>This is a Text</span>',
1987 'case' => 'lcfirst',
1989 '<span>this is a Text</span>',
1991 'uppercamelcase text' => array(
1992 '<span>this_is_a_text</span>',
1994 'case' => 'uppercamelcase',
1996 '<span>ThisIsAText</span>',
1998 'lowercamelcase text' => array(
1999 '<span>this_is_a_text</span>',
2001 'case' => 'lowercamelcase',
2003 '<span>thisIsAText</span>',
2009 * @param string|NULL $content
2010 * @param array $configuration
2011 * @param string $expected
2012 * @dataProvider stdWrap_caseDataProvider
2015 public function stdWrap_case($content, array $configuration, $expected)
2017 $result = $this->subject
->stdWrap_case($content, $configuration);
2018 $this->assertEquals($expected, $result);
2022 * Data provider for stdWrap_bytes test
2026 public function stdWrap_bytesDataProvider()
2029 'value 1234 default' => array(
2040 'value 1234 si' => array(
2051 'value 1234 iec' => array(
2062 'value 1234 a-i' => array(
2066 'labels' => 'a|b|c|d|e|f|g|h|i',
2073 'value 1234 a-i invalid base' => array(
2077 'labels' => 'a|b|c|d|e|f|g|h|i',
2084 'value 1234567890 default' => array(
2099 * @param string|NULL $content
2100 * @param array $configuration
2101 * @param string $expected
2102 * @dataProvider stdWrap_bytesDataProvider
2105 public function stdWrap_bytes($content, array $configuration, $expected, $locale)
2107 if (!setlocale(LC_NUMERIC
, $locale)) {
2108 $this->markTestSkipped('Locale ' . $locale . ' is not available.');
2110 $result = $this->subject
->stdWrap_bytes($content, $configuration);
2111 $this->assertSame($expected, $result);
2115 * Data provider for stdWrap_substring test
2119 public function stdWrap_substringDataProvider()
2125 'substring' => '-1',
2129 'sub -1,0' => array(
2132 'substring' => '-1,0',
2136 'sub -1,-1' => array(
2139 'substring' => '-1,-1',
2143 'sub -1,1' => array(
2146 'substring' => '-1,1',
2160 'substring' => '0,0',
2164 'sub 0,-1' => array(
2167 'substring' => '0,-1',
2174 'substring' => '0,1',
2188 'substring' => '1,0',
2192 'sub 1,-1' => array(
2195 'substring' => '1,-1',
2202 'substring' => '1,1',
2217 * @param string $content
2218 * @param array $configuration
2219 * @param string $expected
2220 * @dataProvider stdWrap_substringDataProvider
2223 public function stdWrap_substring($content, array $configuration, $expected)
2225 $result = $this->subject
->stdWrap_substring($content, $configuration);
2226 $this->assertSame($expected, $result);
2230 * Data provider for stdWrap_stdWrapValue test
2234 public function stdWrap_stdWrapValueDataProvider()
2237 'only key returns value' => array(
2245 'array without key returns empty string' => array(
2253 'array without key returns default' => array(
2261 'non existing key returns default' => array(
2264 'noTrimWrap' => 'test',
2265 'noTrimWrap.' => '1',
2270 'existing key and array returns stdWrap' => array(
2274 'test.' => array('case' => 'upper'),
2283 * @param string $key
2284 * @param array $configuration
2285 * @param string $defaultValue
2286 * @param string $expected
2287 * @dataProvider stdWrap_stdWrapValueDataProvider
2290 public function stdWrap_stdWrapValue($key, array $configuration, $defaultValue, $expected)
2292 $result = $this->subject
->stdWrapValue($key, $configuration, $defaultValue);
2293 $this->assertEquals($expected, $result);
2297 * @param string|NULL $content
2298 * @param array $configuration
2299 * @param string $expected
2300 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
2303 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected)
2305 $result = $this->subject
->stdWrap_ifNull($content, $configuration);
2306 $this->assertEquals($expected, $result);
2310 * Data provider for stdWrap_ifNullDeterminesNullValues test
2314 public function stdWrap_ifNullDeterminesNullValuesDataProvider()
2317 'null value' => array(
2324 'zero value' => array(
2335 * Data provider for stdWrap_ifEmptyDeterminesEmptyValues test
2339 public function stdWrap_ifEmptyDeterminesEmptyValuesDataProvider()
2342 'null value' => array(
2349 'empty value' => array(
2356 'string value' => array(
2363 'empty string value' => array(
2374 * @param string|NULL $content
2375 * @param array $configuration
2376 * @param string $expected
2377 * @dataProvider stdWrap_ifEmptyDeterminesEmptyValuesDataProvider
2380 public function stdWrap_ifEmptyDeterminesEmptyValues($content, array $configuration, $expected)
2382 $result = $this->subject
->stdWrap_ifEmpty($content, $configuration);
2383 $this->assertEquals($expected, $result);
2388 * @param array $configuration
2390 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
2393 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected)
2395 $result = $this->subject
->stdWrap_noTrimWrap($content, $configuration);
2396 $this->assertEquals($expected, $result);
2400 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
2404 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider()
2407 'No char given' => array(
2410 'noTrimWrap' => '| left | right |',
2412 ' left middle right '
2414 'Zero char given' => array(
2417 'noTrimWrap' => '0 left 0 right 0',
2418 'noTrimWrap.' => array('splitChar' => '0'),
2421 ' left middle right '
2423 'Default char given' => array(
2426 'noTrimWrap' => '| left | right |',
2427 'noTrimWrap.' => array('splitChar' => '|'),
2429 ' left middle right '
2431 'Split char is a' => array(
2434 'noTrimWrap' => 'a left a right a',
2435 'noTrimWrap.' => array('splitChar' => 'a'),
2437 ' left middle right '
2439 'Split char is multi-char (ab)' => array(
2442 'noTrimWrap' => 'ab left ab right ab',
2443 'noTrimWrap.' => array('splitChar' => 'ab'),
2445 ' left middle right '
2447 'Split char accepts stdWrap' => array(
2450 'noTrimWrap' => 'abc left abc right abc',
2451 'noTrimWrap.' => array(
2453 'splitChar.' => array('wrap' => 'a|c'),
2456 ' left middle right '
2462 * @param array $expectedTags
2463 * @param array $configuration
2465 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
2467 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration)
2469 $this->subject
->stdWrap_addPageCacheTags('', $configuration);
2470 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock
->_get('pageCacheTags'));
2476 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider()
2481 array('addPageCacheTags' => ''),
2483 'Two expectedTags' => array(
2484 array('tag1', 'tag2'),
2485 array('addPageCacheTags' => 'tag1,tag2'),
2487 'Two expectedTags plus one with stdWrap' => array(
2488 array('tag1', 'tag2', 'tag3'),
2490 'addPageCacheTags' => 'tag1,tag2',
2491 'addPageCacheTags.' => array('wrap' => '|,tag3')
2498 * Data provider for stdWrap_encodeForJavaScriptValue test
2500 * @return array multi-dimensional array with the second level like this:
2501 * @see encodeForJavaScriptValue
2503 public function stdWrap_encodeForJavaScriptValueDataProvider()
2506 'double quote in string' => array(
2509 '\'double\u0020quote\u0022\''
2511 'backslash in string' => array(
2514 '\'backslash\u0020\u005C\''
2516 'exclamation mark' => array(
2519 '\'exclamation\u0021\''
2521 'whitespace tab, newline and carriage return' => array(
2522 "white\tspace\ns\r",
2524 '\'white\u0009space\u000As\u000D\''
2526 'single quote in string' => array(
2529 '\'single\u0020quote\u0020\u0027\''
2534 '\'\u003Ctag\u003E\''
2536 'ampersand in string' => array(
2539 '\'amper\u0026sand\''
2545 * Check if encodeForJavaScriptValue works properly
2547 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
2550 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected)
2552 $result = $this->subject
->stdWrap_encodeForJavaScriptValue($input, $conf);
2553 $this->assertEquals($expected, $result);
2556 ///////////////////////////////
2557 // Tests concerning getData()
2558 ///////////////////////////////
2563 public function getDataWithTypeGpDataProvider()
2566 'Value in get-data' => array('onlyInGet', 'GetValue'),
2567 'Value in post-data' => array('onlyInPost', 'PostValue'),
2568 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
2573 * Checks if getData() works with type "gp"
2576 * @dataProvider getDataWithTypeGpDataProvider
2578 public function getDataWithTypeGp($key, $expectedValue)
2581 'onlyInGet' => 'GetValue',
2582 'inGetAndPost' => 'ValueInGet',
2585 'onlyInPost' => 'PostValue',
2586 'inGetAndPost' => 'ValueInPost',
2588 $this->assertEquals($expectedValue, $this->subject
->getData('gp:' . $key));
2592 * Checks if getData() works with type "tsfe"
2596 public function getDataWithTypeTsfe()
2598 $this->assertEquals($GLOBALS['TSFE']->metaCharset
, $this->subject
->getData('tsfe:metaCharset'));
2602 * Checks if getData() works with type "getenv"
2606 public function getDataWithTypeGetenv()
2608 $envName = $this->getUniqueId('frontendtest');
2609 $value = $this->getUniqueId('someValue');
2610 putenv($envName . '=' . $value);
2611 $this->assertEquals($value, $this->subject
->getData('getenv:' . $envName));
2615 * Checks if getData() works with type "getindpenv"
2619 public function getDataWithTypeGetindpenv()
2621 $this->subject
->expects($this->once())->method('getEnvironmentVariable')
2622 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
2623 $this->assertEquals('dummyPath', $this->subject
->getData('getindpenv:SCRIPT_FILENAME'));
2627 * Checks if getData() works with type "field"
2631 public function getDataWithTypeField()
2634 $value = 'someValue';
2635 $field = array($key => $value);
2637 $this->assertEquals($value, $this->subject
->getData('field:' . $key, $field));
2641 * Checks if getData() works with type "field" of the field content
2642 * is multi-dimensional (e.g. an array)
2646 public function getDataWithTypeFieldAndFieldIsMultiDimensional()
2648 $key = 'somekey|level1|level2';
2649 $value = 'somevalue';
2650 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
2652 $this->assertEquals($value, $this->subject
->getData('field:' . $key, $field));
2656 * Basic check if getData gets the uid of a file object
2660 public function getDataWithTypeFileReturnsUidOfFileObject()
2662 $uid = $this->getUniqueId();
2663 $file = $this->getMock(\TYPO3\CMS\Core\
Resource\File
::class, array(), array(), '', false);
2664 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
2665 $this->subject
->setCurrentFile($file);
2666 $this->assertEquals($uid, $this->subject
->getData('file:current:uid'));
2670 * Checks if getData() works with type "parameters"
2674 public function getDataWithTypeParameters()
2676 $key = $this->getUniqueId('someKey');
2677 $value = $this->getUniqueId('someValue');
2678 $this->subject
->parameters
[$key] = $value;
2680 $this->assertEquals($value, $this->subject
->getData('parameters:' . $key));
2684 * Checks if getData() works with type "register"
2688 public function getDataWithTypeRegister()
2690 $key = $this->getUniqueId('someKey');
2691 $value = $this->getUniqueId('someValue');
2692 $GLOBALS['TSFE']->register
[$key] = $value;
2694 $this->assertEquals($value, $this->subject
->getData('register:' . $key));
2698 * Checks if getData() works with type "level"
2702 public function getDataWithTypeLevel()
2705 0 => array('uid' => 1, 'title' => 'title1'),
2706 1 => array('uid' => 2, 'title' => 'title2'),
2707 2 => array('uid' => 3, 'title' => 'title3'),
2710 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2711 $this->assertEquals(2, $this->subject
->getData('level'));
2715 * Checks if getData() works with type "global"
2719 public function getDataWithTypeGlobal()
2721 $this->assertEquals($GLOBALS['TSFE']->metaCharset
, $this->subject
->getData('global:TSFE|metaCharset'));
2725 * Checks if getData() works with type "leveltitle"
2729 public function getDataWithTypeLeveltitle()
2732 0 => array('uid' => 1, 'title' => 'title1'),
2733 1 => array('uid' => 2, 'title' => 'title2'),
2734 2 => array('uid' => 3, 'title' => ''),
2737 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2738 $this->assertEquals('', $this->subject
->getData('leveltitle:-1'));
2739 // since "title3" is not set, it will slide to "title2"
2740 $this->assertEquals('title2', $this->subject
->getData('leveltitle:-1,slide'));
2744 * Checks if getData() works with type "levelmedia"
2748 public function getDataWithTypeLevelmedia()
2751 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
2752 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
2753 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
2756 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2757 $this->assertEquals('', $this->subject
->getData('levelmedia:-1'));
2758 // since "title3" is not set, it will slide to "title2"
2759 $this->assertEquals('media2', $this->subject
->getData('levelmedia:-1,slide'));
2763 * Checks if getData() works with type "leveluid"
2767 public function getDataWithTypeLeveluid()
2770 0 => array('uid' => 1, 'title' => 'title1'),
2771 1 => array('uid' => 2, 'title' => 'title2'),
2772 2 => array('uid' => 3, 'title' => 'title3'),
2775 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2776 $this->assertEquals(3, $this->subject
->getData('leveluid:-1'));
2777 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
2778 $this->assertEquals(3, $this->subject
->getData('leveluid:-1,slide'));
2782 * Checks if getData() works with type "levelfield"
2786 public function getDataWithTypeLevelfield()
2789 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2790 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2791 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2794 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2795 $this->assertEquals('', $this->subject
->getData('levelfield:-1,testfield'));
2796 $this->assertEquals('field2', $this->subject
->getData('levelfield:-1,testfield,slide'));
2800 * Checks if getData() works with type "fullrootline"
2804 public function getDataWithTypeFullrootline()
2807 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2810 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2811 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2812 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2815 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline1;
2816 $GLOBALS['TSFE']->rootLine
= $rootline2;
2817 $this->assertEquals('field2', $this->subject
->getData('fullrootline:-1,testfield'));
2821 * Checks if getData() works with type "date"
2825 public function getDataWithTypeDate()
2828 $defaultFormat = 'd/m Y';
2830 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject
->getData('date:' . $format));
2831 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject
->getData('date'));
2835 * Checks if getData() works with type "page"
2839 public function getDataWithTypePage()
2842 $GLOBALS['TSFE']->page
['uid'] = $uid;
2843 $this->assertEquals($uid, $this->subject
->getData('page:uid'));
2847 * Checks if getData() works with type "current"
2851 public function getDataWithTypeCurrent()
2853 $key = $this->getUniqueId('someKey');
2854 $value = $this->getUniqueId('someValue');
2855 $this->subject
->data
[$key] = $value;
2856 $this->subject
->currentValKey
= $key;
2857 $this->assertEquals($value, $this->subject
->getData('current'));
2861 * Checks if getData() works with type "db"
2865 public function getDataWithTypeDb()
2867 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2869 $GLOBALS['TSFE']->sys_page
->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2870 $this->assertEquals($dummyRecord['title'], $this->subject
->getData('db:tt_content:106:title'));
2874 * Checks if getData() works with type "lll"
2878 public function getDataWithTypeLll()
2880 $key = $this->getUniqueId('someKey');
2881 $value = $this->getUniqueId('someValue');
2882 $language = $this->getUniqueId('someLanguage');
2883 $GLOBALS['TSFE']->LL_labels_cache
[$language]['LLL:' . $key] = $value;
2884 $GLOBALS['TSFE']->lang
= $language;
2886 $this->assertEquals($value, $this->subject
->getData('lll:' . $key));
2890 * Checks if getData() works with type "path"
2894 public function getDataWithTypePath()
2896 $filenameIn = $this->getUniqueId('someValue');
2897 $filenameOut = $this->getUniqueId('someValue');
2898 $this->templateServiceMock
->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2899 $this->assertEquals($filenameOut, $this->subject
->getData('path:' . $filenameIn));
2903 * Checks if getData() works with type "parentRecordNumber"
2907 public function getDataWithTypeParentRecordNumber()
2909 $recordNumber = rand();
2910 $this->subject
->parentRecordNumber
= $recordNumber;
2911 $this->assertEquals($recordNumber, $this->subject
->getData('cobj:parentRecordNumber'));
2915 * Checks if getData() works with type "debug:rootLine"
2919 public function getDataWithTypeDebugRootline()
2922 0 => array('uid' => 1, 'title' => 'title1'),
2923 1 => array('uid' => 2, 'title' => 'title2'),
2924 2 => array('uid' => 3, 'title' => ''),
2926 $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)';
2927 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2929 $result = $this->subject
->getData('debug:rootLine');
2930 $cleanedResult = strip_tags($result);
2931 $cleanedResult = str_replace("\r", '', $cleanedResult);
2932 $cleanedResult = str_replace("\n", '', $cleanedResult);
2933 $cleanedResult = str_replace("\t", '', $cleanedResult);
2934 $cleanedResult = str_replace(' ', '', $cleanedResult);
2936 $this->assertEquals($expectedResult, $cleanedResult);
2940 * Checks if getData() works with type "debug:fullRootLine"
2944 public function getDataWithTypeDebugFullRootline()
2947 0 => array('uid' => 1, 'title' => 'title1'),
2948 1 => array('uid' => 2, 'title' => 'title2'),
2949 2 => array('uid' => 3, 'title' => ''),
2951 $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)';
2952 $GLOBALS['TSFE']->rootLine
= $rootline;
2954 $result = $this->subject
->getData('debug:fullRootLine');
2955 $cleanedResult = strip_tags($result);
2956 $cleanedResult = str_replace("\r", '', $cleanedResult);
2957 $cleanedResult = str_replace("\n", '', $cleanedResult);
2958 $cleanedResult = str_replace("\t", '', $cleanedResult);
2959 $cleanedResult = str_replace(' ', '', $cleanedResult);
2961 $this->assertEquals($expectedResult, $cleanedResult);
2965 * Checks if getData() works with type "debug:data"
2969 public function getDataWithTypeDebugData()
2971 $key = $this->getUniqueId('someKey');
2972 $value = $this->getUniqueId('someValue');
2973 $this->subject
->data
= array($key => $value);
2975 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2977 $result = $this->subject
->getData('debug:data');
2978 $cleanedResult = strip_tags($result);
2979 $cleanedResult = str_replace("\r", '', $cleanedResult);
2980 $cleanedResult = str_replace("\n", '', $cleanedResult);
2981 $cleanedResult = str_replace("\t", '', $cleanedResult);
2982 $cleanedResult = str_replace(' ', '', $cleanedResult);
2984 $this->assertEquals($expectedResult, $cleanedResult);
2988 * Checks if getData() works with type "debug:register"
2992 public function getDataWithTypeDebugRegister()
2994 $key = $this->getUniqueId('someKey');
2995 $value = $this->getUniqueId('someValue');
2996 $GLOBALS['TSFE']->register
= array($key => $value);
2998 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
3000 $result = $this->subject
->getData('debug:register');
3001 $cleanedResult = strip_tags($result);
3002 $cleanedResult = str_replace("\r", '', $cleanedResult);
3003 $cleanedResult = str_replace("\n", '', $cleanedResult);
3004 $cleanedResult = str_replace("\t", '', $cleanedResult);
3005 $cleanedResult = str_replace(' ', '', $cleanedResult);
3007 $this->assertEquals($expectedResult, $cleanedResult);
3011 * Checks if getData() works with type "data:page"
3015 public function getDataWithTypeDebugPage()
3018 $GLOBALS['TSFE']->page
= array('uid' => $uid);
3020 $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
3022 $result = $this->subject
->getData('debug:page');
<