27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 use TYPO3Fluid\Fluid\View\TemplateView;
63 protected function setUp()
65 $this->contentObjectRenderer = $this->getMockBuilder(
66 ContentObjectRenderer::class
68 $this->subject = $this->getAccessibleMock(
69 FluidTemplateContentObject::class,
70 [
'initializeStandaloneViewInstance'],
71 [$this->contentObjectRenderer]
74 $tsfe = $this->createMock(TypoScriptFrontendController::class);
75 $tsfe->tmpl = $this->getMockBuilder(TemplateService::class)
76 ->disableOriginalConstructor(
true)
86 $this->standaloneView = $this->createMock(StandaloneView::class);
87 $this->request = $this->getMockBuilder(Request::class)->getMock();
89 ->expects($this->any())
90 ->method(
'getRequest')
91 ->will($this->returnValue($this->request));
92 $this->subject->_set(
'view', $this->standaloneView);
100 $this->assertSame($this->contentObjectRenderer, $this->subject->getContentObjectRenderer());
110 ->expects($this->once())
111 ->method(
'initializeStandaloneViewInstance');
112 $this->subject->render([]);
122 $templateService =
$GLOBALS[
'TSFE']->tmpl;
124 ->expects($this->any())
125 ->method(
'getFileName')
127 $this->subject->render([
'file' =>
'foo']);
136 $this->contentObjectRenderer
137 ->expects($this->any())
139 ->with(
'foo', [
'bar' =>
'baz']);
140 $this->subject->render([
'file' =>
'foo',
'file.' => [
'bar' =>
'baz']]);
149 $this->contentObjectRenderer
150 ->expects($this->at(0))
152 ->with(
'dummyPath', [
'wrap' =>
'|5/']);
153 $this->contentObjectRenderer
154 ->expects($this->at(1))
156 ->with(
'', [
'field' =>
'someField']);
157 $this->subject->render(
159 'templateName' =>
'foobar',
160 'templateRootPaths.' => [
167 'field' =>
'someField',
180 $this->standaloneView
181 ->expects($this->any())
182 ->method(
'setTemplatePathAndFilename')
184 $this->subject->render([
'file' =>
'EXT:core/bar.html']);
194 $this->contentObjectRenderer
195 ->expects($this->any())
196 ->method(
'cObjGetSingle')
198 ->will($this->returnValue(
'baz'));
200 $this->standaloneView
201 ->expects($this->any())
202 ->method(
'setTemplateSource')
205 $this->subject->render([
206 'template' =>
'FILE',
220 $this->standaloneView
221 ->expects($this->any())
222 ->method(
'getFormat')
223 ->will($this->returnValue(
'html'));
224 $this->standaloneView
225 ->expects($this->once())
226 ->method(
'setTemplate')
229 $this->subject->render(
231 'templateName' =>
'foo',
232 'templateRootPaths.' => [
247 $this->contentObjectRenderer
248 ->expects($this->once())
250 ->with(
'TEXT', [
'value' =>
'bar'])
251 ->will($this->returnValue(
'bar'));
252 $this->standaloneView
253 ->expects($this->any())
254 ->method(
'getFormat')
255 ->will($this->returnValue(
'html'));
256 $this->standaloneView
257 ->expects($this->once())
258 ->method(
'setTemplate')
261 $this->subject->render(
263 'templateName' =>
'TEXT',
264 'templateName.' => [
'value' =>
'bar'],
265 'templateRootPaths.' => [
279 $this->standaloneView
280 ->expects($this->once())
281 ->method(
'setLayoutRootPaths')
283 $this->subject->render([
'layoutRootPath' =>
'foo/bar.html']);
292 $this->contentObjectRenderer
293 ->expects($this->once())
295 ->with(
'foo', [
'bar' =>
'baz']);
296 $this->subject->render([
'layoutRootPath' =>
'foo',
'layoutRootPath.' => [
'bar' =>
'baz']]);
305 $this->contentObjectRenderer
306 ->expects($this->at(0))
308 ->with(
'FILE', [
'file' =>
'foo/bar.html']);
309 $this->subject->render(
311 'layoutRootPaths.' => [
314 'file' =>
'foo/bar.html',
316 20 =>
'foo/bar2.html',
328 $this->standaloneView
329 ->expects($this->once())
330 ->method(
'setLayoutRootPaths')
335 $this->subject->render([
'layoutRootPaths.' => [10 =>
'foo/bar.html', 20 =>
'foo/bar2.html']]);
344 $this->standaloneView
345 ->expects($this->once())
346 ->method(
'setLayoutRootPaths')
352 $this->subject->render([
353 'layoutRootPath' =>
'foo/main.html',
354 'layoutRootPaths.' => [10 =>
'foo/bar.html', 20 =>
'foo/bar2.html']
364 $this->standaloneView
365 ->expects($this->once())
366 ->method(
'setPartialRootPaths')
368 $this->subject->render([
'partialRootPath' =>
'foo/bar.html']);
377 $this->contentObjectRenderer
378 ->expects($this->at(0))
380 ->with(
'FILE', [
'file' =>
'foo/bar.html']);
381 $this->subject->render(
383 'partialRootPaths.' => [
386 'file' =>
'foo/bar.html',
388 20 =>
'foo/bar2.html',
400 $this->contentObjectRenderer
401 ->expects($this->once())
403 ->with(
'foo', [
'bar' =>
'baz']);
404 $this->subject->render([
'partialRootPath' =>
'foo',
'partialRootPath.' => [
'bar' =>
'baz']]);
413 $this->standaloneView
414 ->expects($this->once())
415 ->method(
'setPartialRootPaths')
417 $this->subject->render([
'partialRootPaths.' => [10 =>
'foo', 20 =>
'bar']]);
426 $this->standaloneView
427 ->expects($this->once())
428 ->method(
'setPartialRootPaths')
434 $this->subject->render([
'partialRootPath' =>
'main',
'partialRootPaths.' => [10 =>
'foo', 20 =>
'bar']]);
443 $this->standaloneView
444 ->expects($this->once())
445 ->method(
'setFormat')
447 $this->subject->render([
'format' =>
'xml']);
456 $this->contentObjectRenderer
457 ->expects($this->once())
459 ->with(
'foo', [
'bar' =>
'baz']);
460 $this->subject->render([
'format' =>
'foo',
'format.' => [
'bar' =>
'baz']]);
470 ->expects($this->once())
471 ->method(
'setPluginName')
475 'pluginName' =>
'foo',
478 $this->subject->render($configuration);
487 $this->contentObjectRenderer
488 ->expects($this->once())
490 ->with(
'foo', [
'bar' =>
'baz']);
493 'pluginName' =>
'foo',
499 $this->subject->render($configuration);
509 ->expects($this->once())
510 ->method(
'setControllerExtensionName')
514 'controllerExtensionName' =>
'foo',
517 $this->subject->render($configuration);
526 $this->contentObjectRenderer
527 ->expects($this->once())
529 ->with(
'foo', [
'bar' =>
'baz']);
532 'controllerExtensionName' =>
'foo',
533 'controllerExtensionName.' => [
538 $this->subject->render($configuration);
548 ->expects($this->once())
549 ->method(
'setControllerName')
553 'controllerName' =>
'foo',
556 $this->subject->render($configuration);
565 $this->contentObjectRenderer
566 ->expects($this->once())
568 ->with(
'foo', [
'bar' =>
'baz']);
571 'controllerName' =>
'foo',
572 'controllerName.' => [
577 $this->subject->render($configuration);
587 ->expects($this->once())
588 ->method(
'setControllerActionName')
592 'controllerActionName' =>
'foo',
595 $this->subject->render($configuration);
604 $this->contentObjectRenderer
605 ->expects($this->once())
607 ->with(
'foo', [
'bar' =>
'baz']);
610 'controllerActionName' =>
'foo',
611 'controllerActionName.' => [
616 $this->subject->render($configuration);
635 $expectedSettingsToBeSet = [
643 $typoScriptServiceMock = $this->getMockBuilder(TypoScriptService::class)->getMock();
644 $typoScriptServiceMock
645 ->expects($this->once())
646 ->method(
'convertTypoScriptArrayToPlainArray')
647 ->with($configuration[
'settings.'])
648 ->will($this->returnValue($expectedSettingsToBeSet));
649 GeneralUtility::addInstance(TypoScriptService::class, $typoScriptServiceMock);
651 $this->standaloneView
652 ->expects($this->at(1))
654 ->with(
'settings', $expectedSettingsToBeSet);
656 $this->subject->render($configuration);
673 $this->expectException(\InvalidArgumentException::class);
674 $this->expectExceptionCode(1288095720);
675 $this->subject->render($configuration);
692 $this->expectException(\InvalidArgumentException::class);
693 $this->expectExceptionCode(1288095720);
694 $this->subject->render($configuration);
711 $this->contentObjectRenderer
712 ->expects($this->once())
713 ->method(
'cObjGetSingle')
714 ->with(
'TEXT', [
'value' =>
'foo']);
715 $this->subject->render($configuration);
732 $this->contentObjectRenderer
733 ->expects($this->once())
734 ->method(
'cObjGetSingle')
735 ->will($this->returnValue(
'foo'));
736 $this->standaloneView
737 ->expects($this->once())
738 ->method(
'assignMultiple')
739 ->with([
'aVar' =>
'foo',
'data' => [],
'current' =>
null]);
740 $this->subject->render($configuration);
749 $this->contentObjectRenderer->data = [
'foo'];
750 $this->standaloneView
751 ->expects($this->once())
752 ->method(
'assignMultiple')
753 ->with([
'data' => [
'foo'],
'current' =>
null]);
754 $this->subject->render([]);
763 $this->contentObjectRenderer->data = [
'currentKey' =>
'currentValue'];
764 $this->contentObjectRenderer->currentValKey =
'currentKey';
765 $this->standaloneView
766 ->expects($this->once())
767 ->method(
'assignMultiple')
768 ->with([
'data' => [
'currentKey' =>
'currentValue'],
'current' =>
'currentValue']);
769 $this->subject->render([]);
778 $this->standaloneView
779 ->expects($this->once())
781 $this->subject->render([]);
795 $this->standaloneView
796 ->expects($this->any())
798 ->will($this->returnValue(
'baz'));
799 $this->contentObjectRenderer
800 ->expects($this->once())
802 ->with(
'baz', [
'foo' =>
'bar']);
803 $this->subject->render($configuration);
818 $pageRendererMock = $this->getMockBuilder(PageRenderer::class)->setMethods([
822 if (!empty(trim($expectedHeader))) {
823 $pageRendererMock->expects($this->once())->method(
'addHeaderData')->with($expectedHeader);
825 $pageRendererMock->expects($this->never())->method(
'addHeaderData');
827 if (!empty(trim($expectedFooter))) {
828 $pageRendererMock->expects($this->once())->method(
'addFooterData')->with($expectedFooter);
830 $pageRendererMock->expects($this->never())->method(
'addFooterData');
832 $subject = $this->getMockBuilder(FluidTemplateContentObject::class)->setMethods([
'getPageRenderer'])->disableOriginalConstructor()->getMock();
833 $subject->expects($this->once())->method(
'getPageRenderer')->willReturn($pageRendererMock);
834 $viewProperty = new \ReflectionProperty(
$subject,
'view');
835 $viewProperty->setAccessible(
true);
836 $viewProperty->setValue(
$subject, $viewMock);
838 $method = new \ReflectionMethod(
$subject,
'renderFluidTemplateAssetsIntoPageRenderer');
839 $method->setAccessible(
true);
848 $viewWithHeaderData = $this->getMockBuilder(TemplateView::class)->setMethods([
'renderSection'])->disableOriginalConstructor()->getMock();
849 $viewWithHeaderData->expects($this->at(0))->method(
'renderSection')->with(
853 )->willReturn(
'custom-header-data');
854 $viewWithHeaderData->expects($this->at(1))->method(
'renderSection')->with(
859 $viewWithFooterData = $this->getMockBuilder(TemplateView::class)->setMethods([
'renderSection'])->disableOriginalConstructor()->getMock();
860 $viewWithFooterData->expects($this->at(0))->method(
'renderSection')->with(
865 $viewWithFooterData->expects($this->at(1))->method(
'renderSection')->with(
869 )->willReturn(
'custom-footer-data');
870 $viewWithBothData = $this->getMockBuilder(TemplateView::class)->setMethods([
'renderSection'])->disableOriginalConstructor()->getMock();
871 $viewWithBothData->expects($this->at(0))->method(
'renderSection')->with(
875 )->willReturn(
'custom-header-data');
876 $viewWithBothData->expects($this->at(1))->method(
'renderSection')->with(
880 )->willReturn(
'custom-footer-data');
882 [$viewWithHeaderData,
'custom-header-data',
null],
883 [$viewWithFooterData,
null,
'custom-footer-data'],
884 [$viewWithBothData,
'custom-header-data',
'custom-footer-data']