TYPO3 CMS  TYPO3_7-6
FluidTemplateContentObjectTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
28 {
32  protected $singletonInstances = [];
33 
37  protected $subject = null;
38 
42  protected $contentObjectRenderer = null;
43 
47  protected $standaloneView = null;
48 
52  protected $request = null;
53 
57  protected function setUp()
58  {
59  $this->singletonInstances = GeneralUtility::getSingletonInstances();
60  $this->contentObjectRenderer = $this->getMock(
61  \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class
62  );
63  $this->subject = $this->getAccessibleMock(
64  \TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject::class,
65  ['initializeStandaloneViewInstance'],
66  [$this->contentObjectRenderer]
67  );
69  $tsfe = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, [], [], '', false);
70  $tsfe->tmpl = $this->getMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
71  $GLOBALS['TSFE'] = $tsfe;
72  }
73 
77  protected function tearDown()
78  {
79  GeneralUtility::resetSingletonInstances($this->singletonInstances);
80  parent::tearDown();
81  }
82 
86  protected function addMockViewToSubject()
87  {
88  $this->standaloneView = $this->getMock(\TYPO3\CMS\Fluid\View\StandaloneView::class, [], [], '', false);
89  $this->request = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Request::class);
90  $this->standaloneView
91  ->expects($this->any())
92  ->method('getRequest')
93  ->will($this->returnValue($this->request));
94  $this->subject->_set('view', $this->standaloneView);
95  }
96 
101  {
102  $this->assertSame($this->contentObjectRenderer, $this->subject->getContentObject());
103  }
104 
109  {
110  $this->addMockViewToSubject();
111  $this->subject
112  ->expects($this->once())
113  ->method('initializeStandaloneViewInstance');
114  $this->subject->render([]);
115  }
116 
120  public function renderCallsTemplateServiceGetFileNameForGivenTemplateFile()
121  {
122  $this->addMockViewToSubject();
124  $templateService = $GLOBALS['TSFE']->tmpl;
125  $templateService
126  ->expects($this->any())
127  ->method('getFileName')
128  ->with('foo');
129  $this->subject->render(['file' => 'foo']);
130  }
131 
136  {
137  $this->addMockViewToSubject();
138  $this->contentObjectRenderer
139  ->expects($this->any())
140  ->method('stdWrap')
141  ->with('foo', ['bar' => 'baz']);
142  $this->subject->render(['file' => 'foo', 'file.' => ['bar' => 'baz']]);
143  }
144 
149  {
150  $this->addMockViewToSubject();
151  $this->contentObjectRenderer
152  ->expects($this->at(0))
153  ->method('stdWrap')
154  ->with('dummyPath', ['wrap' => '|5/']);
155  $this->contentObjectRenderer
156  ->expects($this->at(1))
157  ->method('stdWrap')
158  ->with('', ['field' => 'someField']);
159  $this->subject->render([
160  'templateName' => 'foobar',
161  'templateRootPaths.' => [
162  10 => 'dummyPath',
163  '10.' => [
164  'wrap' => '|5/',
165  ],
166  15 => 'dummyPath6/',
167  '25.' => [
168  'field' => 'someField',
169  ],
170  ]
171  ]
172  );
173  }
174 
178  public function renderSetsTemplateFileInView()
179  {
180  $this->addMockViewToSubject();
182  $templateService = $GLOBALS['TSFE']->tmpl;
183  $templateService
184  ->expects($this->any())
185  ->method('getFileName')
186  ->with('foo')
187  ->will($this->returnValue('bar'));
188  $this->standaloneView
189  ->expects($this->any())
190  ->method('setTemplatePathAndFilename')
191  ->with(PATH_site . 'bar');
192  $this->subject->render(['file' => 'foo']);
193  }
194 
199  {
200  $this->addMockViewToSubject();
201 
202  $this->contentObjectRenderer
203  ->expects($this->any())
204  ->method('cObjGetSingle')
205  ->with('FILE', ['file' => PATH_site . 'foo/bar.html'])
206  ->will($this->returnValue('baz'));
207 
208  $this->standaloneView
209  ->expects($this->any())
210  ->method('setTemplateSource')
211  ->with('baz');
212 
213  $this->subject->render([
214  'template' => 'FILE',
215  'template.' => [
216  'file' => PATH_site . 'foo/bar.html'
217  ]
218  ]);
219  }
220 
225  {
226  $this->addMockViewToSubject();
227 
228  $this->standaloneView
229  ->expects($this->any())
230  ->method('getFormat')
231  ->will($this->returnValue('html'));
232  $this->standaloneView
233  ->expects($this->once())
234  ->method('setTemplate')
235  ->with('foo');
236 
237  $this->subject->render([
238  'templateName' => 'foo',
239  'templateRootPaths.' => [
240  0 => 'dummyPath1/',
241  1 => 'dummyPath2/']
242  ]
243  );
244  }
245 
250  {
251  $this->addMockViewToSubject();
252 
253  $this->contentObjectRenderer
254  ->expects($this->once())
255  ->method('stdWrap')
256  ->with('TEXT', ['value' => 'bar'])
257  ->will($this->returnValue('bar'));
258  $this->standaloneView
259  ->expects($this->any())
260  ->method('getFormat')
261  ->will($this->returnValue('html'));
262  $this->standaloneView
263  ->expects($this->once())
264  ->method('setTemplate')
265  ->with('bar');
266 
267  $this->subject->render([
268  'templateName' => 'TEXT',
269  'templateName.' => ['value' => 'bar'],
270  'templateRootPaths.' => [
271  0 => 'dummyPath1/',
272  1 => 'dummyPath2/']
273  ]
274  );
275  }
276 
281  {
282  $this->addMockViewToSubject();
283  $this->standaloneView
284  ->expects($this->once())
285  ->method('setLayoutRootPaths')
286  ->with([PATH_site . 'foo/bar.html']);
287  $this->subject->render(['layoutRootPath' => 'foo/bar.html']);
288  }
289 
294  {
295  $this->addMockViewToSubject();
296  $this->contentObjectRenderer
297  ->expects($this->once())
298  ->method('stdWrap')
299  ->with('foo', ['bar' => 'baz']);
300  $this->subject->render(['layoutRootPath' => 'foo', 'layoutRootPath.' => ['bar' => 'baz']]);
301  }
302 
307  {
308  $this->addMockViewToSubject();
309  $this->contentObjectRenderer
310  ->expects($this->at(0))
311  ->method('stdWrap')
312  ->with('FILE', ['file' => 'foo/bar.html']);
313  $this->subject->render(
314  [
315  'layoutRootPaths.' => [
316  10 => 'FILE',
317  '10.' => [
318  'file' => 'foo/bar.html',
319  ],
320  20 => 'foo/bar2.html',
321  ]
322  ]
323  );
324  }
325 
330  {
331  $this->addMockViewToSubject();
332  $this->standaloneView
333  ->expects($this->once())
334  ->method('setLayoutRootPaths')
335  ->with([10 => PATH_site . 'foo/bar.html', 20 => PATH_site . 'foo/bar2.html']);
336  $this->subject->render(['layoutRootPaths.' => [10 => 'foo/bar.html', 20 => 'foo/bar2.html']]);
337  }
338 
343  {
344  $this->addMockViewToSubject();
345  $this->standaloneView
346  ->expects($this->once())
347  ->method('setLayoutRootPaths')
348  ->with([0 => PATH_site . 'foo/main.html', 10 => PATH_site . 'foo/bar.html', 20 => PATH_site . 'foo/bar2.html']);
349  $this->subject->render(['layoutRootPath' => 'foo/main.html', 'layoutRootPaths.' => [10 => 'foo/bar.html', 20 => 'foo/bar2.html']]);
350  }
351 
356  {
357  $this->addMockViewToSubject();
358  $this->standaloneView
359  ->expects($this->once())
360  ->method('setPartialRootPaths')
361  ->with([PATH_site . 'foo/bar.html']);
362  $this->subject->render(['partialRootPath' => 'foo/bar.html']);
363  }
364 
369  {
370  $this->addMockViewToSubject();
371  $this->contentObjectRenderer
372  ->expects($this->at(0))
373  ->method('stdWrap')
374  ->with('FILE', ['file' => 'foo/bar.html']);
375  $this->subject->render(
376  [
377  'partialRootPaths.' => [
378  10 => 'FILE',
379  '10.' => [
380  'file' => 'foo/bar.html',
381  ],
382  20 => 'foo/bar2.html',
383  ]
384  ]
385  );
386  }
387 
392  {
393  $this->addMockViewToSubject();
394  $this->contentObjectRenderer
395  ->expects($this->once())
396  ->method('stdWrap')
397  ->with('foo', ['bar' => 'baz']);
398  $this->subject->render(['partialRootPath' => 'foo', 'partialRootPath.' => ['bar' => 'baz']]);
399  }
400 
405  {
406  $this->addMockViewToSubject();
407  $this->standaloneView
408  ->expects($this->once())
409  ->method('setPartialRootPaths')
410  ->with([10 => PATH_site . 'foo', 20 => PATH_site . 'bar']);
411  $this->subject->render(['partialRootPaths.' => [10 => 'foo', 20 => 'bar']]);
412  }
413 
418  {
419  $this->addMockViewToSubject();
420  $this->standaloneView
421  ->expects($this->once())
422  ->method('setPartialRootPaths')
423  ->with([0 => PATH_site . 'main', 10 => PATH_site . 'foo', 20 => PATH_site . 'bar']);
424  $this->subject->render(['partialRootPath' => 'main', 'partialRootPaths.' => [10 => 'foo', 20 => 'bar']]);
425  }
426 
430  public function renderSetsFormatInView()
431  {
432  $this->addMockViewToSubject();
433  $this->standaloneView
434  ->expects($this->once())
435  ->method('setFormat')
436  ->with('xml');
437  $this->subject->render(['format' => 'xml']);
438  }
439 
444  {
445  $this->addMockViewToSubject();
446  $this->contentObjectRenderer
447  ->expects($this->once())
448  ->method('stdWrap')
449  ->with('foo', ['bar' => 'baz']);
450  $this->subject->render(['format' => 'foo', 'format.' => ['bar' => 'baz']]);
451  }
452 
457  {
458  $this->addMockViewToSubject();
459  $this->request
460  ->expects($this->once())
461  ->method('setPluginName')
462  ->with('foo');
463  $configuration = [
464  'extbase.' => [
465  'pluginName' => 'foo',
466  ],
467  ];
468  $this->subject->render($configuration);
469  }
470 
475  {
476  $this->addMockViewToSubject();
477  $this->contentObjectRenderer
478  ->expects($this->once())
479  ->method('stdWrap')
480  ->with('foo', ['bar' => 'baz']);
481  $configuration = [
482  'extbase.' => [
483  'pluginName' => 'foo',
484  'pluginName.' => [
485  'bar' => 'baz',
486  ],
487  ],
488  ];
489  $this->subject->render($configuration);
490  }
491 
496  {
497  $this->addMockViewToSubject();
498  $this->request
499  ->expects($this->once())
500  ->method('setControllerExtensionName')
501  ->with('foo');
502  $configuration = [
503  'extbase.' => [
504  'controllerExtensionName' => 'foo',
505  ],
506  ];
507  $this->subject->render($configuration);
508  }
509 
514  {
515  $this->addMockViewToSubject();
516  $this->contentObjectRenderer
517  ->expects($this->once())
518  ->method('stdWrap')
519  ->with('foo', ['bar' => 'baz']);
520  $configuration = [
521  'extbase.' => [
522  'controllerExtensionName' => 'foo',
523  'controllerExtensionName.' => [
524  'bar' => 'baz',
525  ],
526  ],
527  ];
528  $this->subject->render($configuration);
529  }
530 
535  {
536  $this->addMockViewToSubject();
537  $this->request
538  ->expects($this->once())
539  ->method('setControllerName')
540  ->with('foo');
541  $configuration = [
542  'extbase.' => [
543  'controllerName' => 'foo',
544  ],
545  ];
546  $this->subject->render($configuration);
547  }
548 
553  {
554  $this->addMockViewToSubject();
555  $this->contentObjectRenderer
556  ->expects($this->once())
557  ->method('stdWrap')
558  ->with('foo', ['bar' => 'baz']);
559  $configuration = [
560  'extbase.' => [
561  'controllerName' => 'foo',
562  'controllerName.' => [
563  'bar' => 'baz',
564  ],
565  ],
566  ];
567  $this->subject->render($configuration);
568  }
569 
574  {
575  $this->addMockViewToSubject();
576  $this->request
577  ->expects($this->once())
578  ->method('setControllerActionName')
579  ->with('foo');
580  $configuration = [
581  'extbase.' => [
582  'controllerActionName' => 'foo',
583  ],
584  ];
585  $this->subject->render($configuration);
586  }
587 
592  {
593  $this->addMockViewToSubject();
594  $this->contentObjectRenderer
595  ->expects($this->once())
596  ->method('stdWrap')
597  ->with('foo', ['bar' => 'baz']);
598  $configuration = [
599  'extbase.' => [
600  'controllerActionName' => 'foo',
601  'controllerActionName.' => [
602  'bar' => 'baz',
603  ],
604  ],
605  ];
606  $this->subject->render($configuration);
607  }
608 
612  public function renderAssignsSettingsArrayToView()
613  {
614  $this->addMockViewToSubject();
615 
616  $configuration = [
617  'settings.' => [
618  'foo' => 'value',
619  'bar.' => [
620  'baz' => 'value2',
621  ],
622  ],
623  ];
624 
625  $expectedSettingsToBeSet = [
626  'foo' => 'value',
627  'bar' => [
628  'baz' => 'value2',
629  ],
630  ];
631 
633  $typoScriptServiceMock = $this->getMock(\TYPO3\CMS\Extbase\Service\TypoScriptService::class);
634  $typoScriptServiceMock
635  ->expects($this->once())
636  ->method('convertTypoScriptArrayToPlainArray')
637  ->with($configuration['settings.'])
638  ->will($this->returnValue($expectedSettingsToBeSet));
639  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Service\TypoScriptService::class, $typoScriptServiceMock);
640 
641  $this->standaloneView
642  ->expects($this->at(1))
643  ->method('assign')
644  ->with('settings', $expectedSettingsToBeSet);
645 
646  $this->subject->render($configuration);
647  }
648 
654  {
655  $this->addMockViewToSubject();
656  $configuration = [
657  'variables.' => [
658  'data' => 'foo',
659  'data.' => [
660  'bar' => 'baz',
661  ],
662  ],
663  ];
664  $this->subject->render($configuration);
665  }
666 
672  {
673  $this->addMockViewToSubject();
674  $configuration = [
675  'variables.' => [
676  'current' => 'foo',
677  'current.' => [
678  'bar' => 'baz',
679  ],
680  ],
681  ];
682  $this->subject->render($configuration);
683  }
684 
689  {
690  $this->addMockViewToSubject();
691  $configuration = [
692  'variables.' => [
693  'aVar' => 'TEXT',
694  'aVar.' => [
695  'value' => 'foo',
696  ],
697  ],
698  ];
699  $this->contentObjectRenderer
700  ->expects($this->once())
701  ->method('cObjGetSingle')
702  ->with('TEXT', ['value' => 'foo']);
703  $this->subject->render($configuration);
704  }
705 
710  {
711  $this->addMockViewToSubject();
712  $configuration = [
713  'variables.' => [
714  'aVar' => 'TEXT',
715  'aVar.' => [
716  'value' => 'foo',
717  ],
718  ],
719  ];
720  $this->contentObjectRenderer
721  ->expects($this->once())
722  ->method('cObjGetSingle')
723  ->will($this->returnValue('foo'));
724  $this->standaloneView
725  ->expects($this->once())
726  ->method('assignMultiple')
727  ->with(['aVar' => 'foo', 'data' => [], 'current' => null]);
728  $this->subject->render($configuration);
729  }
730 
735  {
736  $this->addMockViewToSubject();
737  $this->contentObjectRenderer->data = ['foo'];
738  $this->standaloneView
739  ->expects($this->once())
740  ->method('assignMultiple')
741  ->with(['data' => ['foo'], 'current' => null]);
742  $this->subject->render([]);
743  }
744 
749  {
750  $this->addMockViewToSubject();
751  $this->contentObjectRenderer->data = ['currentKey' => 'currentValue'];
752  $this->contentObjectRenderer->currentValKey = 'currentKey';
753  $this->standaloneView
754  ->expects($this->once())
755  ->method('assignMultiple')
756  ->with(['data' => ['currentKey' => 'currentValue'], 'current' => 'currentValue']);
757  $this->subject->render([]);
758  }
759 
764  {
765  $this->addMockViewToSubject();
766  $this->standaloneView
767  ->expects($this->once())
768  ->method('render');
769  $this->subject->render([]);
770  }
771 
776  {
777  $this->addMockViewToSubject();
778  $configuration = [
779  'stdWrap.' => [
780  'foo' => 'bar',
781  ],
782  ];
783  $this->standaloneView
784  ->expects($this->any())
785  ->method('render')
786  ->will($this->returnValue('baz'));
787  $this->contentObjectRenderer
788  ->expects($this->once())
789  ->method('stdWrap')
790  ->with('baz', ['foo' => 'bar']);
791  $this->subject->render($configuration);
792  }
793 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']