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\DebugUtility
;
23 use TYPO3\CMS\Core\Utility\GeneralUtility
;
24 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
;
25 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
;
26 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
27 use TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Fixtures\PageRepositoryFixture
;
28 use TYPO3\CMS\Core\Cache\CacheManager
;
29 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
as CacheFrontendInterface
;
32 * Testcase for TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
34 class ContentObjectRendererTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
39 protected $currentLocale;
42 * @var array A backup of registered singleton instances
44 protected $singletonInstances = array();
47 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
49 protected $subject = null;
52 * @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
54 protected $typoScriptFrontendControllerMock = null;
57 * @var \PHPUnit_Framework_MockObject_MockObject|TemplateService
59 protected $templateServiceMock = null;
62 * Default content object name -> class name map, shipped with TYPO3 CMS
66 protected $contentObjectMap = array(
67 'TEXT' => \TYPO3\CMS\Frontend\ContentObject\TextContentObject
::class,
68 'CASE' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject
::class,
69 'COBJ_ARRAY' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
::class,
70 'COA' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
::class,
71 'COA_INT' => \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayInternalContentObject
::class,
72 'USER' => \TYPO3\CMS\Frontend\ContentObject\UserContentObject
::class,
73 'USER_INT' => \TYPO3\CMS\Frontend\ContentObject\UserInternalContentObject
::class,
74 'FILE' => \TYPO3\CMS\Frontend\ContentObject\FileContentObject
::class,
75 'FILES' => \TYPO3\CMS\Frontend\ContentObject\FilesContentObject
::class,
76 'IMAGE' => \TYPO3\CMS\Frontend\ContentObject\ImageContentObject
::class,
77 'IMG_RESOURCE' => \TYPO3\CMS\Frontend\ContentObject\ImageResourceContentObject
::class,
78 'CONTENT' => \TYPO3\CMS\Frontend\ContentObject\ContentContentObject
::class,
79 'RECORDS' => \TYPO3\CMS\Frontend\ContentObject\RecordsContentObject
::class,
80 'HMENU' => \TYPO3\CMS\Frontend\ContentObject\HierarchicalMenuContentObject
::class,
81 'CASEFUNC' => \TYPO3\CMS\Frontend\ContentObject\CaseContentObject
::class,
82 'LOAD_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\LoadRegisterContentObject
::class,
83 'RESTORE_REGISTER' => \TYPO3\CMS\Frontend\ContentObject\RestoreRegisterContentObject
::class,
84 'TEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\TemplateContentObject
::class,
85 'FLUIDTEMPLATE' => \TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject
::class,
86 'SVG' => \TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject
::class,
87 'EDITPANEL' => \TYPO3\CMS\Frontend\ContentObject\EditPanelContentObject
::class
93 protected function setUp()
95 $this->currentLocale
= setlocale(LC_NUMERIC
, 0);
97 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
98 $this->createMockedLoggerAndLogManager();
100 $this->templateServiceMock
= $this->getMockBuilder(TemplateService
::class)
101 ->setMethods(array('getFileName', 'linkData'))
103 $pageRepositoryMock = $this->getMockBuilder(PageRepositoryFixture
::class)
104 ->setMethods(array('getRawRecord', 'getMountPointInfo'))
107 $this->typoScriptFrontendControllerMock
= $this->getAccessibleMock(TypoScriptFrontendController
::class, array('dummy'), array(), '', false);
108 $this->typoScriptFrontendControllerMock
->tmpl
= $this->templateServiceMock
;
109 $this->typoScriptFrontendControllerMock
->config
= array();
110 $this->typoScriptFrontendControllerMock
->page
= array();
111 $this->typoScriptFrontendControllerMock
->sys_page
= $pageRepositoryMock;
112 $GLOBALS['TSFE'] = $this->typoScriptFrontendControllerMock
;
113 $GLOBALS['TYPO3_DB'] = $this->getMockBuilder(\TYPO3\CMS\Core\Database\DatabaseConnection
::class)->getMock();
115 $this->subject
= $this->getAccessibleMock(
116 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class,
117 array('getResourceFactory', 'getEnvironmentVariable'),
118 array($this->typoScriptFrontendControllerMock
)
120 $this->subject
->setContentObjectClassMap($this->contentObjectMap
);
121 $this->subject
->start(array(), 'tt_content');
124 protected function tearDown()
126 setlocale(LC_NUMERIC
, $this->currentLocale
);
127 GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
131 //////////////////////
133 //////////////////////
136 * Avoid logging to the file system (file writer is currently the only configured writer)
138 protected function createMockedLoggerAndLogManager()
140 $logManagerMock = $this->getMockBuilder(LogManager
::class)->getMock();
141 $loggerMock = $this->getMockBuilder(LoggerInterface
::class)->getMock();
142 $logManagerMock->expects($this->any())
143 ->method('getLogger')
144 ->willReturn($loggerMock);
145 GeneralUtility
::setSingletonInstance(LogManager
::class, $logManagerMock);
149 * Converts the subject and the expected result into utf-8.
151 * @param string $subject the subject, will be modified
152 * @param string $expected the expected result, will be modified
154 protected function handleCharset(&$subject, &$expected)
156 $charsetConverter = new CharsetConverter();
157 $subject = $charsetConverter->conv($subject, 'iso-8859-1', 'utf-8');
158 $expected = $charsetConverter->conv($expected, 'iso-8859-1', 'utf-8');
161 /////////////////////////////////////////////
162 // Tests concerning the getImgResource hook
163 /////////////////////////////////////////////
167 public function getImgResourceCallsGetImgResourcePostProcessHook()
169 $this->templateServiceMock
170 ->expects($this->atLeastOnce())
171 ->method('getFileName')
172 ->with('typo3/clear.gif')
173 ->will($this->returnValue('typo3/clear.gif'));
175 $resourceFactory = $this->createMock(\TYPO3\CMS\Core\
Resource\ResourceFactory
::class);
176 $this->subject
->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
178 $className = $this->getUniqueId('tx_coretest');
179 $getImgResourceHookMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectGetImageResourceHookInterface
::class)
180 ->setMethods(array('getImgResourcePostProcess'))
181 ->setMockClassName($className)
183 $getImgResourceHookMock
184 ->expects($this->once())
185 ->method('getImgResourcePostProcess')
186 ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
187 $getImgResourceHookObjects = array($getImgResourceHookMock);
188 $this->subject
->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
189 $this->subject
->getImgResource('typo3/clear.gif', array());
193 * Handles the arguments that have been sent to the getImgResource hook.
195 * @param string $file
196 * @param array $fileArray
197 * @param $imageResource
198 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $parent
200 * @see getImgResourceHookGetsCalled
202 public function isGetImgResourceHookCalledCallback($file, $fileArray, $imageResource, $parent)
204 $this->assertEquals('typo3/clear.gif', $file);
205 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
206 $this->assertTrue(is_array($fileArray));
207 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
);
208 return $imageResource;
211 //////////////////////////////////////
212 // Tests concerning getContentObject
213 //////////////////////////////////////
215 public function getContentObjectValidContentObjectsDataProvider()
217 $dataProvider = array();
218 foreach ($this->contentObjectMap
as $name => $className) {
219 $dataProvider[] = array($name, $className);
221 return $dataProvider;
226 * @dataProvider getContentObjectValidContentObjectsDataProvider
227 * @param string $name TypoScript name of content object
228 * @param string $fullClassName Expected class name
230 public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $fullClassName)
232 $contentObjectInstance = $this->createMock($fullClassName);
233 \TYPO3\CMS\Core\Utility\GeneralUtility
::addInstance($fullClassName, $contentObjectInstance);
234 $this->assertSame($contentObjectInstance, $this->subject
->getContentObject($name));
237 /////////////////////////////////////////
238 // Tests concerning getQueryArguments()
239 /////////////////////////////////////////
243 public function getQueryArgumentsExcludesParameters()
245 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
246 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
248 $getQueryArgumentsConfiguration = array();
249 $getQueryArgumentsConfiguration['exclude'] = array();
250 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
251 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
252 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
253 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
254 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
255 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
256 $this->assertEquals($expectedResult, $actualResult);
262 public function getQueryArgumentsExcludesGetParameters()
268 'key31' => 'value31',
270 'key321' => 'value321',
271 'key322' => 'value322'
275 $getQueryArgumentsConfiguration = array();
276 $getQueryArgumentsConfiguration['method'] = 'GET';
277 $getQueryArgumentsConfiguration['exclude'] = array();
278 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
279 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
280 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
281 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
282 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
283 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
284 $this->assertEquals($expectedResult, $actualResult);
290 public function getQueryArgumentsOverrulesSingleParameter()
292 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
293 $this->returnValue('key1=value1')
295 $getQueryArgumentsConfiguration = array();
296 $overruleArguments = array(
297 // Should be overridden
298 'key1' => 'value1Overruled',
299 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
300 'key2' => 'value2Overruled'
302 $expectedResult = '&key1=value1Overruled';
303 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
304 $this->assertEquals($expectedResult, $actualResult);
310 public function getQueryArgumentsOverrulesMultiDimensionalParameters()
316 'key31' => 'value31',
318 'key321' => 'value321',
319 'key322' => 'value322'
323 $getQueryArgumentsConfiguration = array();
324 $getQueryArgumentsConfiguration['method'] = 'POST';
325 $getQueryArgumentsConfiguration['exclude'] = array();
326 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
327 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
328 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
329 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
330 $overruleArguments = array(
331 // Should be overriden
332 'key2' => 'value2Overruled',
335 // Shouldn't be set: Parameter is excluded and not forced
336 'key321' => 'value321Overruled',
337 // Should be overriden: Parameter is not excluded
338 'key322' => 'value322Overruled',
339 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
340 'key323' => 'value323Overruled'
344 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
345 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
346 $this->assertEquals($expectedResult, $actualResult);
352 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters()
354 $this->subject
->expects($this->any())->method('getEnvironmentVariable')->with($this->equalTo('QUERY_STRING'))->will(
355 $this->returnValue('key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322')
361 'key31' => 'value31',
363 'key321' => 'value321',
364 'key322' => 'value322'
368 $getQueryArgumentsConfiguration = array();
369 $getQueryArgumentsConfiguration['exclude'] = array();
370 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
371 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
372 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
373 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
374 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
375 $overruleArguments = array(
376 // Should be overriden
377 'key2' => 'value2Overruled',
380 // Should be set: Parameter is excluded but forced
381 'key321' => 'value321Overruled',
382 // Should be set: Parameter doesn't exist in source array but is forced
383 'key323' => 'value323Overruled'
387 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
388 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, true);
389 $this->assertEquals($expectedResult, $actualResult);
390 $getQueryArgumentsConfiguration['method'] = 'POST';
391 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, true);
392 $this->assertEquals($expectedResult, $actualResult);
398 public function getQueryArgumentsWithMethodPostGetMergesParameters()
407 'key331' => 'POST331',
408 'key332' => 'POST332',
417 'key331' => 'GET331',
421 $getQueryArgumentsConfiguration = array();
422 $getQueryArgumentsConfiguration['method'] = 'POST,GET';
423 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=POST1&key2=GET2&key3[key31]=POST31&key3[key32]=GET32&key3[key33][key331]=GET331&key3[key33][key332]=POST332');
424 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
425 $this->assertEquals($expectedResult, $actualResult);
431 public function getQueryArgumentsWithMethodGetPostMergesParameters()
440 'key331' => 'GET331',
441 'key332' => 'GET332',
450 'key331' => 'POST331',
454 $getQueryArgumentsConfiguration = array();
455 $getQueryArgumentsConfiguration['method'] = 'GET,POST';
456 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key1=GET1&key2=POST2&key3[key31]=GET31&key3[key32]=POST32&key3[key33][key331]=POST331&key3[key33][key332]=GET332');
457 $actualResult = $this->subject
->getQueryArguments($getQueryArgumentsConfiguration);
458 $this->assertEquals($expectedResult, $actualResult);
462 * Encodes square brackets in URL.
464 * @param string $string
467 private function rawUrlEncodeSquareBracketsInUrl($string)
469 return str_replace(array('[', ']'), array('%5B', '%5D'), $string);
472 //////////////////////////
473 // Tests concerning crop
474 //////////////////////////
478 public function cropIsMultibyteSafe()
480 $this->assertEquals('бла', $this->subject
->crop('бла', '3|...'));
483 //////////////////////////////
484 // Tests concerning cropHTML
485 //////////////////////////////
487 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
488 * of charset, text type, and configuration options to be tested.
490 * @return array two-dimensional array with the second level like this:
491 * @see cropHtmlWithDataProvider
493 public function cropHtmlDataProvider()
495 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.';
496 $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.';
497 $textWithEntities = 'Kasper Skårhøj implemented the; original ' . 'version of the crop function.';
499 'plain text; 11|...' => array(
502 'Kasper Sk' . chr(229) . 'r...'
504 'plain text; -58|...' => array(
507 '...h' . chr(248) . 'j implemented the original version of the crop function.'
509 'plain text; 4|...|1' => array(
514 'plain text; 20|...|1' => array(
517 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...'
519 'plain text; -5|...|1' => array(
524 'plain text; -49|...|1' => array(
527 '...the original version of the crop function.'
529 'text with markup; 11|...' => array(
532 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>'
534 'text with markup; 13|...' => array(
537 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>'
539 'text with markup; 14|...' => array(
542 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>'
544 'text with markup; 15|...' => array(
547 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>'
549 'text with markup; 29|...' => array(
552 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...'
554 'text with markup; -58|...' => array(
557 '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.'
559 'text with markup 4|...|1' => array(
562 '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>'
564 'text with markup; 11|...|1' => array(
567 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>'
569 'text with markup; 13|...|1' => array(
572 '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>'
574 'text with markup; 14|...|1' => array(
577 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>'
579 'text with markup; 15|...|1' => array(
582 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>'
584 'text with markup; 29|...|1' => array(
587 '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...'
589 'text with markup; -66|...|1' => array(
592 '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.'
594 'text with entities 9|...' => array(
599 'text with entities 10|...' => array(
602 'Kasper Skå...'
604 'text with entities 11|...' => array(
607 'Kasper Skår...'
609 'text with entities 13|...' => array(
612 'Kasper Skårhø...'
614 'text with entities 14|...' => array(
617 'Kasper Skårhøj...'
619 'text with entities 15|...' => array(
622 'Kasper Skårhøj ...'
624 'text with entities 16|...' => array(
627 'Kasper Skårhøj i...'
629 'text with entities -57|...' => array(
632 '...j implemented the; original version of the crop function.'
634 'text with entities -58|...' => array(
637 '...øj implemented the; original version of the crop function.'
639 'text with entities -59|...' => array(
642 '...høj implemented the; original version of the crop function.'
644 'text with entities 4|...|1' => array(
649 'text with entities 9|...|1' => array(
654 'text with entities 10|...|1' => array(
659 'text with entities 11|...|1' => array(
664 'text with entities 13|...|1' => array(
669 'text with entities 14|...|1' => array(
672 'Kasper Skårhøj...'
674 'text with entities 15|...|1' => array(
677 'Kasper Skårhøj...'
679 'text with entities 16|...|1' => array(
682 'Kasper Skårhøj...'
684 'text with entities -57|...|1' => array(
687 '...implemented the; original version of the crop function.'
689 'text with entities -58|...|1' => array(
692 '...implemented the; original version of the crop function.'
694 'text with entities -59|...|1' => array(
697 '...implemented the; original version of the crop function.'
699 'text with dash in html-element 28|...|1' => array(
701 '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',
702 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>'
704 'html elements with dashes in attributes' => array(
706 '<em data-foo="x">foobar</em>foobaz',
707 '<em data-foo="x">foobar</em>foo'
709 'html elements with iframe embedded 24|...|1' => array(
711 'Text with iframe <iframe src="//what.ever/"></iframe> and text after it',
712 'Text with iframe <iframe src="//what.ever/"></iframe> and...'
714 'html elements with script tag embedded 24|...|1' => array(
716 'Text with script <script>alert(\'foo\');</script> and text after it',
717 'Text with script <script>alert(\'foo\');</script> and...'
724 * Checks if stdWrap.cropHTML works with plain text cropping from left
727 * @dataProvider cropHtmlDataProvider
728 * @param string $settings
729 * @param string $subject the string to crop
730 * @param string $expected the expected cropped result
732 public function cropHtmlWithDataProvider($settings, $subject, $expected)
734 $this->handleCharset($subject, $expected);
735 $this->assertEquals($expected, $this->subject
->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '"');
739 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
740 * counts multiple invisible characters not as one (as the browser will output the content).
744 public function cropHtmlWorksWithComplexContent()
747 '<h1>Blog Example</h1>' . LF
.
749 '<div class="csc-header csc-header-n1">' . LF
.
750 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF
.
752 '<p class="bodytext">' . LF
.
753 ' A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.' . LF
.
755 '<div class="tx-blogexample-list-container">' . LF
.
756 ' <p class="bodytext">' . LF
.
757 ' Below are the most recent posts:' . LF
.
760 ' <li data-element="someId">' . LF
.
762 ' <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
.
764 ' <p class="bodytext">' . LF
.
765 ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...' . LF
.
767 ' <p class="metadata">' . LF
.
768 ' Published on 26.08.2009 by Jochen Rau' . LF
.
771 ' Tags: [MVC] [Domain Driven Design] <br>' . LF
.
772 ' <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
.
773 ' <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
.
778 ' <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
.
783 ' ? TYPO3 Association' . LF
.
786 $result = $this->subject
->cropHTML($input, '300');
789 '<h1>Blog Example</h1>' . LF
.
791 '<div class="csc-header csc-header-n1">' . LF
.
792 ' <h2 class="csc-firstHeader">Welcome to Blog #1</h2>' . LF
.
794 '<p class="bodytext">' . LF
.
795 ' A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.' . LF
.
797 '<div class="tx-blogexample-list-container">' . LF
.
798 ' <p class="bodytext">' . LF
.
799 ' Below are the most recent posts:' . LF
.
802 ' <li data-element="someId">' . LF
.
804 ' <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>';
806 $this->assertEquals($expected, $result);
808 $result = $this->subject
->cropHTML($input, '-100');
811 '<div class="tx-blogexample-list-container"><ul><li data-element="someId"><p> Design] <br>' . LF
.
812 ' <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
.
813 ' <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
.
818 ' <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
.
823 ' ? TYPO3 Association' . LF
.
826 $this->assertEquals($expected, $result);
830 * Checks if stdWrap.cropHTML handles linebreaks correctly (by ignoring them)
834 public function cropHtmlWorksWithLinebreaks()
836 $subject = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam";
837 $expected = "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor invidunt ut labore et dolore magna";
838 $result = $this->subject
->cropHTML($subject, '121');
839 $this->assertEquals($expected, $result);
843 * Data provider for stdWrap_cacheRead
845 * @return array Order: expect, input, conf, times, with, will
847 public function stdWrap_cacheReadDataProvider()
849 $cacheConf = [$this->getUniqueId('cache.')];
850 $conf = ['cache.' => $cacheConf];
853 'content', 'content', [],
856 'no cache. conf' => [
857 'content', 'content', ['otherConf' => 1],
860 'non-cached simulation' => [
861 'content', 'content', $conf,
862 1, $cacheConf, false,
864 'cached simulation' => [
865 'cachedContent', 'content', $conf,
866 1, $cacheConf, 'cachedContent',
872 * Check if stdWrap_cacheRead works properly.
874 * - the method branches correctly
875 * - getFromCache is called to fetch from cache
876 * - $conf['cache.'] is passed on as parameter
879 * @dataProvider stdWrap_cacheReadDataProvider
880 * @param string $expect Expected result.
881 * @param string $input Given input string.
882 * @param array $conf Property 'cache.'
883 * @param integer $times Times called mocked method.
884 * @param array $with Parameter passed to mocked method.
885 * @param string|false $will Return value of mocked method.
888 public function stdWrap_cacheRead(
889 $expect, $input, $conf, $times, $with, $will)
891 $subject = $this->getAccessibleMock(
892 ContentObjectRenderer
::class, ['getFromCache']);
894 ->expects($this->exactly($times))
895 ->method('getFromCache')
898 $this->assertSame($expect,
899 $subject->stdWrap_cacheRead($input, $conf));
903 * Check if stdWrap_setContentToCurrent works properly.
908 public function stdWrap_setContentToCurrent()
910 $content = $this->getUniqueId('content');
911 $this->assertNotSame($content, $this->subject
->getData('current'));
912 $this->assertSame($content,
913 $this->subject
->stdWrap_setContentToCurrent($content));
914 $this->assertSame($content, $this->subject
->getData('current'));
918 * Data provider for stdWrap_setCurrent
920 * @return array Order input, conf
922 public function stdWrap_setCurrentDataProvider()
931 ['setCurrent' => ''],
933 'non-empty string' => [
935 ['setCurrent' => 'xxx'],
941 'integer not null' => [
947 ['setCurrent' => true],
951 ['setCurrent' => false],
957 * Check if stdWrap_setCurrent works properly.
960 * @dataProvider stdWrap_setCurrentDataProvider
961 * @param string $input The input value.
962 * @param array $conf Property: setCurrent
965 public function stdWrap_setCurrent($input, $conf)
967 if (isset($conf['setCurrent'])) {
968 $this->assertNotSame($conf['setCurrent'], $this->subject
->getData('current'));
970 $this->assertSame($input, $this->subject
->stdWrap_setCurrent($input, $conf));
971 if (isset($conf['setCurrent'])) {
972 $this->assertSame($conf['setCurrent'], $this->subject
->getData('current'));
977 * Data provider for stdWrap_data.
979 * @return array [$expect, $data, $alt]
981 public function stdWrap_dataDataProvider()
983 $data = [$this->getUniqueId('data')];
984 $alt = [$this->getUniqueId('alternativeData')];
986 'default' => [$data, $data, ''],
987 'alt is array' => [$alt, $data, $alt],
988 'alt is empty array' => [[], $data, []],
989 'alt null' => [$data, $data, null],
990 'alt string' => [$data, $data, 'xxx'],
991 'alt int' => [$data, $data, 1],
992 'alt bool' => [$data, $data, true],
997 * Checks that stdWrap_data works properly.
1001 * - Delegates to method getData.
1002 * - Parameter 1 is $conf['data'].
1003 * - Parameter 2 is property data by default.
1004 * - Parameter 2 is property alternativeData, if set as array.
1005 * - Property alternativeData is always unset to ''.
1006 * - Returns the return value.
1009 * @dataProvider stdWrap_dataDataProvider
1010 * @param mixed $expect Expect either $data or $alternativeData.
1011 * @param array $data The data.
1012 * @param mixed $alt The alternativeData.
1015 public function stdWrap_data($expect, $data, $alt)
1017 $conf = ['data' => $this->getUniqueId('conf.data')];
1018 $return = $this->getUniqueId('return');
1019 $subject = $this->getAccessibleMock(
1020 ContentObjectRenderer
::class, ['getData']);
1021 $subject->_set('data', $data);
1022 $subject->_set('alternativeData', $alt);
1024 ->expects($this->once())
1026 ->with($conf['data'], $expect)
1027 ->willReturn($return);
1028 $this->assertSame($return, $subject->stdWrap_data('discard', $conf));
1029 $this->assertSame('', $subject->_get('alternativeData'));
1033 * Check if stdWrap_preIfEmptyListNum works properly.
1037 * - Delegates to method listNum.
1038 * - Parameter 1 is $content.
1039 * - Parameter 2 is $conf['preIfEmptyListNum'].
1040 * - Parameter 3 is $conf['preIfEmptyListNum.']['splitChar'].
1041 * - Returns the return value.
1046 public function stdWrap_preIfEmptyListNum()
1048 $content = $this->getUniqueId('content');
1050 'preIfEmptyListNum' => $this->getUniqueId('preIfEmptyListNum'),
1051 'preIfEmptyListNum.' => [
1052 'splitChar' => $this->getUniqueId('splitChar')
1055 $return = $this->getUniqueId('return');
1056 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1057 ->setMethods(['listNum'])->getMock();
1059 ->expects($this->once())
1063 $conf['preIfEmptyListNum'],
1064 $conf['preIfEmptyListNum.']['splitChar']
1066 ->willReturn($return);
1067 $this->assertSame($return,
1068 $subject->stdWrap_preIfEmptyListNum($content, $conf));
1072 * Check if stdWrap_current works properly.
1076 * - current is returned from $this->data
1077 * - the key is stored in $this->currentValKey
1078 * - the key defaults to 'currentValue_kidjls9dksoje'
1083 public function stdWrap_current()
1086 'currentValue_kidjls9dksoje' => 'default',
1087 'currentValue_new' => 'new',
1089 $this->subject
->_set('data', $data);
1090 $this->assertSame('currentValue_kidjls9dksoje',
1091 $this->subject
->_get('currentValKey'));
1092 $this->assertSame('default',
1093 $this->subject
->stdWrap_current('discarded', ['discarded']));
1094 $this->subject
->_set('currentValKey', 'currentValue_new');
1095 $this->assertSame('new',
1096 $this->subject
->stdWrap_current('discarded', ['discarded']));
1100 * Check if stdWrap_preUserFunc works properly.
1104 * - Delegates to method callUserFunction.
1105 * - Parameter 1 is $conf['preUserFunc'].
1106 * - Parameter 2 is $conf['preUserFunc.'].
1107 * - Parameter 3 is $content.
1108 * - Returns the return value.
1113 public function stdWrap_preUserFunc()
1115 $content = $this->getUniqueId('content');
1117 'preUserFunc' => $this->getUniqueId('preUserFunc'),
1118 'preUserFunc.' => [$this->getUniqueId('preUserFunc.')],
1120 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1121 ->setMethods(['callUserFunction'])->getMock();
1122 $subject->expects($this->once())->method('callUserFunction')
1123 ->with($conf['preUserFunc'], $conf['preUserFunc.'], $content)
1124 ->willReturn('return');
1125 $this->assertSame('return',
1126 $subject->stdWrap_preUserFunc($content, $conf));
1130 * Data provider for stdWrap_csConv
1132 * @return array Order expected, input, conf
1134 public function stdWrap_overrideDataProvider()
1137 'standard case' => [
1138 'override', 'content', ['override' => 'override']
1140 'empty conf does not override' => [
1141 'content', 'content', []
1143 'empty string does not override' => [
1144 'content', 'content', ['override' => '']
1146 'whitespace does not override' => [
1147 'content', 'content', ['override' => ' ' . TAB
]
1149 'zero does not override' => [
1150 'content', 'content', ['override' => 0]
1152 'false does not override' => [
1153 'content', 'content', ['override' => false]
1155 'null does not override' => [
1156 'content', 'content', ['override' => null]
1158 'one does override' => [
1159 1, 'content', ['override' => 1]
1161 'minus one does override' => [
1162 -1, 'content', ['override' => -1]
1164 'float does override' => [
1165 -0.1, 'content', ['override' => -0.1]
1167 'true does override' => [
1168 true, 'content', ['override' => true]
1170 'the value is not trimmed' => [
1171 TAB
. 'override', 'content', ['override' => TAB
. 'override']
1177 * Check if stdWrap_override works properly.
1180 * @dataProvider stdWrap_overrideDataProvider
1181 * @param string $input The input value.
1182 * @param array $conf Property: setCurrent
1185 public function stdWrap_override($expect, $content, $conf)
1187 $this->assertSame($expect,
1188 $this->subject
->stdWrap_override($content, $conf));
1192 * Check if stdWrap_listNum works properly.
1196 * - Delegates to method listNum.
1197 * - Parameter 1 is $content.
1198 * - Parameter 2 is $conf['listNum'].
1199 * - Parameter 3 is $conf['listNum.']['splitChar'].
1200 * - Returns the return value.
1205 public function stdWrap_listNum()
1207 $content = $this->getUniqueId('content');
1209 'listNum' => $this->getUniqueId('listNum'),
1211 'splitChar' => $this->getUniqueId('splitChar')
1214 $return = $this->getUniqueId('return');
1215 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1216 ->setMethods(['listNum'])->getMock();
1218 ->expects($this->once())
1223 $conf['listNum.']['splitChar']
1225 ->willReturn($return);
1226 $this->assertSame($return,
1227 $subject->stdWrap_listNum($content, $conf));
1231 * Check if stdWrap_field works properly.
1235 * - calls getFieldVal
1236 * - passes conf['field'] as parameter
1241 public function stdWrap_field()
1243 $expect = $this->getUniqueId('expect');
1244 $conf = ['field' => $this->getUniqueId('field')];
1245 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1246 ->setMethods(['getFieldVal'])->getMock();
1248 ->expects($this->once())
1249 ->method('getFieldVal')
1250 ->with($conf['field'])
1251 ->willReturn($expect);
1252 $this->assertSame($expect,
1253 $subject->stdWrap_field('discarded', $conf));
1257 * Check if stdWrap_cObject works properly.
1261 * - Delegates to the method cObjGetSingle().
1262 * - First parameter is $conf['cObject'].
1263 * - Second parameter is $conf['cObject.'].
1264 * - Third parameter is '/stdWrap/.cObject'.
1265 * - Returns the return.
1270 public function stdWrap_cObject()
1272 $debugKey = '/stdWrap/.cObject';
1274 'cObject' => $this->getUniqueId('cObject'),
1275 'cObject.' => [$this->getUniqueId('cObject.')],
1277 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1278 ->setMethods(['cObjGetSingle'])->getMock();
1280 ->expects($this->once())
1281 ->method('cObjGetSingle')
1282 ->with($conf['cObject'], $conf['cObject.'], $debugKey)
1283 ->willReturn('return');
1284 $this->assertSame('return',
1285 $subject->stdWrap_cObject('discard', $conf));
1289 * Data provider for stdWrap_csConv
1291 * @return array Order expected, input, conf
1293 public function stdWrap_csConvDataProvider()
1296 'empty string from ISO-8859-15' => [
1298 iconv('UTF-8', 'ISO-8859-15', ''),
1299 ['csConv' => 'ISO-8859-15']
1301 'empty string from BIG-5' => [
1303 mb_convert_encoding('', 'BIG-5'),
1304 ['csConv' => 'BIG-5']
1306 '"0" from ISO-8859-15' => [
1308 iconv('UTF-8', 'ISO-8859-15', '0'),
1309 ['csConv' => 'ISO-8859-15']
1311 '"0" from BIG-5' => [
1313 mb_convert_encoding('0', 'BIG-5'),
1314 ['csConv' => 'BIG-5']
1316 'euro symbol from ISO-88859-15' => [
1318 iconv('UTF-8', 'ISO-8859-15', '€'),
1319 ['csConv' => 'ISO-8859-15']
1321 'good morning from BIG-5' => [
1323 mb_convert_encoding('早安', 'BIG-5'),
1324 ['csConv' => 'BIG-5']
1330 * Check if stdWrap_csConv works properly.
1333 * @dataProvider stdWrap_csConvDataProvider
1334 * @param string $expected The expected value.
1335 * @param string $value The input value.
1336 * @param array $conf Property: csConv
1339 public function stdWrap_csConv($expected, $input, $conf)
1341 $this->assertSame($expected,
1342 $this->subject
->stdWrap_csConv($input, $conf));
1346 * Check if stdWrap_split works properly.
1350 * - Delegates to method splitObj.
1351 * - Parameter 1 is $content.
1352 * - Prameter 2 is $conf['split.'].
1353 * - Returns the return value.
1358 public function stdWrap_split()
1360 $content = $this->getUniqueId('content');
1362 'split' => $this->getUniqueId('not used'),
1363 'split.' => [$this->getUniqueId('split.')],
1365 $return = $this->getUniqueId('return');
1366 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1367 ->setMethods(['splitObj'])->getMock();
1369 ->expects($this->once())
1370 ->method('splitObj')
1371 ->with($content, $conf['split.'])
1372 ->willReturn($return);
1373 $this->assertSame($return,
1374 $subject->stdWrap_split($content, $conf));
1378 * Data provider for stdWrap_prioriCalc
1380 * @return array [$expect, $content, $conf]
1382 public function stdWrap_prioriCalcDataProvider()
1385 'priority of *' => ['7', '1 + 2 * 3', []],
1386 'priority of parentheses' => ['9', '(1 + 2) * 3', []],
1387 'float' => ['1.5', '3/2', []],
1388 'intval casts to int' => [1, '3/2', ['prioriCalc' => 'intval']],
1389 'intval does not round' => [2, '2.7', ['prioriCalc' => 'intval']],
1394 * Check if stdWrap_prioriCalc works properly.
1398 * - If $conf['prioriCalc'] is 'intval' the return is casted to int.
1399 * - Delegates to MathUtility::calculateWithParentheses.
1401 * Note: As PHPUnit can't mock static methods, the call to
1402 * MathUtility::calculateWithParentheses can't be easily intercepted.
1403 * The test is done by testing input/output pairs instead. To not
1404 * duplicate the testing of calculateWithParentheses just a few
1405 * smoke tests are done here.
1408 * @dataProvider stdWrap_prioriCalcDataProvider
1409 * @param mixed $expect The expected output.
1410 * @param string $content The given content.
1411 * @param array $conf The given configuration.
1414 public function stdWrap_prioriCalc($expect, $content, $conf)
1416 $result = $this->subject
->stdWrap_prioriCalc($content, $conf);
1417 $this->assertSame($expect, $result);
1421 * Test for the stdWrap_stripHtml
1425 public function stdWrap_stripHtml()
1427 $content = '<html><p>Hello <span class="inline">inline tag<span>!</p><p>Hello!</p></html>';
1428 $expected = 'Hello inline tag!Hello!';
1429 $this->assertSame($expected, $this->subject
->stdWrap_stripHtml($content));
1433 * Data provider for round
1435 * @return array [$expect, $contet, $conf]
1437 public function roundDataProvider()
1441 'down' => [1.0, 1.11, []],
1442 'up' => [2.0, 1.51, []],
1443 'rounds up from x.50' => [2.0, 1.50, []],
1444 'down with decimals' => [0.12, 0.1231, ['decimals' => 2]],
1445 'up with decimals' => [0.13, 0.1251, ['decimals' => 2]],
1446 'ceil' => [1.0, 0.11, ['roundType' => 'ceil']],
1447 'ceil does not accept decimals' => [
1449 'roundType' => 'ceil',
1453 'floor' => [2.0, 2.99, ['roundType' => 'floor']],
1454 'floor does not accept decimals' => [
1456 'roundType' => 'floor',
1460 'round, down' => [1.0, 1.11, ['roundType' => 'round']],
1461 'round, up' => [2.0, 1.55, ['roundType' => 'round']],
1462 'round does accept decimals' => [
1464 'roundType' => 'round',
1469 'emtpy string' => [0.0, '', []],
1470 'word string' => [0.0, 'word', []],
1471 'float string' => [1.0, '1.123456789', []],
1473 'null' => [0.0, null, []],
1474 'false' => [0.0, false, []],
1475 'true' => [1.0, true, []]
1480 * Check if round works properly
1484 * - Different types of input are casted to float.
1485 * - Configuration ceil rounds like ceil().
1486 * - Configuration floor rounds like floor().
1487 * - Otherwise rounds like round() and decimals can be applied.
1488 * - Always returns float.
1490 * @param float $expected The expected output.
1491 * @param mixed $content The given content.
1492 * @param array $conf The given configuration of 'round.'.
1494 * @dataProvider roundDataProvider
1497 public function round($expect, $content, $conf)
1499 $this->assertSame($expect,
1500 $this->subject
->_call('round', $content, $conf));
1504 * Check if stdWrap_round works properly
1508 * - Delegates to method round.
1509 * - Parameter 1 is $content.
1510 * - Parameter 2 is $conf['round.'].
1511 * - Returns the return value.
1516 public function stdWrap_round()
1518 $content = $this->getUniqueId('content');
1520 'round' => $this->getUniqueId('not used'),
1521 'round.' => [$this->getUniqueId('round.')],
1523 $return = $this->getUniqueId('return');
1524 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1525 ->setMethods(['round'])->getMock();
1527 ->expects($this->once())
1529 ->with($content, $conf['round.'])
1530 ->willReturn($return);
1531 $this->assertSame($return, $subject->stdWrap_round($content, $conf));
1537 public function stdWrap_numberFormatDataProvider()
1540 'testing decimals' => array(
1543 'numberFormat.' => array(
1549 'testing decimals with input as string' => array(
1552 'numberFormat.' => array(
1558 'testing dec_point' => array(
1561 'numberFormat.' => array(
1568 'testing thousands_sep' => array(
1571 'numberFormat.' => array(
1573 'thousands_sep.' => array(
1580 'testing mixture' => array(
1583 'numberFormat.' => array(
1585 'dec_point.' => array(
1588 'thousands_sep.' => array(
1599 * Test for the stdWrap function "stdWrap_numberFormat"
1601 * @param float $float
1602 * @param array $conf
1603 * @param string $expected
1605 * @dataProvider stdWrap_numberFormatDataProvider
1608 public function stdWrap_numberFormat($float, $conf, $expected)
1610 $result = $this->subject
->stdWrap_numberFormat($float, $conf);
1611 $this->assertEquals($expected, $result);
1615 * Data provider for expandList
1617 * @return array [$expect, $content]
1619 public function stdWrap_expandListDataProvider()
1622 'numbers' => ['1,2,3', '1,2,3'],
1623 'range' => ['3,4,5', '3-5'],
1624 'numbers and range' => ['1,3,4,5,7', '1,3-5,7']
1629 * Test for the stdWrap function "expandList"
1631 * The method simply delegates to GeneralUtility::expandList. There is no
1632 * need to repeat the full set of tests of this method here. As PHPUnit
1633 * can't mock static methods, to prove they are called, all we do here
1634 * is to provide a few smoke tests.
1637 * @dataProvider stdWrap_expandListDataProvider
1638 * @param string $expected The expeced output.
1639 * @param string $content The given content.
1642 public function stdWrap_expandList($expected, $content)
1644 $this->assertEquals($expected,
1645 $this->subject
->stdWrap_expandList($content));
1649 * Data provider for stdWrap_trim.
1651 * @return array [$expect, $content]
1653 public function stdWrap_trimDataProvider()
1656 // string not trimmed
1657 'empty string' => ['', ''],
1658 'string without whitespace' => ['xxx', 'xxx'],
1659 'string with whitespace inside' => [
1660 'xx ' . TAB
. ' xx',
1661 'xx ' . TAB
. ' xx',
1663 'string with newlines inside' => [
1664 'xx ' . PHP_EOL
. ' xx',
1665 'xx ' . PHP_EOL
. ' xx',
1668 'blanks around' => ['xxx', ' xxx '],
1669 'tabs around' => ['xxx', TAB
. 'xxx' . TAB
],
1670 'newlines around' => ['xxx', PHP_EOL
. 'xxx' . PHP_EOL
],
1671 'mixed case' => ['xxx', TAB
. ' xxx ' . PHP_EOL
],
1673 'null' => ['', null],
1674 'false' => ['', false],
1675 'true' => ['1', true],
1679 '0.0' => ['0', 0.0],
1680 '1.0' => ['1', 1.0],
1681 '-1.0' => ['-1', -1.0],
1682 '1.1' => ['1.1', 1.1],
1687 * Check that stdWrap_trim works properly.
1691 * - the given string is trimmed like PHP trim
1692 * - non-strings are casted to strings:
1702 * @dataProvider stdWrap_trimDataProvider
1703 * @param string $expected The expected output.
1704 * @param mixed $content The given content.
1707 public function stdWrap_trim($expect, $content)
1709 $result = $this->subject
->stdWrap_trim($content);
1710 $this->assertSame($expect, $result);
1714 * Data provider for stdWrap_if.
1716 * @return array [$expect, $stop, $content, $conf, $times, $will]
1718 public function stdWrap_ifDataProvider()
1720 $content = $this->getUniqueId('content');
1721 $conf = ['if.' => [$this->getUniqueId('if.')]];
1725 $content, false, $content, [], 0, null
1727 'if. is empty array' => [
1728 $content, false, $content, ['if.' => []], 0, null
1731 $content, false, $content, ['if.' => null], 0, null
1734 $content, false, $content, ['if.' => false], 0, null
1737 $content, false, $content, ['if.' => false], 0, null
1740 $content, false, $content, ['if.' => '0'], 0, null
1742 'checkIf returning true' => [
1743 $content, false, $content, $conf, 1, true
1746 'checkIf returning false' => [
1747 '', true, $content, $conf, 1, false
1753 * Check if stdWrap_if works properly.
1757 * - Delegates to the method checkIf to check for 'true'.
1758 * - The parameter to checkIf is $conf['if.'].
1759 * - Is also 'true' if $conf['if.'] is empty (PHP method empty).
1760 * - 'False' triggers a stop of further rendering.
1761 * - Returns the content as is or '' if false.
1764 * @dataProvider stdWrap_ifDataProvider
1765 * @param mixed $expect The expected output.
1766 * @param bool $stop Expect stop further rendering.
1767 * @param mixed $content The given content.
1768 * @param mixed $config The given configuration.
1769 * @param int $times Times checkIf is called (0 or 1).
1770 * @param bool|null $will Return of checkIf (null if not called).
1773 public function stdWrap_if($expect, $stop, $content, $conf, $times, $will)
1775 $subject = $this->getAccessibleMock(
1776 ContentObjectRenderer
::class, ['checkIf']);
1777 $subject->_set('stdWrapRecursionLevel', 1);
1778 $subject->_set('stopRendering', [1 => false]);
1780 ->expects($this->exactly($times))
1782 ->with($conf['if.'])
1783 ->willReturn($will);
1784 $this->assertSame($expect, $subject->stdWrap_if($content, $conf));
1785 $this->assertSame($stop, $subject->_get('stopRendering')[1]);
1789 * Data provider for stdWrap_intval
1791 * @return array [$expect, $content]
1793 public function stdWrap_intvalDataProvider()
1797 'int' => [123, 123],
1798 'float' => [123, 123.45],
1799 'float does not round up' => [123, 123.55],
1801 'negative int' => [-123, -123],
1802 'negative float' => [-123, -123.45],
1803 'negative float does not round down' => [ -123, -123.55],
1805 'word string' => [0, 'string'],
1806 'empty string' => [0, ''],
1807 'zero string' => [0, '0'],
1808 'int string' => [123, '123'],
1809 'float string' => [123, '123.55'],
1810 'negative float string' => [-123, '-123.55'],
1812 'null' => [0, null],
1813 'true' => [1, true],
1814 'false' => [0, false]
1819 * Check that stdWrap_intval works properly.
1823 * - It does not round up.
1824 * - All types of input is casted to int:
1833 * @dataProvider stdWrap_intvalDataProvider
1834 * @param int $expect The expected output.
1835 * @param string $content The given input.
1838 public function stdWrap_intval($expect, $content)
1840 $this->assertSame($expect, $this->subject
->stdWrap_intval($content));
1844 * Data provider for stdWrap_strPad.
1846 * @return array [$expect, $content, $conf]
1848 public function stdWrap_strPadDataProvider()
1851 'pad string with default settings and length 10' => [
1858 'pad string with padWith -= and type left and length 10' => [
1867 'pad string with padWith _ and type both and length 10' => [
1876 'pad string with padWith 0 and type both and length 10' => [
1885 'pad string with padWith ___ and type both and length 6' => [
1894 'pad string with padWith _ and type both and length 12, using stdWrap for length' => [
1906 'pad string with padWith _ and type both and length 12, using stdWrap for padWidth' => [
1918 'pad string with padWith _ and type both and length 12, using stdWrap for type' => [
1925 // make type become "left"
1927 'substring' => '2,1',
1936 * Check if stdWrap_strPad works properly.
1939 * @dataProvider stdWrap_strPadDataProvider
1940 * @param string $expect The expected output.
1941 * @param string $content The given input.
1942 * @param array $conf The configuration of 'strPad.'.
1945 public function stdWrap_strPad($expect, $content, $conf)
1947 $conf = ['strPad.' => $conf];
1948 $result = $this->subject
->stdWrap_strPad($content, $conf);
1949 $this->assertSame($expect, $result);
1953 * Check that stdWrap_stdWrap works properly.
1956 * - Delegates to method stdWrap.
1957 * - Parameter 1 is $content.
1958 * - Parameter 2 is $conf['stdWrap.'].
1959 * - Returns the return value.
1964 public function stdWrap_stdWrap()
1966 $content = $this->getUniqueId('content');
1968 'stdWrap' => $this->getUniqueId('not used'),
1969 'stdWrap.' => [$this->getUniqueId('stdWrap.')],
1971 $return = $this->getUniqueId('return');
1972 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
1973 ->setMethods(['stdWrap'])->getMock();
1975 ->expects($this->once())
1977 ->with($content, $conf['stdWrap.'])
1978 ->willReturn($return);
1979 $this->assertSame($return, $subject->stdWrap_stdWrap($content, $conf));
1983 * Data provider for the hash test
1985 * @return array [$expect, $content, $conf]
1987 public function hashDataProvider()
1991 'bacb98acf97e0b6112b1d1b650b84971',
1996 '063b3d108bed9f88fa618c6046de0dccadcf3158',
2000 'stdWrap capability' => [
2001 'bacb98acf97e0b6112b1d1b650b84971',
2005 'hash.' => ['wrap' => 'md|']
2008 'non-existing hashing algorithm' => [
2011 ['hash' => 'non-existing']
2017 * Check if stdWrap_hash works properly.
2021 * - Algorithms: sha1, md5
2022 * - Returns '' for invalid algorithm.
2023 * - Value can be processed by stdWrap.
2026 * @dataProvider hashDataProvider
2027 * @param string $expect The expected output.
2028 * @param string $content The given content.
2029 * @param array $conf The given configuration.
2032 public function stdWrap_hash($expect, $content, $conf)
2034 $this->assertSame($expect,
2035 $this->subject
->stdWrap_hash($content, $conf));
2041 public function recursiveStdWrapProperlyRendersBasicString()
2043 $stdWrapConfiguration = array(
2044 'noTrimWrap' => '|| 123|',
2045 'stdWrap.' => array(
2046 'wrap' => '<b>|</b>'
2051 $this->subject
->stdWrap('Test', $stdWrapConfiguration)
2058 public function recursiveStdWrapIsOnlyCalledOnce()
2060 $stdWrapConfiguration = array(
2063 'data' => 'register:Counter'
2065 'stdWrap.' => array(
2066 'append' => 'LOAD_REGISTER',
2068 'Counter.' => array(
2069 'prioriCalc' => 'intval',
2070 'cObject' => 'TEXT',
2071 'cObject.' => array(
2072 'data' => 'register:Counter',
2081 $this->subject
->stdWrap('Counter:', $stdWrapConfiguration)
2086 * Data provider for the numberFormat test
2088 * @return array multi-dimensional array with the second level like this:
2091 public function numberFormatDataProvider()
2094 'testing decimals' => array(
2101 'testing decimals with input as string' => array(
2108 'testing dec_point' => array(
2116 'testing thousands_sep' => array(
2120 'thousands_sep.' => array(
2126 'testing mixture' => array(
2130 'dec_point.' => array(
2133 'thousands_sep.' => array(
2144 * Check if stdWrap.numberFormat and all of its properties work properly
2146 * @dataProvider numberFormatDataProvider
2149 public function numberFormat($float, $formatConf, $expected)
2151 $result = $this->subject
->numberFormat($float, $formatConf);
2152 $this->assertEquals($expected, $result);
2156 * Check if stdWrap_replacement works properly.
2160 * - Delegates to method replacement.
2161 * - Parameter 1 is $content.
2162 * - Parameter 2 is $conf['replacement.'].
2163 * - Returns the return value.
2168 public function stdWrap_replacement()
2170 $content = $this->getUniqueId('content');
2172 'replacement' => $this->getUniqueId('not used'),
2173 'replacement.' => [$this->getUniqueId('replacement.')],
2175 $return = $this->getUniqueId('return');
2176 $subject = $this->getMockBuilder(ContentObjectRenderer
::class)
2177 ->setMethods(['replacement'])->getMock();
2179 ->expects($this->once())
2180 ->method('replacement')
2181 ->with( $content, $conf['replacement.'])
2182 ->willReturn($return);
2183 $this->assertSame($return,
2184 $subject->stdWrap_replacement($content, $conf));
2188 * Data provider replacement
2190 * @return array [$expect, $content, $conf]
2192 public function replacementDataProvider()
2195 'multiple replacements, including regex' => [
2196 'There is an animal, an animal and an animal around the block! Yeah!',
2197 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
2201 'replace.' => ['char' => '32']
2204 'search' => 'in da hood',
2205 'replace' => 'around the block'
2208 'search' => '#a (Cat|Dog|Tiger)#i',
2209 'replace' => 'an animal',
2214 'replacement with optionSplit, normal pattern' => [
2215 'There1is2a3cat,3a3dog3and3a3tiger3in3da3hood!3Yeah!',
2216 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
2220 'replace' => '1 || 2 || 3',
2221 'useOptionSplitReplace' => '1'
2225 'replacement with optionSplit, using regex' => [
2226 'There is a tiny cat, a midsized dog and a big tiger in da hood! Yeah!',
2227 'There is a cat, a dog and a tiger in da hood! Yeah!',
2230 'search' => '#(a) (Cat|Dog|Tiger)#i',
2231 'replace' => '${1} tiny ${2} || ${1} midsized ${2} || ${1} big ${2}',
2232 'useOptionSplitReplace' => '1',
2241 * Check if stdWrap.replacement and all of its properties work properly
2244 * @dataProvider replacementDataProvider
2245 * @param string $content The given input.
2246 * @param string $expects The expected result.
2247 * @param array $conf The given configuration.
2250 public function replacement($expects, $content, $conf)
2252 $this->assertSame($expects,
2253 $this->subject
->_call('replacement', $content, $conf));
2259 public function stdWrapRawUrlEncodeDataProvider()
2262 'https://typo3.org?id=10' => ['https://typo3.org?id=10', 'https%3A%2F%2Ftypo3.org%3Fid%3D10'],
2263 'https://typo3.org?id=10&foo=bar' => ['https://typo3.org?id=10&foo=bar', 'https%3A%2F%2Ftypo3.org%3Fid%3D10%26foo%3Dbar'],
2268 * Check if rawUrlEncode works properly
2271 * @dataProvider stdWrapRawUrlEncodeDataProvider
2273 public function stdWrap_rawUrlEncode($input, $expected)
2275 $this->assertEquals($expected, $this->subject
->stdWrap_rawUrlEncode($input));
2279 * Data provider for the getQuery test
2281 * @return array multi-dimensional array with the second level like this:
2284 public function getQueryDataProvider()
2287 'testing empty conf' => array(
2294 'testing #17284: adding uid/pid for workspaces' => array(
2297 'selectFields' => 'header,bodytext'
2300 'SELECT' => 'header,bodytext, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
2303 'testing #17284: no need to add' => array(
2306 'selectFields' => 'tt_content.*'
2309 'SELECT' => 'tt_content.*'
2312 'testing #17284: no need to add #2' => array(
2315 'selectFields' => '*'
2321 'testing #29783: joined tables, prefix tablename' => array(
2324 'selectFields' => 'tt_content.header,be_users.username',
2325 'join' => 'be_users ON tt_content.cruser_id = be_users.uid'
2328 'SELECT' => 'tt_content.header,be_users.username, tt_content.uid as uid, tt_content.pid as pid, tt_content.t3ver_state as t3ver_state'
2331 'testing #34152: single count(*), add nothing' => array(
2334 'selectFields' => 'count(*)'
2337 'SELECT' => 'count(*)'
2340 'testing #34152: single max(crdate), add nothing' => array(
2343 'selectFields' => 'max(crdate)'
2346 'SELECT' => 'max(crdate)'
2349 'testing #34152: single min(crdate), add nothing' => array(
2352 'selectFields' => 'min(crdate)'
2355 'SELECT' => 'min(crdate)'
2358 'testing #34152: single sum(is_siteroot), add nothing' => array(
2361 'selectFields' => 'sum(is_siteroot)'
2364 'SELECT' => 'sum(is_siteroot)'
2367 'testing #34152: single avg(crdate), add nothing' => array(
2370 'selectFields' => 'avg(crdate)'
2373 'SELECT' => 'avg(crdate)'
2381 * Check if sanitizeSelectPart works as expected
2383 * @dataProvider getQueryDataProvider
2386 public function getQuery($table, $conf, $expected)
2388 $GLOBALS['TCA'] = array(
2391 'enablecolumns' => array(
2392 'disabled' => 'hidden'
2396 'tt_content' => array(
2398 'enablecolumns' => array(
2399 'disabled' => 'hidden'
2401 'versioningWS' => true
2405 $result = $this->subject
->getQuery($table, $conf, true);
2406 foreach ($expected as $field => $value) {
2407 $this->assertEquals($value, $result[$field]);
2414 public function getQueryCallsGetTreeListWithNegativeValuesIfRecursiveIsSet()
2416 $GLOBALS['TCA'] = array(
2419 'enablecolumns' => array(
2420 'disabled' => 'hidden'
2424 'tt_content' => array(
2426 'enablecolumns' => array(
2427 'disabled' => 'hidden'
2432 $this->subject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class, array('getTreeList'));
2433 $this->subject
->start(array(), 'tt_content');
2435 'recursive' => '15',
2436 'pidInList' => '16, -35'
2438 $this->subject
->expects($this->at(0))
2439 ->method('getTreeList')
2441 ->will($this->returnValue('15,16'));
2442 $this->subject
->expects($this->at(1))
2443 ->method('getTreeList')
2445 ->will($this->returnValue('15,35'));
2446 $this->subject
->getQuery('tt_content', $conf, true);
2452 public function getQueryCallsGetTreeListWithCurrentPageIfThisIsSet()
2454 $GLOBALS['TCA'] = array(
2457 'enablecolumns' => array(
2458 'disabled' => 'hidden'
2462 'tt_content' => array(
2464 'enablecolumns' => array(
2465 'disabled' => 'hidden'
2470 $this->subject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class, array('getTreeList'));
2471 $GLOBALS['TSFE']->id
= 27;
2472 $this->subject
->start(array(), 'tt_content');
2474 'pidInList' => 'this',
2477 $this->subject
->expects($this->once())
2478 ->method('getTreeList')
2480 ->will($this->returnValue('27'));
2481 $this->subject
->getQuery('tt_content', $conf, true);
2485 * Data provider for the stdWrap_date test
2487 * @return array [$expect, $content, $conf, $now]
2489 public function stdWrap_dateDataProvider()
2491 // Fictive execution time: 2015-10-02 12:00
2494 'given timestamp' => [
2497 ['date' => 'd.m.Y'],
2503 ['date' => 'd.m.Y'],
2509 ['date' => 'd.m.Y'],
2512 'given timestamp return GMT' => [
2513 '02.10.2015 10:00:00',
2516 'date' => 'd.m.Y H:i:s',
2517 'date.' => ['GMT' => true],
2525 * Check if stdWrap_date works properly.
2528 * @dataProvider stdWrap_dateDataProvider
2529 * @param string $expected The expected output.
2530 * @param mixed $content The given input.
2531 * @param array $conf The given configuration.
2532 * @param int $now Fictive execution time.
2535 public function stdWrap_date($expected, $content, $conf, $now)
2537 $GLOBALS['EXEC_TIME'] = $now;
2538 $this->assertEquals($expected,
2539 $this->subject
->stdWrap_date($content, $conf));
2543 * Data provider for stdWrap_strftime
2545 * @return array [$expect, $content, $conf, $now]
2547 public function stdWrap_strftimeDataProvider()
2549 // Fictive execution time is 2012-09-01 12:00 in UTC/GMT.
2552 'given timestamp' => [
2555 ['strftime' => '%d-%m-%Y'],
2561 ['strftime' => '%d-%m-%Y'],
2567 ['strftime' => '%d-%m-%Y'],
2574 * Check if stdWrap_strftime works properly.
2577 * @dataProvider stdWrap_strftimeDataProvider
2578 * @param string $expect The expected output.
2579 * @param mixed $content The given input.
2580 * @param array $conf The given configuration.
2581 * @param int $now Fictive execution time.
2584 public function stdWrap_strftime($expect, $content, $conf, $now)
2586 // Save current timezone and set to UTC to make the system under test
2587 // behave the same in all server timezone settings
2588 $timezoneBackup = date_default_timezone_get();
2589 date_default_timezone_set('UTC');
2591 $GLOBALS['EXEC_TIME'] = $now;
2592 $result = $this->subject
->stdWrap_strftime($content, $conf);
2595 date_default_timezone_set($timezoneBackup);
2597 $this->assertSame($expect, $result);
2601 * Data provider for the stdWrap_strtotime test
2603 * @return array [$expect, $content, $conf]
2605 public function stdWrap_strtotimeDataProvider()
2608 'date from content' => [
2609 1417651200, '2014-12-04',
2610 ['strtotime' => '1']
2612 'manipulation of date from content' => [
2613 1417996800, '2014-12-04',
2614 ['strtotime' => '+ 2 weekdays']
2616 'date from configuration' => [
2618 ['strtotime' => '2014-12-04']
2620 'manipulation of date from configuration' => [
2622 ['strtotime' => '2014-12-04 + 2 weekdays']
2626 ['strtotime' => '1']
2628 'date from content and configuration' => [
2629 false, '2014-12-04',
2630 ['strtotime' => '2014-12-05']
2636 * Check if stdWrap_strtotime works properly.
2639 * @dataProvider stdWrap_strtotimeDataProvider
2640 * @param int $expect The expected output.
2641 * @param mixed $content The given input.
2642 * @param array $conf The given configuration.
2645 public function stdWrap_strtotime($expect, $content, $conf)
2647 // Set exec_time to a hard timestamp
2648 $GLOBALS['EXEC_TIME'] = 1417392000;
2649 // Save current timezone and set to UTC to make the system under test
2650 // behave the same in all server timezone settings
2651 $timezoneBackup = date_default_timezone_get();
2652 date_default_timezone_set('UTC');
2654 $result = $this->subject
->stdWrap_strtotime($content, $conf);
2657 date_default_timezone_set($timezoneBackup);
2659 $this->assertEquals($expect, $result);
2665 public function stdWrap_ageCallsCalcAgeWithSubtractedTimestampAndSubPartOfArray()
2667 $subject = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class)
2668 ->setMethods(array('calcAge'))
2670 // Set exec_time to a hard timestamp
2671 $GLOBALS['EXEC_TIME'] = 10;
2672 $subject->expects($this->once())->method('calcAge')->with(1, 'Min| Hrs| Days| Yrs');
2673 $subject->stdWrap_age(9, array('age' => 'Min| Hrs| Days| Yrs'));
2677 * Data provider for calcAgeCalculatesAgeOfTimestamp
2682 public function calcAgeCalculatesAgeOfTimestampDataProvider()
2687 ' min| hrs| days| yrs',
2692 ' min| hrs| days| yrs',
2697 ' min| hrs| days| yrs',
2700 'day with provided singular labels' => array(
2702 ' min| hrs| days| yrs| min| hour| day| year',
2707 ' min| hrs| days| yrs',
2710 'different labels' => array(
2712 ' Minutes| Hrs| Days| Yrs',
2715 'negative values' => array(
2717 ' min| hrs| days| yrs',
2720 'default label values for wrong label input' => array(
2725 'default singular label values for wrong label input' => array(
2734 * @param int $timestamp
2735 * @param string $labels
2736 * @param int $expectation
2737 * @dataProvider calcAgeCalculatesAgeOfTimestampDataProvider
2740 public function calcAgeCalculatesAgeOfTimestamp($timestamp, $labels, $expectation)
2742 $result = $this->subject
->calcAge($timestamp, $labels);
2743 $this->assertEquals($result, $expectation);
2749 public function stdWrapReturnsExpectationDataProvider()
2752 'Prevent silent bool conversion' => [
2765 * @param string $content
2766 * @param array $configuration
2767 * @param string $expectation
2768 * @dataProvider stdWrapReturnsExpectationDataProvider
2771 public function stdWrapReturnsExpectation($content, array $configuration, $expectation)
2773 $this->assertSame($expectation, $this->subject
->stdWrap($content, $configuration));
2777 * Data provider for stdWrap_case test
2781 public function stdWrap_caseDataProvider()
2784 'lower case text to upper' => array(
2785 '<span>text</span>',
2789 '<span>TEXT</span>',
2791 'upper case text to lower' => array(
2792 '<span>TEXT</span>',
2796 '<span>text</span>',
2798 'capitalize text' => array(
2799 '<span>this is a text</span>',
2801 'case' => 'capitalize',
2803 '<span>This Is A Text</span>',
2805 'ucfirst text' => array(
2806 '<span>this is a text</span>',
2808 'case' => 'ucfirst',
2810 '<span>This is a text</span>',
2812 'lcfirst text' => array(
2813 '<span>This is a Text</span>',
2815 'case' => 'lcfirst',
2817 '<span>this is a Text</span>',
2819 'uppercamelcase text' => array(
2820 '<span>this_is_a_text</span>',
2822 'case' => 'uppercamelcase',
2824 '<span>ThisIsAText</span>',
2826 'lowercamelcase text' => array(
2827 '<span>this_is_a_text</span>',
2829 'case' => 'lowercamelcase',
2831 '<span>thisIsAText</span>',
2837 * @param string|NULL $content
2838 * @param array $configuration
2839 * @param string $expected
2840 * @dataProvider stdWrap_caseDataProvider
2843 public function stdWrap_case($content, array $configuration, $expected)
2845 $result = $this->subject
->stdWrap_case($content, $configuration);
2846 $this->assertEquals($expected, $result);
2850 * Data provider for stdWrap_bytes test
2854 public function stdWrap_bytesDataProvider()
2857 'value 1234 default' => array(
2868 'value 1234 si' => array(
2879 'value 1234 iec' => array(
2890 'value 1234 a-i' => array(
2894 'labels' => 'a|b|c|d|e|f|g|h|i',
2901 'value 1234 a-i invalid base' => array(
2905 'labels' => 'a|b|c|d|e|f|g|h|i',
2912 'value 1234567890 default' => array(
2927 * @param string|NULL $content
2928 * @param array $configuration
2929 * @param string $expected
2930 * @dataProvider stdWrap_bytesDataProvider
2933 public function stdWrap_bytes($content, array $configuration, $expected, $locale)
2935 if (!setlocale(LC_NUMERIC
, $locale)) {
2936 $this->markTestSkipped('Locale ' . $locale . ' is not available.');
2938 $result = $this->subject
->stdWrap_bytes($content, $configuration);
2939 $this->assertSame($expected, $result);
2943 * Data provider for stdWrap_substring test
2947 public function stdWrap_substringDataProvider()
2953 'substring' => '-1',
2957 'sub -1,0' => array(
2960 'substring' => '-1,0',
2964 'sub -1,-1' => array(
2967 'substring' => '-1,-1',
2971 'sub -1,1' => array(
2974 'substring' => '-1,1',
2988 'substring' => '0,0',
2992 'sub 0,-1' => array(
2995 'substring' => '0,-1',
3002 'substring' => '0,1',
3016 'substring' => '1,0',
3020 'sub 1,-1' => array(
3023 'substring' => '1,-1',
3030 'substring' => '1,1',