2 declare(strict_types = 1);
19 use Prophecy\Argument;
20 use Prophecy\Prophecy\ObjectProphecy;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
45 protected function setUp():
void
48 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
49 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
50 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
51 $cacheManagerProphecy->getCache(Argument::cetera())->willReturn($cacheFrontendProphecy->reveal());
63 'No start marker' => [
70 <!-- ###SUBPART### Start -->
76 'Start and stop marker in HTML comment' => [
78 <!-- ###SUBPART### Start -->
80 <!-- ###SUBPART### End -->
87 'Stop marker in HTML comment' => [
91 <!-- ###SUBPART### End -->
98 'Start marker in HTML comment' => [
100 <!-- ###SUBPART### Start -->
109 'Start and stop marker direct' => [
130 public function getSubpart(
string $content,
string $marker,
string $expected):
void
132 $this->assertSame($expected, $this->templateService->getSubpart($content, $marker));
143 'No start marker' => [
151 'No stop marker' => [
153 <!-- ###SUBPART### Start -->
161 <!-- ###SUBPART### Start -->
165 'Start and stop marker in HTML comment' => [
167 <!-- ###SUBPART### Start -->
169 <!-- ###SUBPART### End -->
179 'Recursive subpart' => [
181 <!-- ###SUBPART### Start -->text1<!-- ###SUBPART### End -->
182 <!-- ###SUBPART### Start -->text2<!-- ###SUBPART### End -->
193 'Keep HTML marker' => [
195 <!-- ###SUBPART### Start -->text<!-- ###SUBPART### End -->
202 <!-- ###SUBPART### Start -->hello<!-- ###SUBPART### End -->
205 'Keep HTML begin marker' => [
207 <!-- ###SUBPART### Start -->text###SUBPART###
214 <!-- ###SUBPART### Start -->hello###SUBPART###
217 'Keep HTML end marker' => [
219 ###SUBPART###text<!-- ###SUBPART### End -->
226 ###SUBPART###hello<!-- ###SUBPART### End -->
229 'Keep plain marker' => [
231 ###SUBPART###text###SUBPART###
238 ###SUBPART###hello###SUBPART###
243 ###SUBPART###text###SUBPART###
246 [
'before-',
'-after'],
250 ###SUBPART###before-text-after###SUBPART###
276 $this->templateService->substituteSubpart($content, $marker, $subpartContent, $recursive, $keepMarker)
286 'Upper case marker' => [
287 'This is ###MARKER1### and this is ###MARKER2###',
289 '###MARKER1###' =>
'marker 1',
290 '###MARKER2###' =>
'marker 2'
295 'This is marker 1 and this is marker 2'
297 'Lower case marker' => [
298 'This is ###MARKER1### and this is ###MARKER2###',
300 '###marker1###' =>
'marker 1',
301 '###marker2###' =>
'marker 2'
306 'This is marker 1 and this is marker 2'
308 'Upper case marker without hash mark' => [
309 'This is ###MARKER1### and this is ###MARKER2###',
311 'MARKER1' =>
'marker 1',
312 'MARKER2' =>
'marker 2'
317 'This is marker 1 and this is marker 2'
319 'Upper case marker with another hash mark' => [
320 'This is *MARKER1* and this is *MARKER2*',
322 'MARKER1' =>
'marker 1',
323 'MARKER2' =>
'marker 2'
328 'This is marker 1 and this is marker 2'
330 'Upper case marker with unused marker' => [
331 'This is ###MARKER1### and this is ###MARKER2### ###UNUSED###',
333 '###MARKER1###' =>
'marker 1',
334 '###MARKER2###' =>
'marker 2'
339 'This is marker 1 and this is marker 2 ###UNUSED###'
341 'Upper case marker with unused marker deleted' => [
342 'This is ###MARKER1### and this is ###MARKER2### ###UNUSED###',
344 '###MARKER1###' =>
'marker 1',
345 '###MARKER2###' =>
'marker 2'
350 'This is marker 1 and this is marker 2 '
367 array $markContentArray,
375 $this->templateService->substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused)
386 'This is a ###SAMPLE### text',
389 'This is a simple text'
392 'This is a ###SAMPLE### text with a ###SAMPLE### content',
395 'This is a simple text with a simple content'
407 public function substituteMarker(
string $content,
string $marker, $markContent,
string $expected):
void
409 $this->assertSame($expected, $this->templateService->substituteMarker($content, $marker, $markContent));
420 'Substitute multiple subparts at once with plain marker' => [
422 ###SUBPART1###text1###SUBPART1###
423 ###SUBPART2###text2###SUBPART2###
426 '###SUBPART1###' =>
'hello',
427 '###SUBPART2###' =>
'world'
446 $this->assertSame($expected, $this->templateService->substituteSubpartArray($content, $subpartsContent));
456 $template =
'###SINGLEMARKER1###
457 <!-- ###FOO### begin -->
458 <!-- ###BAR### begin -->
460 <!-- ###BAR### end -->
461 <!-- ###FOOTER### begin -->
463 <!-- ###FOOTER### end -->
464 <!-- ###FOO### end -->';
482 '###SINGLEMARKER###',
484 '###SINGLEMARKER###' =>
'Value 1'
491 'Subpart marker' => [
494 '###SINGLEMARKER1###' =>
'Value 1',
499 '###SINGLEMARKER2###' =>
'Value 2.1'
502 '###SINGLEMARKER2###' =>
'Value 2.2'
507 '###SINGLEMARKER3###' =>
'Value 3.1'
510 '###SINGLEMARKER3###' =>
'Value 3.2'
521 'Subpart marker with wrap' => [
524 'SINGLEMARKER1' =>
'Value 1',
529 'SINGLEMARKER2' =>
'Value 2.1'
532 'SINGLEMARKER2' =>
'Value 2.2'
537 'SINGLEMARKER3' =>
'Value 3.1'
540 'SINGLEMARKER3' =>
'Value 3.2'
551 'Subpart marker with lower marker array keys' => [
554 '###singlemarker1###' =>
'Value 1',
559 '###singlemarker2###' =>
'Value 2.1'
562 '###singlemarker2###' =>
'Value 2.2'
567 '###singlemarker3###' =>
'Value 3.1'
570 '###singlemarker3###' =>
'Value 3.2'
581 'Subpart marker with unused markers' => [
588 '###SINGLEMARKER2###' =>
'Value 2.1'
593 '###SINGLEMARKER3###' =>
'Value 3.1'
612 'Subpart marker with empty subpart' => [
615 '###SINGLEMARKER1###' =>
'Value 1',
620 '###SINGLEMARKER2###' =>
'Value 2.1'
623 '###SINGLEMARKER2###' =>
'Value 2.2'
658 array $markersAndSubparts,
666 $this->templateService->substituteMarkerAndSubpartArrayRecursive(
682 'no markers defined' => [
683 'dummy content with ###UNREPLACED### marker',
687 'dummy content with ###UNREPLACED### marker',
689 'no markers used' => [
690 'dummy content with no marker',
692 '###REPLACED###' =>
'_replaced_'
696 'dummy content with no marker',
699 'dummy content with ###REPLACED### marker',
701 '###REPLACED###' =>
'_replaced_'
705 'dummy content with _replaced_ marker'
707 'one marker with lots of chars' => [
708 'dummy content with ###RE.:##-=_()LACED### marker',
710 '###RE.:##-=_()LACED###' =>
'_replaced_'
714 'dummy content with _replaced_ marker'
716 'markers which are special' => [
717 'dummy ###aa##.#######A### ######',
719 '###aa##.###' =>
'content ',
721 '######' =>
'-is not considered-'
725 'dummy content #is ######'
727 'two markers in content, but more defined' => [
728 'dummy ###CONTENT### with ###REPLACED### marker',
730 '###REPLACED###' =>
'_replaced_',
731 '###CONTENT###' =>
'content',
732 '###NEVERUSED###' =>
'bar'
736 'dummy content with _replaced_ marker'
739 'dummy content with ###ASUBPART### around some text###ASUBPART###.',
742 '###ASUBPART###' =>
'some other text'
745 'dummy content with some other text.'
747 'one wrapped subpart' => [
748 'dummy content with ###AWRAPPEDSUBPART### around some text###AWRAPPEDSUBPART###.',
752 '###AWRAPPEDSUBPART###' => [
757 'dummy content with more content around some textcontent.'
759 'one subpart with markers, not replaced recursively' => [
760 'dummy ###CONTENT### with ###ASUBPART### around ###SOME### text###ASUBPART###.',
762 '###CONTENT###' =>
'content',
763 '###SOME###' =>
'-this should never make it into output-',
764 '###OTHER_NOT_REPLACED###' =>
'-this should never make it into output-'
767 '###ASUBPART###' =>
'some ###OTHER_NOT_REPLACED### text'
770 'dummy content with some ###OTHER_NOT_REPLACED### text.'
787 array $markContentArray,
788 array $subpartContentArray,
789 array $wrappedSubpartContentArray,
790 string $expectedContent
792 $resultContent = $this->templateService->substituteMarkerArrayCached(
795 $subpartContentArray,
796 $wrappedSubpartContentArray
798 $this->assertSame($expectedContent, $resultContent);