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\Utility\GeneralUtility
;
22 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
;
25 * Testcase for TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
27 class ContentObjectRendererTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
30 * @var array A backup of registered singleton instances
32 protected $singletonInstances = array();
35 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
37 protected $subject = NULL;
40 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
42 protected $typoScriptFrontendControllerMock = NULL;
45 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\TypoScript\TemplateService
47 protected $templateServiceMock = NULL;
50 * Default content object name -> class name map, shipped with TYPO3 CMS
54 protected $contentObjectMap = array(
55 'TEXT' => \TYPO3\CMS\Frontend\ContentObject\TextContentObject
::class,
56 'CASE' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject
::class,
57 'COBJ_ARRAY' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
::class,
58 'COA' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
::class,
59 'COA_INT' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayInternalContentObject
::class,
60 'USER' => \TYPO3\CMS\Frontend\ContentObject\UserContentObject
::class,
61 'USER_INT' => \TYPO3\CMS\Frontend\ContentObject\UserInternalContentObject
::class,
62 'FILE' => \TYPO3\CMS\Frontend\ContentObject\FileContentObject
::class,
63 'FILES' => \TYPO3\CMS\Frontend\ContentObject\FilesContentObject
::class,
64 'IMAGE' => \TYPO3\CMS\Frontend\ContentObject\ImageContentObject
::class,
65 'IMG_RESOURCE' => \TYPO3\CMS\Frontend\ContentObject\ImageResourceContentObject
::class,
66 'CONTENT' => \TYPO3\CMS\Frontend\ContentObject\ContentContentObject
::class,
67 'RECORDS' => \TYPO3\CMS\Frontend\ContentObject\RecordsContentObject
::class,
68 'HMENU' => \TYPO3\CMS\Frontend\ContentObject\HierarchicalMenuContentObject
::class,
69 'CASEFUNC' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject
::class,
70 'LOAD_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\LoadRegisterContentObject
::class,
71 'RESTORE_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\RestoreRegisterContentObject
::class,
72 'TEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\TemplateContentObject
::class,
73 'FLUIDTEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject
::class,
74 'SVG' => \TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject
::class,
75 'EDITPANEL' => \TYPO3\CMS\Frontend\ContentObject\EditPanelContentObject
::class
81 protected function setUp() {
82 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
83 $this->createMockedLoggerAndLogManager();
85 $this->templateServiceMock
= $this->getMock(\TYPO3\CMS\Core\TypoScript\TemplateService
::class, array('getFileName', 'linkData'));
86 $pageRepositoryMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository
::class, array('getRawRecord'));
88 $this->typoScriptFrontendControllerMock
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
::class, array('dummy'), array(), '', FALSE);
89 $this->typoScriptFrontendControllerMock
->tmpl
= $this->templateServiceMock
;
90 $this->typoScriptFrontendControllerMock
->config
= array();
91 $this->typoScriptFrontendControllerMock
->page
= array();
92 $this->typoScriptFrontendControllerMock
->sys_page
= $pageRepositoryMock;
93 $this->typoScriptFrontendControllerMock
->csConvObj
= new CharsetConverter();
94 $this->typoScriptFrontendControllerMock
->renderCharset
= 'utf-8';
95 $GLOBALS['TSFE'] = $this->typoScriptFrontendControllerMock
;
97 $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection
::class, array());
98 $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring';
100 $this->subject
= $this->getAccessibleMock(
101 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
102 array('getResourceFactory', 'getEnvironmentVariable'),
103 array($this->typoScriptFrontendControllerMock
)
105 $this->subject
->setContentObjectClassMap($this->contentObjectMap
);
106 $this->subject
->start(array(), 'tt_content');
109 protected function tearDown() {
110 GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
114 ////////////////////////
115 // Utitility functions
116 ////////////////////////
119 * Avoid logging to the file system (file writer is currently the only configured writer)
121 protected function createMockedLoggerAndLogManager() {
122 $logManagerMock = $this->getMock(LogManager
::class);
123 $loggerMock = $this->getMock(LoggerInterface
::class);
124 $logManagerMock->expects($this->any())
125 ->method('getLogger')
126 ->willReturn($loggerMock);
127 GeneralUtility
::setSingletonInstance(LogManager
::class, $logManagerMock);
131 * Converts the subject and the expected result into the target charset.
133 * @param string $charset the target charset
134 * @param string $subject the subject, will be modified
135 * @param string $expected the expected result, will be modified
137 protected function handleCharset($charset, &$subject, &$expected) {
138 $GLOBALS['TSFE']->renderCharset
= $charset;
139 $subject = $GLOBALS['TSFE']->csConvObj
->conv($subject, 'iso-8859-1', $charset);
140 $expected = $GLOBALS['TSFE']->csConvObj
->conv($expected, 'iso-8859-1', $charset);
143 /////////////////////////////////////////////
144 // Tests concerning the getImgResource hook
145 /////////////////////////////////////////////
149 public function getImgResourceCallsGetImgResourcePostProcessHook() {
150 $this->templateServiceMock
151 ->expects($this->atLeastOnce())
152 ->method('getFileName')
153 ->with('typo3/clear.gif')
154 ->will($this->returnValue('typo3/clear.gif'));
156 $resourceFactory = $this->getMock(\TYPO3\CMS\Core\
Resource\ResourceFactory
::class, array(), array(), '', FALSE);
157 $this->subject
->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
159 $className = $this->getUniqueId('tx_coretest');
160 $getImgResourceHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectGetImageResourceHookInterface
::class, array('getImgResourcePostProcess'), array(), $className);
161 $getImgResourceHookMock
162 ->expects($this->once())
163 ->method('getImgResourcePostProcess')
164 ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
165 $getImgResourceHookObjects = array($getImgResourceHookMock);
166 $this->subject
->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
167 $this->subject
->getImgResource('typo3/clear.gif', array());
171 * Handles the arguments that have been sent to the getImgResource hook.
174 * @see getImgResourceHookGetsCalled
176 public function isGetImgResourceHookCalledCallback() {
177 list($file, $fileArray, $imageResource, $parent) = func_get_args();
178 $this->assertEquals('typo3/clear.gif', $file);
179 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
180 $this->assertTrue(is_array($fileArray));
181 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
);
182 return $imageResource;
186 /*************************
187 * Tests concerning getContentObject
188 ************************/
190 public function getContentObjectValidContentObjectsDataProvider() {
191 $dataProvider = array();
192 foreach ($this->contentObjectMap
as $name => $className) {
193 $dataProvider[] = array($name, $className);
195 return $dataProvider;
200 * @dataProvider getContentObjectValidContentObjectsDataProvider
201 * @param string $name TypoScript name of content object
202 * @param string $fullClassName Expected class name
204 public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $fullClassName) {
205 $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', FALSE);
206 \TYPO3\CMS\Core\Utility\GeneralUtility
::addInstance($fullClassName, $contentObjectInstance);
207 $this->assertSame($contentObjectInstance, $this->subject
->getContentObject($name));
210 /////////////////////////////////////////
211 // Tests concerning getQueryArguments()
212 /////////////////////////////////////////
216 public function getQueryArgumentsExcludesParameters() {
217 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
218 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
220 $getQueryArgumentsConfiguration = array();
221 $getQueryArgumentsConfiguration['exclude'] = array();
222 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
223 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
224 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
225 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
226 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
227 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
228 $this->assertEquals($expectedResult, $actualResult);
234 public function getQueryArgumentsExcludesGetParameters() {
239 'key31' => 'value31',
241 'key321' => 'value321',
242 'key322' => 'value322'
246 $getQueryArgumentsConfiguration = array();
247 $getQueryArgumentsConfiguration['method'] = 'GET';
248 $getQueryArgumentsConfiguration['exclude'] = array();
249 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
250 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
251 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
252 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
253 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
254 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
255 $this->assertEquals($expectedResult, $actualResult);
261 public function getQueryArgumentsOverrulesSingleParameter() {
262 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
263 $this->returnValue('key1=value1')
265 $getQueryArgumentsConfiguration = array();
266 $overruleArguments = array(
267 // Should be overridden
268 'key1' => 'value1Overruled',
269 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
270 'key2' => 'value2Overruled'
272 $expectedResult = '&key1=value1Overruled';
273 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
274 $this->assertEquals($expectedResult, $actualResult);
280 public function getQueryArgumentsOverrulesMultiDimensionalParameters() {
285 'key31' => 'value31',
287 'key321' => 'value321',
288 'key322' => 'value322'
292 $getQueryArgumentsConfiguration = array();
293 $getQueryArgumentsConfiguration['method'] = 'POST';
294 $getQueryArgumentsConfiguration['exclude'] = array();
295 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
296 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
297 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
298 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
299 $overruleArguments = array(
300 // Should be overriden
301 'key2' => 'value2Overruled',
304 // Shouldn't be set: Parameter is excluded and not forced
305 'key321' => 'value321Overruled',
306 // Should be overriden: Parameter is not excluded
307 'key322' => 'value322Overruled',
308 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
309 'key323' => 'value323Overruled'
313 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
314 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
315 $this->assertEquals($expectedResult, $actualResult);
321 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters() {
322 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
323 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
329 'key31' => 'value31',
331 'key321' => 'value321',
332 'key322' => 'value322'
336 $getQueryArgumentsConfiguration = array();
337 $getQueryArgumentsConfiguration['exclude'] = array();
338 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
339 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
340 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
341 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
342 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
343 $overruleArguments = array(
344 // Should be overriden
345 'key2' => 'value2Overruled',
348 // Should be set: Parameter is excluded but forced
349 'key321' => 'value321Overruled',
350 // Should be set: Parameter doesn't exist in source array but is forced
351 'key323' => 'value323Overruled'
355 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
356 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
357 $this->assertEquals($expectedResult, $actualResult);
358 $getQueryArgumentsConfiguration['method'] = 'POST';
359 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
360 $this->assertEquals($expectedResult, $actualResult);
366 public function getQueryArgumentsWithMethodPostGetMergesParameters() {
374 'key331' => 'POST331',
375 'key332' => 'POST332',
384 'key331' => 'GET331',
388 $getQueryArgumentsConfiguration = array();
389 $getQueryArgumentsConfiguration['method'] = 'POST,GET';
390 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
391 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
392 $this->assertEquals($expectedResult, $actualResult);
398 public function getQueryArgumentsWithMethodGetPostMergesParameters() {
406 'key331' => 'GET331',
407 'key332' => 'GET332',
416 'key331' => 'POST331',
420 $getQueryArgumentsConfiguration = array();
421 $getQueryArgumentsConfiguration['method'] = 'GET,POST';
422 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
423 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
424 $this->assertEquals($expectedResult, $actualResult);
428 * Encodes square brackets in URL.
430 * @param string $string
433 private function rawUrlEncodeSquareBracketsInUrl($string) {
434 return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
437 //////////////////////////////
438 // Tests concerning crop
439 //////////////////////////////
443 public function cropIsMultibyteSafe() {
444 $this->assertEquals('бла', $this->subject
->crop('бла', '3|...'));
447 //////////////////////////////
448 // Tests concerning cropHTML
449 //////////////////////////////
451 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
452 * of charset, text type, and configuration options to be tested.
454 * @return array two-dimensional array with the second level like this:
455 * @see cropHtmlWithDataProvider
457 public function cropHtmlDataProvider() {
458 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
459 $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.';
460 $textWithEntities = 'Kasper Skårhøj implemented the; original ' . 'version of the crop function.';
461 $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
463 foreach ($charsets as $charset) {
464 $data = array_merge($data, array(
465 $charset . ' plain text; 11|...' => array(
468 'Kasper Sk' . chr(229) . 'r...',
471 $charset . ' plain text; -58|...' => array(
474 '...h' . chr(248) . 'j implemented the original version of the crop function.',
477 $charset . ' plain text; 4|...|1' => array(
483 $charset . ' plain text; 20|...|1' => array(
486 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...',
489 $charset . ' plain text; -5|...|1' => array(
495 $charset . ' plain text; -49|...|1' => array(
498 '...the original version of the crop function.',
501 $charset . ' text with markup; 11|...' => array(
504 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>',
507 $charset . ' text with markup; 13|...' => array(
510 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>',
513 $charset . ' text with markup; 14|...' => array(
516 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
519 $charset . ' text with markup; 15|...' => array(
522 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>',
525 $charset . ' text with markup; 29|...' => array(
528 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...',
531 $charset . ' text with markup; -58|...' => array(
534 '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
537 $charset . ' text with markup 4|...|1' => array(
540 '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>',
543 $charset . ' text with markup; 11|...|1' => array(
546 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
549 $charset . ' text with markup; 13|...|1' => array(
552 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>',
555 $charset . ' text with markup; 14|...|1' => array(
558 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
561 $charset . ' text with markup; 15|...|1' => array(
564 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>',
567 $charset . ' text with markup; 29|...|1' => array(
570 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...',
573 $charset . ' text with markup; -66|...|1' => array(
576 '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.',
579 $charset . ' text with entities 9|...' => array(
585 $charset . ' text with entities 10|...' => array(
588 'Kasper Skå...',
591 $charset . ' text with entities 11|...' => array(
594 'Kasper Skår...',
597 $charset . ' text with entities 13|...' => array(
600 'Kasper Skårhø...',
603 $charset . ' text with entities 14|...' => array(
606 'Kasper Skårhøj...',
609 $charset . ' text with entities 15|...' => array(
612 'Kasper Skårhøj ...',
615 $charset . ' text with entities 16|...' => array(
618 'Kasper Skårhøj i...',
621 $charset . ' text with entities -57|...' => array(
624 '...j implemented the; original version of the crop function.',
627 $charset . ' text with entities -58|...' => array(
630 '...øj implemented the; original version of the crop function.',
633 $charset . ' text with entities -59|...' => array(
636 '...høj implemented the; original version of the crop function.',
639 $charset . ' text with entities 4|...|1' => array(
645 $charset . ' text with entities 9|...|1' => array(
651 $charset . ' text with entities 10|...|1' => array(
657 $charset . ' text with entities 11|...|1' => array(
663 $charset . ' text with entities 13|...|1' => array(
669 $charset . ' text with entities 14|...|1' => array(
672 'Kasper Skårhøj...',
675 $charset . ' text with entities 15|...|1' => array(
678 'Kasper Skårhøj...',
681 $charset . ' text with entities 16|...|1' => array(
684 'Kasper Skårhøj...',
687 $charset . ' text with entities -57|...|1' => array(
690 '...implemented the; original version of the crop function.',
693 $charset . ' text with entities -58|...|1' => array(
696 '...implemented the; original version of the crop function.',
699 $charset . ' text with entities -59|...|1' => array(
702 '...implemented the; original version of the crop function.',
705 $charset . ' text with dash in html-element 28|...|1' => array(
707 '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',
708 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>',
711 $charset . ' html elements with dashes in attributes' => array(
713 '<em data-foo="x">foobar</em>foobaz',
714 '<em data-foo="x">foobar</em>foo',
723 * Checks if stdWrap.cropHTML works with plain text cropping from left
726 * @dataProvider cropHtmlDataProvider
727 * @param string $settings
728 * @param string $subject the string to crop
729 * @param string $expected the expected cropped result
730 * @param string $charset the charset that will be set as renderCharset
732 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
733 $this->handleCharset($charset, $subject, $expected);
734 $this->assertEquals($expected, $this->subject
->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"');
738 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
739 * counts multiple invisible characters not as one (as the browser will output the content).
743 public function cropHtmlWorksWithComplexContent() {
744 $GLOBALS['TSFE']->renderCharset
= 'iso-8859-1';
746 '<h1>Blog Example</h1>' . LF
.
748 '<div class="csc-header csc-header-n1">' . LF
.
749 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF
.
751 '<p class="bodytext">' . LF
.
752 ' A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.' . LF
.
754 '<div class="tx-blogexample-list-container">' . LF
.
755 ' <p class="bodytext">' . LF
.
756 ' Below are the most recent posts:' . LF
.
759 ' <li data-element="someId">' . LF
.
761 ' <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
.
763 ' <p class="bodytext">' . LF
.
764 ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...' . LF
.
766 ' <p class="metadata">' . LF
.
767 ' Published on 26.08.2009 by Jochen Rau' . LF
.
770 ' Tags: [MVC] [Domain Driven Design] <br>' . LF
.
771 ' <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
.
772 ' <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
.
777 ' <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
.
782 ' ? TYPO3 Association' . LF
.
785 $result = $this->subject
->cropHTML($input, '300');
788 '<h1>Blog Example</h1>' . LF
.
790 '<div class="csc-header csc-header-n1">' . LF
.
791 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF
.
793 '<p class="bodytext">' . LF
.
794 ' A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.' . LF
.
796 '<div class="tx-blogexample-list-container">' . LF
.
797 ' <p class="bodytext">' . LF
.
798 ' Below are the most recent posts:' . LF
.
801 ' <li data-element="someId">' . LF
.
803 ' <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>';
805 $this->assertEquals($expected, $result);
807 $result = $this->subject
->cropHTML($input, '-100');
810 '<div class="tx-blogexample-list-container"><ul><li data-element="someId"><p> Design] <br>' . LF
.
811 ' <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
.
812 ' <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
.
817 ' <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
.
822 ' ? TYPO3 Association' . LF
.
825 $this->assertEquals($expected, $result);
831 public function stdWrap_roundDataProvider() {
833 'rounding off without any configuration' => array(
838 'rounding up without any configuration' => array(
843 'regular rounding (off) to two decimals' => array(
850 'regular rounding (up) to two decimals' => array(
857 'rounding up to integer with type ceil' => array(
860 'roundType' => 'ceil'
864 'rounding down to integer with type floor' => array(
867 'roundType' => 'floor'
875 * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
879 public function cropHtmlWorksWithLinebreaks() {
880 $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
881 $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
882 $result = $this->subject
->cropHTML($subject, '121');
883 $this->assertEquals($expected, $result);
887 * Test for the stdWrap function "round"
889 * @param float $float
891 * @param float $expected
893 * @dataProvider stdWrap_roundDataProvider
896 public function stdWrap_round($float, $conf, $expected) {
900 $result = $this->subject
->stdWrap_round($float, $conf);
901 $this->assertEquals($expected, $result);
907 public function stdWrap_strPadDataProvider() {
909 'pad string with default settings and length 10' => array(
916 'pad string with padWith -= and type left and length 10' => array(
925 'pad string with padWith _ and type both and length 10' => array(
934 'pad string with padWith 0 and type both and length 10' => array(
943 'pad string with padWith ___ and type both and length 6' => array(
952 'pad string with padWith _ and type both and length 12, using stdWrap for length' => array(
964 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => array(
976 'pad string with padWith _ and type both and length 12, using stdWrap for type' => array(
982 // make type become "left"
984 'substring' => '2,1',
994 * Test for the stdWrap function "strPad"
996 * @param string $content
998 * @param string $expected
1000 * @dataProvider stdWrap_strPadDataProvider
1003 public function stdWrap_strPad($content, $conf, $expected) {
1007 $result = $this->subject
->stdWrap_strPad($content, $conf);
1008 $this->assertEquals($expected, $result);
1012 * Data provider for the hash test
1014 * @return array multi-dimensional array with the second level like this:
1017 public function hashDataProvider() {
1019 'testing md5' => array(
1024 'bacb98acf97e0b6112b1d1b650b84971'
1026 'testing sha1' => array(
1031 '063b3d108bed9f88fa618c6046de0dccadcf3158'
1033 'testing non-existing hashing algorithm' => array(
1036 'hash' => 'non-existing'
1040 'testing stdWrap capability' => array(
1044 'cObject' => 'TEXT',
1045 'cObject.' => array(
1050 'bacb98acf97e0b6112b1d1b650b84971'
1057 * Test for the stdWrap function "hash"
1059 * @param string $text
1060 * @param array $conf
1061 * @param string $expected
1063 * @dataProvider hashDataProvider
1066 public function stdWrap_hash($text, array $conf, $expected) {
1067 $result = $this->subject
->stdWrap_hash($text, $conf);
1068 $this->assertEquals($expected, $result);
1074 public function recursiveStdWrapProperlyRendersBasicString() {
1075 $stdWrapConfiguration = array(
1076 'noTrimWrap' => '|| 123|',
1077 'stdWrap.' => array(
1078 'wrap' => '<b>|</b>'
1083 $this->subject
->stdWrap('Test', $stdWrapConfiguration)
1090 public function recursiveStdWrapIsOnlyCalledOnce() {
1091 $stdWrapConfiguration = array(
1094 'data' => 'register:Counter'
1096 'stdWrap.' => array(
1097 'append' => 'LOAD_REGISTER',
1099 'Counter.' => array(
1100 'prioriCalc' => 'intval',
1101 'cObject' => 'TEXT',
1102 'cObject.' => array(
1103 'data' => 'register:Counter',
1112 $this->subject
->stdWrap('Counter:', $stdWrapConfiguration)
1117 * Data provider for the numberFormat test
1119 * @return array multi-dimensional array with the second level like this:
1122 public function numberFormatDataProvider() {
1124 'testing decimals' => array(
1131 'testing decimals with input as string' => array(
1138 'testing dec_point' => array(
1146 'testing thousands_sep' => array(
1150 'thousands_sep.' => array(
1156 'testing mixture' => array(
1160 'dec_point.' => array(
1163 'thousands_sep.' => array(
1174 * Check if stdWrap.numberFormat and all of its properties work properly
1176 * @dataProvider numberFormatDataProvider
1179 public function numberFormat($float, $formatConf, $expected) {
1180 $result = $this->subject
->numberFormat($float, $formatConf);
1181 $this->assertEquals($expected, $result);
1185 * Data provider for the replacement test
1187 * @return array multi-dimensional array with the second level like this:
1190 public function replacementDataProvider() {
1192 'multiple replacements, including regex' => array(
1193 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1195 'replacement.' => array(
1197 'search' => 'in da hood',
1198 'replace' => 'around the block'
1202 'replace.' => array('char' => '32')
1205 'search' => '#a (Cat|Dog|Tiger)#i',
1206 'replace' => 'an animal',
1211 'There is an animal, an animal and an animal around the block! Yeah!'
1213 'replacement with optionSplit, normal pattern' => array(
1214 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
1216 'replacement.' => array(
1219 'replace' => '1 || 2 || 3',
1220 'useOptionSplitReplace' => '1'
1224 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!'
1226 'replacement with optionSplit, using regex' => array(
1227 'There is a cat, a dog and a tiger in da hood! Yeah!',
1229 'replacement.' => array(
1231 'search' => '#(a) (Cat|Dog|Tiger)#i',
1232 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
1233 'useOptionSplitReplace' => '1',
1238 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!'
1245 * Check if stdWrap.replacement and all of its properties work properly
1247 * @dataProvider replacementDataProvider
1250 public function replacement($input, $conf, $expected) {
1251 $result = $this->subject
->stdWrap_replacement($input, $conf);
1252 $this->assertEquals($expected, $result);
1256 * Data provider for the getQuery test
1258 * @return array multi-dimensional array with the second level like this:
1261 public function getQueryDataProvider() {
1263 'testing empty conf' => array(
1270 'testing #17284: adding uid/pid for workspaces' => array(
1273 'selectFields' => 'header,bodytext'
1276 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1279 'testing #17284: no need to add' => array(
1282 'selectFields' => 'tt_content.*'
1285 'SELECT' => 'tt_content.*'
1288 'testing #17284: no need to add #2' => array(
1291 'selectFields' => '*'
1297 'testing #29783: joined tables, prefix tablename' => array(
1300 'selectFields' => 'tt_content.header,be_users.username',
1301 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
1304 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
1307 'testing #34152: single count(*), add nothing' => array(
1310 'selectFields' => 'count(*)'
1313 'SELECT' => 'count(*)'
1316 'testing #34152: single max(crdate), add nothing' => array(
1319 'selectFields' => 'max(crdate)'
1322 'SELECT' => 'max(crdate)'
1325 'testing #34152: single min(crdate), add nothing' => array(
1328 'selectFields' => 'min(crdate)'
1331 'SELECT' => 'min(crdate)'
1334 'testing #34152: single sum(is_siteroot), add nothing' => array(
1337 'selectFields' => 'sum(is_siteroot)'
1340 'SELECT' => 'sum(is_siteroot)'
1343 'testing #34152: single avg(crdate), add nothing' => array(
1346 'selectFields' => 'avg(crdate)'
1349 'SELECT' => 'avg(crdate)'
1357 * Check if sanitizeSelectPart works as expected
1359 * @dataProvider getQueryDataProvider
1362 public function getQuery($table, $conf, $expected) {
1363 $GLOBALS['TCA'] = array(
1366 'enablecolumns' => array(
1367 'disabled' => 'hidden'
1371 'tt_content' => array(
1373 'enablecolumns' => array(
1374 'disabled' => 'hidden'
1380 $result = $this->subject
->getQuery($table, $conf, TRUE);
1381 foreach ($expected as $field => $value) {
1382 $this->assertEquals($value, $result[$field]);
1389 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet() {
1390 $GLOBALS['TCA'] = array(
1393 'enablecolumns' => array(
1394 'disabled' => 'hidden'
1398 'tt_content' => array(
1400 'enablecolumns' => array(
1401 'disabled' => 'hidden'
1406 $this->subject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class, array('getTreeList'));
1407 $this->subject
->start(array(), 'tt_content');
1409 'recursive' => '15',
1410 'pidInList' => '16, -35'
1412 $this->subject
->expects($this->at(0))
1413 ->method('getTreeList')
1415 ->will($this->returnValue('15,16'));
1416 $this->subject
->expects($this->at(1))
1417 ->method('getTreeList')
1419 ->will($this->returnValue('15,35'));
1420 $this->subject
->getQuery('tt_content', $conf, TRUE);
1426 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet() {
1427 $GLOBALS['TCA'] = array(
1430 'enablecolumns' => array(
1431 'disabled' => 'hidden'
1435 'tt_content' => array(
1437 'enablecolumns' => array(
1438 'disabled' => 'hidden'
1443 $this->subject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class, array('getTreeList'));
1444 $GLOBALS['TSFE']->id
= 27;
1445 $this->subject
->start(array(), 'tt_content');
1447 'pidInList' => 'this',
1450 $this->subject
->expects($this->once())
1451 ->method('getTreeList')
1453 ->will($this->returnValue('27'));
1454 $this->subject
->getQuery('tt_content', $conf, TRUE);
1458 * Data provider for the stdWrap_strftime test
1460 * @return array multi-dimensional array with the second level like this:
1461 * @see stdWrap_strftime
1463 public function stdWrap_strftimeReturnsFormattedStringDataProvider() {
1465 'given timestamp' => array(
1466 1346500800, // This is 2012-09-01 12:00 in UTC/GMT
1468 'strftime' => '%d-%m-%Y',
1471 'empty string' => array(
1474 'strftime' => '%d-%m-%Y',
1477 'testing null' => array(
1480 'strftime' => '%d-%m-%Y',
1489 * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
1491 public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
1492 // Set exec_time to a hard timestamp
1493 $GLOBALS['EXEC_TIME'] = 1346500800;
1494 // Save current timezone and set to UTC to make the system under test behave
1495 // the same in all server timezone settings
1496 $timezoneBackup = date_default_timezone_get();
1497 date_default_timezone_set('UTC');
1499 $result = $this->subject
->stdWrap_strftime($content, $conf);
1502 date_default_timezone_set($timezoneBackup);
1504 $this->assertEquals('01-09-2012', $result);
1508 * Data provider for the stdWrap_strtotime test
1511 * @see stdWrap_strtotime
1513 public function stdWrap_strtotimeReturnsTimestampDataProvider() {
1515 'date from content' => array(
1522 'manipulation of date from content' => array(
1525 'strtotime' => '+ 2 weekdays',
1529 'date from configuration' => array(
1532 'strtotime' => '2014-12-04',
1536 'manipulation of date from configuration' => array(
1539 'strtotime' => '2014-12-04 + 2 weekdays',
1543 'empty input' => array(
1550 'date from content and configuration' => array(
1553 'strtotime' => '2014-12-05',
1561 * @param string|NULL $content
1562 * @param array $configuration
1563 * @param int $expected
1564 * @dataProvider stdWrap_strtotimeReturnsTimestampDataProvider
1567 public function stdWrap_strtotimeReturnsTimestamp($content, $configuration, $expected) {
1568 // Set exec_time to a hard timestamp
1569 $GLOBALS['EXEC_TIME'] = 1417392000;
1570 // Save current timezone and set to UTC to make the system under test behave
1571 // the same in all server timezone settings
1572 $timezoneBackup = date_default_timezone_get();
1573 date_default_timezone_set('UTC');
1575 $result = $this->subject
->stdWrap_strtotime($content, $configuration);
1578 date_default_timezone_set($timezoneBackup);
1580 $this->assertEquals($expected, $result);
1584 * @param string|NULL $content
1585 * @param array $configuration
1586 * @param string $expected
1587 * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
1590 public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
1591 $result = $this->subject
->stdWrap_ifNull($content, $configuration);
1592 $this->assertEquals($expected, $result);
1596 * Data provider for stdWrap_ifNullDeterminesNullValues test
1600 public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
1602 'null value' => array(
1609 'zero value' => array(
1621 * @param array $configuration
1623 * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
1626 public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
1627 $result = $this->subject
->stdWrap_noTrimWrap($content, $configuration);
1628 $this->assertEquals($expected, $result);
1632 * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
1636 public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
1638 'No char given' => array(
1641 'noTrimWrap' => '| left | right |',
1643 ' left middle right '
1645 'Zero char given' => array(
1648 'noTrimWrap' => '0 left 0 right 0',
1649 'noTrimWrap.' => array('splitChar' => '0'),
1652 ' left middle right '
1654 'Default char given' => array(
1657 'noTrimWrap' => '| left | right |',
1658 'noTrimWrap.' => array('splitChar' => '|'),
1660 ' left middle right '
1662 'Split char is a' => array(
1665 'noTrimWrap' => 'a left a right a',
1666 'noTrimWrap.' => array('splitChar' => 'a'),
1668 ' left middle right '
1670 'Split char is multi-char (ab)' => array(
1673 'noTrimWrap' => 'ab left ab right ab',
1674 'noTrimWrap.' => array('splitChar' => 'ab'),
1676 ' left middle right '
1678 'Split char accepts stdWrap' => array(
1681 'noTrimWrap' => 'abc left abc right abc',
1682 'noTrimWrap.' => array(
1684 'splitChar.' => array('wrap' => 'a|c'),
1687 ' left middle right '
1693 * @param array $expectedTags
1694 * @param array $configuration
1696 * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
1698 public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
1699 $this->subject
->stdWrap_addPageCacheTags('', $configuration);
1700 $this->assertEquals($expectedTags, $this->typoScriptFrontendControllerMock
->_get('pageCacheTags'));
1706 public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
1710 array('addPageCacheTags' => ''),
1712 'Two expectedTags' => array(
1713 array('tag1', 'tag2'),
1714 array('addPageCacheTags' => 'tag1,tag2'),
1716 'Two expectedTags plus one with stdWrap' => array(
1717 array('tag1', 'tag2', 'tag3'),
1719 'addPageCacheTags' => 'tag1,tag2',
1720 'addPageCacheTags.' => array('wrap' => '|,tag3')
1727 * Data provider for stdWrap_encodeForJavaScriptValue test
1729 * @return array multi-dimensional array with the second level like this:
1730 * @see encodeForJavaScriptValue
1732 public function stdWrap_encodeForJavaScriptValueDataProvider() {
1734 'double quote in string' => array(
1737 '\'double\u0020quote\u0022\''
1739 'backslash in string' => array(
1742 '\'backslash\u0020\u005C\''
1744 'exclamation mark' => array(
1747 '\'exclamation\u0021\''
1749 'whitespace tab, newline and carriage return' => array(
1750 "white\tspace\ns\r",
1752 '\'white\u0009space\u000As\u000D\''
1754 'single quote in string' => array(
1757 '\'single\u0020quote\u0020\u0027\''
1762 '\'\u003Ctag\u003E\''
1764 'ampersand in string' => array(
1767 '\'amper\u0026sand\''
1773 * Check if encodeForJavaScriptValue works properly
1775 * @dataProvider stdWrap_encodeForJavaScriptValueDataProvider
1778 public function stdWrap_encodeForJavaScriptValue($input, $conf, $expected) {
1779 $result = $this->subject
->stdWrap_encodeForJavaScriptValue($input, $conf);
1780 $this->assertEquals($expected, $result);
1784 /////////////////////////////
1785 // Tests concerning getData()
1786 /////////////////////////////
1791 public function getDataWithTypeGpDataProvider() {
1793 'Value in get-data' => array('onlyInGet', 'GetValue'),
1794 'Value in post-data' => array('onlyInPost', 'PostValue'),
1795 'Value in post-data overriding get-data' => array('inGetAndPost', 'ValueInPost'),
1800 * Checks if getData() works with type "gp"
1803 * @dataProvider getDataWithTypeGpDataProvider
1805 public function getDataWithTypeGp($key, $expectedValue) {
1807 'onlyInGet' => 'GetValue',
1808 'inGetAndPost' => 'ValueInGet',
1811 'onlyInPost' => 'PostValue',
1812 'inGetAndPost' => 'ValueInPost',
1814 $this->assertEquals($expectedValue, $this->subject
->getData('gp:' . $key));
1818 * Checks if getData() works with type "tsfe"
1822 public function getDataWithTypeTsfe() {
1823 $this->assertEquals($GLOBALS['TSFE']->renderCharset
, $this->subject
->getData('tsfe:renderCharset'));
1827 * Checks if getData() works with type "getenv"
1831 public function getDataWithTypeGetenv() {
1832 $envName = $this->getUniqueId('frontendtest');
1833 $value = $this->getUniqueId('someValue');
1834 putenv($envName . '=' . $value);
1835 $this->assertEquals($value, $this->subject
->getData('getenv:' . $envName));
1839 * Checks if getData() works with type "getindpenv"
1843 public function getDataWithTypeGetindpenv() {
1844 $this->subject
->expects($this->once())->method('getEnvironmentVariable')
1845 ->with($this->equalTo('SCRIPT_FILENAME'))->will($this->returnValue('dummyPath'));
1846 $this->assertEquals('dummyPath', $this->subject
->getData('getindpenv:SCRIPT_FILENAME'));
1850 * Checks if getData() works with type "field"
1854 public function getDataWithTypeField() {
1856 $value = 'someValue';
1857 $field = array($key => $value);
1859 $this->assertEquals($value, $this->subject
->getData('field:' . $key, $field));
1863 * Checks if getData() works with type "field" of the field content
1864 * is multi-dimensional (e.g. an array)
1868 public function getDataWithTypeFieldAndFieldIsMultiDimensional() {
1869 $key = 'somekey|level1|level2';
1870 $value = 'somevalue';
1871 $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
1873 $this->assertEquals($value, $this->subject
->getData('field:' . $key, $field));
1877 * Basic check if getData gets the uid of a file object
1881 public function getDataWithTypeFileReturnsUidOfFileObject() {
1882 $uid = $this->getUniqueId();
1883 $file = $this->getMock(\TYPO3\CMS\Core\
Resource\File
::class, array(), array(), '', FALSE);
1884 $file->expects($this->once())->method('getUid')->will($this->returnValue($uid));
1885 $this->subject
->setCurrentFile($file);
1886 $this->assertEquals($uid, $this->subject
->getData('file:current:uid'));
1890 * Checks if getData() works with type "parameters"
1894 public function getDataWithTypeParameters() {
1895 $key = $this->getUniqueId('someKey');
1896 $value = $this->getUniqueId('someValue');
1897 $this->subject
->parameters
[$key] = $value;
1899 $this->assertEquals($value, $this->subject
->getData('parameters:' . $key));
1903 * Checks if getData() works with type "register"
1907 public function getDataWithTypeRegister() {
1908 $key = $this->getUniqueId('someKey');
1909 $value = $this->getUniqueId('someValue');
1910 $GLOBALS['TSFE']->register
[$key] = $value;
1912 $this->assertEquals($value, $this->subject
->getData('register:' . $key));
1916 * Checks if getData() works with type "level"
1920 public function getDataWithTypeLevel() {
1922 0 => array('uid' => 1, 'title' => 'title1'),
1923 1 => array('uid' => 2, 'title' => 'title2'),
1924 2 => array('uid' => 3, 'title' => 'title3'),
1927 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
1928 $this->assertEquals(2, $this->subject
->getData('level'));
1932 * Checks if getData() works with type "global"
1936 public function getDataWithTypeGlobal() {
1937 $this->assertEquals($GLOBALS['TSFE']->renderCharset
, $this->subject
->getData('global:TSFE|renderCharset'));
1941 * Checks if getData() works with type "leveltitle"
1945 public function getDataWithTypeLeveltitle() {
1947 0 => array('uid' => 1, 'title' => 'title1'),
1948 1 => array('uid' => 2, 'title' => 'title2'),
1949 2 => array('uid' => 3, 'title' => ''),
1952 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
1953 $this->assertEquals('', $this->subject
->getData('leveltitle:-1'));
1954 // since "title3" is not set, it will slide to "title2"
1955 $this->assertEquals('title2', $this->subject
->getData('leveltitle:-1,slide'));
1959 * Checks if getData() works with type "levelmedia"
1963 public function getDataWithTypeLevelmedia() {
1965 0 => array('uid' => 1, 'title' => 'title1', 'media' => 'media1'),
1966 1 => array('uid' => 2, 'title' => 'title2', 'media' => 'media2'),
1967 2 => array('uid' => 3, 'title' => 'title3', 'media' => ''),
1970 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
1971 $this->assertEquals('', $this->subject
->getData('levelmedia:-1'));
1972 // since "title3" is not set, it will slide to "title2"
1973 $this->assertEquals('media2', $this->subject
->getData('levelmedia:-1,slide'));
1977 * Checks if getData() works with type "leveluid"
1981 public function getDataWithTypeLeveluid() {
1983 0 => array('uid' => 1, 'title' => 'title1'),
1984 1 => array('uid' => 2, 'title' => 'title2'),
1985 2 => array('uid' => 3, 'title' => 'title3'),
1988 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
1989 $this->assertEquals(3, $this->subject
->getData('leveluid:-1'));
1990 // every element will have a uid - so adding slide doesn't really make sense, just for completeness
1991 $this->assertEquals(3, $this->subject
->getData('leveluid:-1,slide'));
1995 * Checks if getData() works with type "levelfield"
1999 public function getDataWithTypeLevelfield() {
2001 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2002 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2003 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => ''),
2006 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2007 $this->assertEquals('', $this->subject
->getData('levelfield:-1,testfield'));
2008 $this->assertEquals('field2', $this->subject
->getData('levelfield:-1,testfield,slide'));
2012 * Checks if getData() works with type "fullrootline"
2016 public function getDataWithTypeFullrootline() {
2018 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2021 0 => array('uid' => 1, 'title' => 'title1', 'testfield' => 'field1'),
2022 1 => array('uid' => 2, 'title' => 'title2', 'testfield' => 'field2'),
2023 2 => array('uid' => 3, 'title' => 'title3', 'testfield' => 'field3'),
2026 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline1;
2027 $GLOBALS['TSFE']->rootLine
= $rootline2;
2028 $this->assertEquals('field2', $this->subject
->getData('fullrootline:-1,testfield'));
2032 * Checks if getData() works with type "date"
2036 public function getDataWithTypeDate() {
2038 $defaultFormat = 'd/m Y';
2040 $this->assertEquals(date($format, $GLOBALS['EXEC_TIME']), $this->subject
->getData('date:' . $format));
2041 $this->assertEquals(date($defaultFormat, $GLOBALS['EXEC_TIME']), $this->subject
->getData('date'));
2045 * Checks if getData() works with type "page"
2049 public function getDataWithTypePage() {
2051 $GLOBALS['TSFE']->page
['uid'] = $uid;
2052 $this->assertEquals($uid, $this->subject
->getData('page:uid'));
2056 * Checks if getData() works with type "current"
2060 public function getDataWithTypeCurrent() {
2061 $key = $this->getUniqueId('someKey');
2062 $value = $this->getUniqueId('someValue');
2063 $this->subject
->data
[$key] = $value;
2064 $this->subject
->currentValKey
= $key;
2065 $this->assertEquals($value, $this->subject
->getData('current'));
2069 * Checks if getData() works with type "db"
2073 public function getDataWithTypeDb() {
2074 $dummyRecord = array('uid' => 5, 'title' => 'someTitle');
2076 $GLOBALS['TSFE']->sys_page
->expects($this->atLeastOnce())->method('getRawRecord')->with('tt_content', '106')->will($this->returnValue($dummyRecord));
2077 $this->assertEquals($dummyRecord['title'], $this->subject
->getData('db:tt_content:106:title'));
2081 * Checks if getData() works with type "lll"
2085 public function getDataWithTypeLll() {
2086 $key = $this->getUniqueId('someKey');
2087 $value = $this->getUniqueId('someValue');
2088 $language = $this->getUniqueId('someLanguage');
2089 $GLOBALS['TSFE']->LL_labels_cache
[$language]['LLL:' . $key] = $value;
2090 $GLOBALS['TSFE']->lang
= $language;
2092 $this->assertEquals($value, $this->subject
->getData('lll:' . $key));
2096 * Checks if getData() works with type "path"
2100 public function getDataWithTypePath() {
2101 $filenameIn = $this->getUniqueId('someValue');
2102 $filenameOut = $this->getUniqueId('someValue');
2103 $this->templateServiceMock
->expects($this->atLeastOnce())->method('getFileName')->with($filenameIn)->will($this->returnValue($filenameOut));
2104 $this->assertEquals($filenameOut, $this->subject
->getData('path:' . $filenameIn));
2108 * Checks if getData() works with type "parentRecordNumber"
2112 public function getDataWithTypeParentRecordNumber() {
2113 $recordNumber = rand();
2114 $this->subject
->parentRecordNumber
= $recordNumber;
2115 $this->assertEquals($recordNumber, $this->subject
->getData('cobj:parentRecordNumber'));
2119 * Checks if getData() works with type "debug:rootLine"
2123 public function getDataWithTypeDebugRootline() {
2125 0 => array('uid' => 1, 'title' => 'title1'),
2126 1 => array('uid' => 2, 'title' => 'title2'),
2127 2 => array('uid' => 3, 'title' => ''),
2129 $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)';
2130 $GLOBALS['TSFE']->tmpl
->rootLine
= $rootline;
2132 $result = $this->subject
->getData('debug:rootLine');
2133 $cleanedResult = strip_tags($result);
2134 $cleanedResult = str_replace("\r", '', $cleanedResult);
2135 $cleanedResult = str_replace("\n", '', $cleanedResult);
2136 $cleanedResult = str_replace("\t", '', $cleanedResult);
2137 $cleanedResult = str_replace(' ', '', $cleanedResult);
2139 $this->assertEquals($expectedResult, $cleanedResult);
2143 * Checks if getData() works with type "debug:fullRootLine"
2147 public function getDataWithTypeDebugFullRootline() {
2149 0 => array('uid' => 1, 'title' => 'title1'),
2150 1 => array('uid' => 2, 'title' => 'title2'),
2151 2 => array('uid' => 3, 'title' => ''),
2153 $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)';
2154 $GLOBALS['TSFE']->rootLine
= $rootline;
2156 $result = $this->subject
->getData('debug:fullRootLine');
2157 $cleanedResult = strip_tags($result);
2158 $cleanedResult = str_replace("\r", '', $cleanedResult);
2159 $cleanedResult = str_replace("\n", '', $cleanedResult);
2160 $cleanedResult = str_replace("\t", '', $cleanedResult);
2161 $cleanedResult = str_replace(' ', '', $cleanedResult);
2163 $this->assertEquals($expectedResult, $cleanedResult);
2167 * Checks if getData() works with type "debug:data"
2171 public function getDataWithTypeDebugData() {
2172 $key = $this->getUniqueId('someKey');
2173 $value = $this->getUniqueId('someValue');
2174 $this->subject
->data
= array($key => $value);
2176 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2178 $result = $this->subject
->getData('debug:data');
2179 $cleanedResult = strip_tags($result);
2180 $cleanedResult = str_replace("\r", '', $cleanedResult);
2181 $cleanedResult = str_replace("\n", '', $cleanedResult);
2182 $cleanedResult = str_replace("\t", '', $cleanedResult);
2183 $cleanedResult = str_replace(' ', '', $cleanedResult);
2185 $this->assertEquals($expectedResult, $cleanedResult);
2189 * Checks if getData() works with type "debug:register"
2193 public function getDataWithTypeDebugRegister() {
2194 $key = $this->getUniqueId('someKey');
2195 $value = $this->getUniqueId('someValue');
2196 $GLOBALS['TSFE']->register
= array($key => $value);
2198 $expectedResult = 'array(1item)' . $key . '=>"' . $value . '"(' . strlen($value) . 'chars)';
2200 $result = $this->subject
->getData('debug:register');
2201 $cleanedResult = strip_tags($result);
2202 $cleanedResult = str_replace("\r", '', $cleanedResult);
2203 $cleanedResult = str_replace("\n", '', $cleanedResult);
2204 $cleanedResult = str_replace("\t", '', $cleanedResult);
2205 $cleanedResult = str_replace(' ', '', $cleanedResult);
2207 $this->assertEquals($expectedResult, $cleanedResult);
2211 * Checks if getData() works with type "data:page"
2215 public function getDataWithTypeDebugPage() {
2217 $GLOBALS['TSFE']->page
= array('uid' => $uid);
2219 $expectedResult = 'array(1item)uid=>' . $uid . '(integer)';
2221 $result = $this->subject
->getData('debug:page');
2222 $cleanedResult = strip_tags($result);
2223 $cleanedResult = str_replace("\r", '', $cleanedResult);
2224 $cleanedResult = str_replace("\n", '', $cleanedResult);
2225 $cleanedResult = str_replace("\t", '', $cleanedResult);
2226 $cleanedResult = str_replace(' ', '', $cleanedResult);
2228 $this->assertEquals($expectedResult, $cleanedResult);
2234 public function getTreeListReturnsChildPageUids() {
2235 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2236 $GLOBALS['TSFE']->sys_page
2237 ->expects($this->any())
2238 ->method('getRawRecord')
2240 $this->onConsecutiveCalls(
2242 array('uid' => 321),
2243 array('uid' => 719),
2248 $GLOBALS['TSFE']->sys_page
->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2249 $GLOBALS['TYPO3_DB']
2250 ->expects($this->any())
2251 ->method('exec_SELECTgetRows')
2253 $this->onConsecutiveCalls(
2265 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2266 // 17 is positive, we expect 17 NOT to be included in result
2267 $result = $this->subject
->getTreeList(17, 5, 0, TRUE);
2268 $expectedResult = '42,719,321';
2269 $this->assertEquals($expectedResult, $result);
2275 public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue() {
2276 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(NULL));
2277 $GLOBALS['TSFE']->sys_page
2278 ->expects($this->any())
2279 ->method('getRawRecord')
2281 $this->onConsecutiveCalls(
2283 array('uid' => 321),
2284 array('uid' => 719),
2289 $GLOBALS['TSFE']->sys_page
->expects($this->any())->method('getMountPointInfo')->will($this->returnValue(NULL));
2290 $GLOBALS['TYPO3_DB']
2291 ->expects($this->any())
2292 ->method('exec_SELECTgetRows')
2294 $this->onConsecutiveCalls(
2306 // 17 = pageId, 5 = recursionLevel, 0 = begin (entry to recursion, internal), TRUE = do not check enable fields
2307 // 17 is negative, we expect 17 to be included in result
2308 $result = $this->subject
->getTreeList(-17, 5, 0, TRUE);
2309 $expectedResult = '42,719,321,17';
2310 $this->assertEquals($expectedResult, $result);
2316 public function aTagParamsHasLeadingSpaceIfNotEmpty() {
2317 $aTagParams = $this->subject
->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2318 $this->assertEquals(' data-test="testdata"', $aTagParams );
2324 public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams() {
2325 $GLOBALS['TSFE']->ATagParams
= 'data-global="dataglobal"';
2326 $aTagParams = $this->subject
->getATagParams(array('ATagParams' => 'data-test="testdata"'));
2327 $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
2333 public function aTagParamsHasNoLeadingSpaceIfEmpty() {
2334 // make sure global ATagParams are empty
2335 $GLOBALS['TSFE']->ATagParams
= '';
2336 $aTagParams = $this->subject
->getATagParams(array('ATagParams' => ''));
2337 $this->assertEquals('', $aTagParams);
2343 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider() {
2348 array('fooo', array('foo' => 'bar'))
2353 * Make sure that the rendering falls back to the classic <img style if nothing else is found
2356 * @dataProvider getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFoundDataProvider
2357 * @param string $key
2358 * @param array $configuration
2360 public function getImageTagTemplateFallsBackToDefaultTemplateIfNoTemplateIsFound($key, $configuration) {
2361 $defaultImgTagTemplate = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
2362 $result = $this->subject
->getImageTagTemplate($key, $configuration);
2363 $this->assertEquals($result, $defaultImgTagTemplate);
2369 public function getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider() {
2376 'element' => '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2380 '<img src="###SRC###" srcset="###SOURCES###" ###PARAMS### ###ALTPARAMS### ###FOOBAR######SELFCLOSINGTAGSLASH###>'
2387 * Assure if a layoutKey and layout is given the selected layout is returned
2390 * @dataProvider getImageTagTemplateReturnTemplateElementIdentifiedByKeyDataProvider
2391 * @param string $key
2392 * @param array $configuration
2393 * @param string $expectation
2395 public function getImageTagTemplateReturnTemplateElementIdentifiedByKey($key, $configuration, $expectation) {
2396 $result = $this->subject
->getImageTagTemplate($key, $configuration);
2397 $this->assertEquals($result, $expectation);
2403 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider() {
2405 array(NULL, NULL, NULL),
2406 array('foo', NULL, NULL),
2407 array('foo', array('sourceCollection.' => 1), 'bar')
2412 * Make sure the source collection is empty if no valid configuration or source collection is defined
2415 * @dataProvider getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefinedDataProvider
2416 * @param string $layoutKey
2417 * @param array $configuration
2418 * @param string $file
2420 public function getImageSourceCollectionReturnsEmptyStringIfNoSourcesAreDefined($layoutKey, $configuration, $file) {
2421 $result = $this->subject
->getImageSourceCollection($layoutKey, $configuration, $file);
2422 $this->assertSame($result, '');
2426 * Make sure the generation of subimages calls the generation of the subimages and uses the layout -> source template
2430 public function getImageSourceCollectionRendersDefinedSources() {
2431 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2432 $cObj = $this->getMock(
2433 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
2434 array('stdWrap','getImgResource')
2436 $cObj->start(array(), 'tt_content');
2438 $layoutKey = 'test';
2440 $configuration = array(
2441 'layoutKey' => 'test',
2442 'layout.' => array (
2444 'element' => '<img ###SRC### ###SRCCOLLECTION### ###SELFCLOSINGTAGSLASH###>',
2445 'source' => '---###SRC###---'
2448 'sourceCollection.' => array(
2455 $file = 'testImageName';
2457 // Avoid calling of stdWrap
2459 ->expects($this->any())
2461 ->will($this->returnArgument(0));
2463 // Avoid calling of imgResource
2465 ->expects($this->exactly(1))
2466 ->method('getImgResource')
2467 ->with($this->equalTo('testImageName'))
2468 ->will($this->returnValue(array(100, 100, NULL, 'bar')));
2470 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2472 $this->assertEquals('---bar---', $result);
2476 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyDefault test
2478 * @return array multi-dimensional array with the second level like this:
2479 * @see getImageSourceCollectionRendersDefinedLayoutKeyDefault
2481 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider() {
2483 * @see css_styled_content/static/setup.txt
2485 $sourceCollectionArray = array(
2488 'srcsetCandidate' => '600w',
2489 'mediaQuery' => '(max-device-width: 600px)',
2490 'dataKey' => 'small',
2492 'smallRetina.' => array(
2493 'if.directReturn' => 0,
2495 'pixelDensity' => '2',
2496 'srcsetCandidate' => '600w 2x',
2497 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2498 'dataKey' => 'smallRetina',
2505 'layoutKey' => 'default',
2506 'layout.' => array (
2507 'default.' => array(
2508 'element' => '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>',
2512 'sourceCollection.' => $sourceCollectionArray
2519 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2522 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDefaultProvider
2523 * @param string $layoutKey
2524 * @param array $configuration
2526 public function getImageSourceCollectionRendersDefinedLayoutKeyDefault($layoutKey , $configuration) {
2527 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2528 $cObj = $this->getMock(
2529 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
2530 array('stdWrap','getImgResource')
2532 $cObj->start(array(), 'tt_content');
2534 $file = 'testImageName';
2536 // Avoid calling of stdWrap
2538 ->expects($this->any())
2540 ->will($this->returnArgument(0));
2542 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2544 $this->assertEmpty($result);
2548 * Data provider for the getImageSourceCollectionRendersDefinedLayoutKeyData test
2550 * @return array multi-dimensional array with the second level like this:
2551 * @see getImageSourceCollectionRendersDefinedLayoutKeyData
2553 public function getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider() {
2555 * @see css_styled_content/static/setup.txt
2557 $sourceCollectionArray = array(
2560 'srcsetCandidate' => '600w',
2561 'mediaQuery' => '(max-device-width: 600px)',
2562 'dataKey' => 'small',
2564 'smallRetina.' => array(
2565 'if.directReturn' => 1,
2567 'pixelDensity' => '2',
2568 'srcsetCandidate' => '600w 2x',
2569 'mediaQuery' => '(max-device-width: 600px) AND (min-resolution: 192dpi)',
2570 'dataKey' => 'smallRetina',
2577 'layoutKey' => 'srcset',
2578 'layout.' => array (
2580 'element' => '<img src="###SRC###" srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2581 'source' => '|*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###'
2584 'sourceCollection.' => $sourceCollectionArray
2587 'bar-file.jpg 600w,bar-file.jpg 600w 2x',
2592 'layoutKey' => 'picture',
2593 'layout.' => array (
2594 'picture.' => array(
2595 'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2596 'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2599 'sourceCollection.' => $sourceCollectionArray,
2602 '<source src="bar-file.jpg" media="(max-device-width: 600px)" /><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)" />',
2607 'layoutKey' => 'picture',
2608 'layout.' => array (
2609 'picture.' => array(
2610 'element' => '<picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###></picture>',
2611 'source' => '<source src="###SRC###" media="###MEDIAQUERY###"###SELFCLOSINGTAGSLASH###>'
2614 'sourceCollection.' => $sourceCollectionArray,
2617 '<source src="bar-file.jpg" media="(max-device-width: 600px)"><source src="bar-file.jpg" media="(max-device-width: 600px) AND (min-resolution: 192dpi)">',
2622 'layoutKey' => 'data',
2623 'layout.' => array (
2625 'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2626 'source' => 'data-###DATAKEY###="###SRC###"'
2629 'sourceCollection.' => $sourceCollectionArray
2632 'data-small="bar-file.jpg"data-smallRetina="bar-file.jpg"',
2638 * Make sure the generation of subimages renders the expected HTML Code for the sourceset
2641 * @dataProvider getImageSourceCollectionRendersDefinedLayoutKeyDataDataProvider
2642 * @param string $layoutKey
2643 * @param array $configuration
2644 * @param string $xhtmlDoctype
2645 * @param string $expectedHtml
2647 public function getImageSourceCollectionRendersDefinedLayoutKeyData($layoutKey , $configuration, $xhtmlDoctype, $expectedHtml) {
2648 /** @var $cObj \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
2649 $cObj = $this->getMock(
2650 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
2651 array('stdWrap','getImgResource')
2653 $cObj->start(array(), 'tt_content');
2655 $file = 'testImageName';
2657 $GLOBALS['TSFE']->xhtmlDoctype
= $xhtmlDoctype;
2659 // Avoid calling of stdWrap
2661 ->expects($this->any())
2663 ->will($this->returnArgument(0));
2665 // Avoid calling of imgResource
2667 ->expects($this->exactly(2))
2668 ->method('getImgResource')
2669 ->with($this->equalTo('testImageName'))
2670 ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2672 $result = $cObj->getImageSourceCollection($layoutKey, $configuration, $file);
2674 $this->assertEquals($expectedHtml, $result);
2678 * Make sure the hook in get sourceCollection is called
2682 public function getImageSourceCollectionHookCalled() {
2683 $this->subject
= $this->getAccessibleMock(
2684 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
2685 array('getResourceFactory', 'stdWrap', 'getImgResource')
2687 $this->subject
->start(array(), 'tt_content');
2689 // Avoid calling stdwrap and getImgResource
2690 $this->subject
->expects($this->any())
2692 ->will($this->returnArgument(0));
2694 $this->subject
->expects($this->any())
2695 ->method('getImgResource')
2696 ->will($this->returnValue(array(100, 100, NULL, 'bar-file.jpg')));
2698 $resourceFactory = $this->getMock(\TYPO3\CMS\Core\
Resource\ResourceFactory
::class, array(), array(), '', FALSE);
2699 $this->subject
->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
2701 $className = $this->getUniqueId('tx_coretest_getImageSourceCollectionHookCalled');
2702 $getImageSourceCollectionHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectOneSourceCollectionHookInterface
::class, array('getOneSourceCollection'), array(), $className);
2703 $GLOBALS['T3_VAR']['getUserObj'][$className] = $getImageSourceCollectionHookMock;
2704 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'][] = $className;
2706 $getImageSourceCollectionHookMock
2707 ->expects($this->exactly(1))
2708 ->method('getOneSourceCollection')
2709 ->will($this->returnCallback(array($this, 'isGetOneSourceCollectionCalledCallback')));
2711 $configuration = array(
2712 'layoutKey' => 'data',
2713 'layout.' => array (
2715 'element' => '<img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS######SELFCLOSINGTAGSLASH###>',
2716 'source' => 'data-###DATAKEY###="###SRC###"'
2719 'sourceCollection.' => array(
2722 'srcsetCandidate' => '600w',
2723 'mediaQuery' => '(max-device-width: 600px)',
2724 'dataKey' => 'small',
2729 $result = $this->subject
->getImageSourceCollection('data', $configuration, $this->getUniqueId('testImage-'));
2731 $this->assertSame($result, 'isGetOneSourceCollectionCalledCallback');
2735 * Handles the arguments that have been sent to the getImgResource hook.
2738 * @see getImageSourceCollectionHookCalled
2740 public function isGetOneSourceCollectionCalledCallback() {
2741 list($sourceRenderConfiguration, $sourceConfiguration, $oneSourceCollection, $parent) = func_get_args();
2742 $this->assertTrue(is_array($sourceRenderConfiguration));
2743 $this->assertTrue(is_array($sourceConfiguration));
2744 return 'isGetOneSourceCollectionCalledCallback';
2748 * @param string $expected The expected URL
2749 * @param string $url The URL to parse and manipulate
2750 * @param array $configuration The configuration array
2752 * @dataProvider forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider
2754 public function forceAbsoluteUrlReturnsCorrectAbsoluteUrl($expected, $url, array $configuration) {
2756 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->will($this->returnValueMap(
2758 array('HTTP_HOST', 'localhost'),
2759 array('TYPO3_SITE_PATH', '/'),
2762 $GLOBALS['TSFE']->absRefPrefix
= '';
2764 $this->assertEquals($expected, $this->subject
->_call('forceAbsoluteUrl', $url, $configuration));
2768 * @return array The test data for forceAbsoluteUrlReturnsAbsoluteUrl
2770 public function forceAbsoluteUrlReturnsCorrectAbsoluteUrlDataProvider() {
2772 'Missing forceAbsoluteUrl leaves URL untouched' => array(
2777 'Absolute URL stays unchanged' => array(
2778 'http://example.org/',
2779 'http://example.org/',
2781 'forceAbsoluteUrl' => '1'
2784 'Absolute URL stays unchanged 2' => array(
2785 'http://example.org/resource.html',
2786 'http://example.org/resource.html',
2788 'forceAbsoluteUrl' => '1'
2791 'Scheme and host w/o ending slash stays unchanged' => array(
2792 'http://example.org',
2793 'http://example.org',
2795 'forceAbsoluteUrl' => '1'
2798 'Scheme can be forced' => array(
2799 'typo3://example.org',
2800 'http://example.org',
2802 'forceAbsoluteUrl' => '1',
2803 'forceAbsoluteUrl.' => array(
2808 'Relative path old-style' => array(
2809 'http://localhost/fileadmin/dummy.txt',
2810 '/fileadmin/dummy.txt',
2812 'forceAbsoluteUrl' => '1',
2815 'Relative path' => array(
2816 'http://localhost/fileadmin/dummy.txt',
2817 'fileadmin/dummy.txt',