TYPO3 CMS  TYPO3_6-2
FluidTemplateContentObjectTest.php
Go to the documentation of this file.
1 <?php
3 
23 
30 
34  protected $singletonInstances = array();
35 
39  protected $subject = NULL;
40 
44  protected $contentObjectRenderer = NULL;
45 
49  protected $standaloneView = NULL;
50 
54  protected $request = NULL;
55 
59  public function setUp() {
61  $this->contentObjectRenderer = $this->getMock(
62  'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'
63  );
64  $this->subject = $this->getAccessibleMock(
65  'TYPO3\\CMS\\Frontend\\ContentObject\\FluidTemplateContentObject',
66  array('dummy', 'initializeStandaloneViewInstance'),
67  array($this->contentObjectRenderer)
68  );
70  $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
71  $tsfe->tmpl = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
72  $GLOBALS['TSFE'] = $tsfe;
73  }
74 
78  public function tearDown() {
80  parent::tearDown();
81  }
82 
86  protected function addMockViewToSubject() {
87  $this->standaloneView = $this->getMock('TYPO3\\CMS\\Fluid\\View\\StandaloneView', array(), array(), '', FALSE);
88  $this->request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request');
89  $this->standaloneView
90  ->expects($this->any())
91  ->method('getRequest')
92  ->will($this->returnValue($this->request));
93  $this->subject->_set('view', $this->standaloneView);
94  }
95 
100  $this->assertSame($this->contentObjectRenderer, $this->subject->getContentObject());
101  }
102 
107  $this->addMockViewToSubject();
108  $this->subject
109  ->expects($this->once())
110  ->method('initializeStandaloneViewInstance');
111  $this->subject->render(array());
112  }
113 
117  public function renderCallsTemplateServiceGetFileNameForGivenTemplateFile() {
118  $this->addMockViewToSubject();
120  $templateService = $GLOBALS['TSFE']->tmpl;
121  $templateService
122  ->expects($this->any())
123  ->method('getFileName')
124  ->with('foo');
125  $this->subject->render(array('file' => 'foo'));
126  }
127 
132  $this->addMockViewToSubject();
133  $this->contentObjectRenderer
134  ->expects($this->any())
135  ->method('stdWrap')
136  ->with('foo', array('bar' => 'baz'));
137  $this->subject->render(array('file' => 'foo', 'file.' => array('bar' => 'baz')));
138  }
139 
143  public function renderSetsTemplateFileInView() {
144  $this->addMockViewToSubject();
146  $templateService = $GLOBALS['TSFE']->tmpl;
147  $templateService
148  ->expects($this->any())
149  ->method('getFileName')
150  ->with('foo')
151  ->will($this->returnValue('bar'));
152  $this->standaloneView
153  ->expects($this->any())
154  ->method('setTemplatePathAndFilename')
155  ->with(PATH_site . 'bar');
156  $this->subject->render(array('file' => 'foo'));
157  }
158 
163  $this->addMockViewToSubject();
164 
165  $this->contentObjectRenderer
166  ->expects($this->any())
167  ->method('cObjGetSingle')
168  ->with('FILE', array('file' => PATH_site . 'foo/bar.html'))
169  ->will($this->returnValue('baz'));
170 
171  $this->standaloneView
172  ->expects($this->any())
173  ->method('setTemplateSource')
174  ->with('baz');
175 
176  $this->subject->render(array(
177  'template' => 'FILE',
178  'template.' => array(
179  'file' => PATH_site . 'foo/bar.html'
180  )
181  ));
182  }
183 
187  public function renderSetsLayoutRootPathInView() {
188  $this->addMockViewToSubject();
189  $this->standaloneView
190  ->expects($this->once())
191  ->method('setLayoutRootPaths')
192  ->with(array(PATH_site . 'foo/bar.html'));
193  $this->subject->render(array('layoutRootPath' => 'foo/bar.html'));
194  }
195 
200  $this->addMockViewToSubject();
201  $this->contentObjectRenderer
202  ->expects($this->once())
203  ->method('stdWrap')
204  ->with('foo', array('bar' => 'baz'));
205  $this->subject->render(array('layoutRootPath' => 'foo', 'layoutRootPath.' => array('bar' => 'baz')));
206  }
207 
212  $this->addMockViewToSubject();
213  $this->contentObjectRenderer
214  ->expects($this->at(0))
215  ->method('stdWrap')
216  ->with('', array('field' => 'someField'));
217  $this->subject->render(
218  array(
219  'layoutRootPaths.' => array(
220  '10.' => array(
221  'field' => 'someField',
222  ),
223  20 => 'foo/bar2.html',
224  )
225  )
226  );
227  }
228 
233  $this->addMockViewToSubject();
234  $this->standaloneView
235  ->expects($this->once())
236  ->method('setLayoutRootPaths')
237  ->with(array(10 => PATH_site . 'foo/bar.html', 20 => PATH_site . 'foo/bar2.html'));
238  $this->subject->render(array('layoutRootPaths.' => array(10 => 'foo/bar.html', 20 => 'foo/bar2.html')));
239  }
240 
245  $this->addMockViewToSubject();
246  $this->standaloneView
247  ->expects($this->once())
248  ->method('setLayoutRootPaths')
249  ->with(array(0 => PATH_site . 'foo/main.html', 10 => PATH_site . 'foo/bar.html', 20 => PATH_site . 'foo/bar2.html'));
250  $this->subject->render(array('layoutRootPath' => 'foo/main.html', 'layoutRootPaths.' => array(10 => 'foo/bar.html', 20 => 'foo/bar2.html')));
251  }
252 
257  $this->addMockViewToSubject();
258  $this->standaloneView
259  ->expects($this->once())
260  ->method('setPartialRootPaths')
261  ->with(array(PATH_site . 'foo/bar.html'));
262  $this->subject->render(array('partialRootPath' => 'foo/bar.html'));
263  }
264 
269  $this->addMockViewToSubject();
270  $this->contentObjectRenderer
271  ->expects($this->at(0))
272  ->method('stdWrap')
273  ->with('foo/', array('wrap' => '|bar.html'));
274  $this->subject->render(
275  array(
276  'partialRootPaths.' => array(
277  10 => 'foo/',
278  '10.' => array(
279  'wrap' => '|bar.html',
280  ),
281  20 => 'foo/bar2.html',
282  )
283  )
284  );
285  }
286 
291  $this->addMockViewToSubject();
292  $this->contentObjectRenderer
293  ->expects($this->once())
294  ->method('stdWrap')
295  ->with('foo', array('bar' => 'baz'));
296  $this->subject->render(array('partialRootPath' => 'foo', 'partialRootPath.' => array('bar' => 'baz')));
297  }
298 
299 
304  $this->addMockViewToSubject();
305  $this->standaloneView
306  ->expects($this->once())
307  ->method('setPartialRootPaths')
308  ->with(array(10 => PATH_site . 'foo', 20 => PATH_site . 'bar'));
309  $this->subject->render(array('partialRootPaths.' => array(10 => 'foo', 20 => 'bar')));
310  }
311 
316  $this->addMockViewToSubject();
317  $this->standaloneView
318  ->expects($this->once())
319  ->method('setPartialRootPaths')
320  ->with(array(0 => PATH_site . 'main', 10 => PATH_site . 'foo', 20 => PATH_site . 'bar'));
321  $this->subject->render(array('partialRootPath' => 'main', 'partialRootPaths.' => array(10 => 'foo', 20 => 'bar')));
322  }
323 
327  public function renderSetsFormatInView() {
328  $this->addMockViewToSubject();
329  $this->standaloneView
330  ->expects($this->once())
331  ->method('setFormat')
332  ->with('xml');
333  $this->subject->render(array('format' => 'xml'));
334  }
335 
340  $this->addMockViewToSubject();
341  $this->contentObjectRenderer
342  ->expects($this->once())
343  ->method('stdWrap')
344  ->with('foo', array('bar' => 'baz'));
345  $this->subject->render(array('format' => 'foo', 'format.' => array('bar' => 'baz')));
346  }
347 
352  $this->addMockViewToSubject();
353  $this->request
354  ->expects($this->once())
355  ->method('setPluginName')
356  ->with('foo');
357  $configuration = array(
358  'extbase.' => array(
359  'pluginName' => 'foo',
360  ),
361  );
362  $this->subject->render($configuration);
363  }
364 
369  $this->addMockViewToSubject();
370  $this->contentObjectRenderer
371  ->expects($this->once())
372  ->method('stdWrap')
373  ->with('foo', array('bar' => 'baz'));
374  $configuration = array(
375  'extbase.' => array(
376  'pluginName' => 'foo',
377  'pluginName.' => array(
378  'bar' => 'baz',
379  ),
380  ),
381  );
382  $this->subject->render($configuration);
383  }
384 
389  $this->addMockViewToSubject();
390  $this->request
391  ->expects($this->once())
392  ->method('setControllerExtensionName')
393  ->with('foo');
394  $configuration = array(
395  'extbase.' => array(
396  'controllerExtensionName' => 'foo',
397  ),
398  );
399  $this->subject->render($configuration);
400  }
401 
406  $this->addMockViewToSubject();
407  $this->contentObjectRenderer
408  ->expects($this->once())
409  ->method('stdWrap')
410  ->with('foo', array('bar' => 'baz'));
411  $configuration = array(
412  'extbase.' => array(
413  'controllerExtensionName' => 'foo',
414  'controllerExtensionName.' => array(
415  'bar' => 'baz',
416  ),
417  ),
418  );
419  $this->subject->render($configuration);
420  }
421 
426  $this->addMockViewToSubject();
427  $this->request
428  ->expects($this->once())
429  ->method('setControllerName')
430  ->with('foo');
431  $configuration = array(
432  'extbase.' => array(
433  'controllerName' => 'foo',
434  ),
435  );
436  $this->subject->render($configuration);
437  }
438 
443  $this->addMockViewToSubject();
444  $this->contentObjectRenderer
445  ->expects($this->once())
446  ->method('stdWrap')
447  ->with('foo', array('bar' => 'baz'));
448  $configuration = array(
449  'extbase.' => array(
450  'controllerName' => 'foo',
451  'controllerName.' => array(
452  'bar' => 'baz',
453  ),
454  ),
455  );
456  $this->subject->render($configuration);
457  }
458 
463  $this->addMockViewToSubject();
464  $this->request
465  ->expects($this->once())
466  ->method('setControllerActionName')
467  ->with('foo');
468  $configuration = array(
469  'extbase.' => array(
470  'controllerActionName' => 'foo',
471  ),
472  );
473  $this->subject->render($configuration);
474  }
475 
480  $this->addMockViewToSubject();
481  $this->contentObjectRenderer
482  ->expects($this->once())
483  ->method('stdWrap')
484  ->with('foo', array('bar' => 'baz'));
485  $configuration = array(
486  'extbase.' => array(
487  'controllerActionName' => 'foo',
488  'controllerActionName.' => array(
489  'bar' => 'baz',
490  ),
491  ),
492  );
493  $this->subject->render($configuration);
494  }
495 
500  $this->addMockViewToSubject();
501 
502  $configuration = array(
503  'settings.' => array(
504  'foo' => 'value',
505  'bar.' => array(
506  'baz' => 'value2',
507  ),
508  ),
509  );
510 
511  $expectedSettingsToBeSet = array(
512  'foo' => 'value',
513  'bar' => array(
514  'baz' => 'value2',
515  ),
516  );
517 
518  $typoScriptServiceMock = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
519  $typoScriptServiceMock
520  ->expects($this->once())
521  ->method('convertTypoScriptArrayToPlainArray')
522  ->with($configuration['settings.'])
523  ->will($this->returnValue($expectedSettingsToBeSet));
524  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService', $typoScriptServiceMock);
525 
526  $this->standaloneView
527  ->expects($this->at(1))
528  ->method('assign')
529  ->with('settings', $expectedSettingsToBeSet);
530 
531  $this->subject->render($configuration);
532  }
533 
539  $this->addMockViewToSubject();
540  $configuration = array(
541  'variables.' => array(
542  'data' => 'foo',
543  'data.' => array(
544  'bar' => 'baz',
545  ),
546  ),
547  );
548  $this->subject->render($configuration);
549  }
550 
556  $this->addMockViewToSubject();
557  $configuration = array(
558  'variables.' => array(
559  'current' => 'foo',
560  'current.' => array(
561  'bar' => 'baz',
562  ),
563  ),
564  );
565  $this->subject->render($configuration);
566  }
567 
572  $this->addMockViewToSubject();
573  $configuration = array(
574  'variables.' => array(
575  'aVar' => 'TEXT',
576  'aVar.' => array(
577  'value' => 'foo',
578  ),
579  ),
580  );
581  $this->contentObjectRenderer
582  ->expects($this->once())
583  ->method('cObjGetSingle')
584  ->with('TEXT', array('value' => 'foo'));
585  $this->subject->render($configuration);
586  }
587 
592  $this->addMockViewToSubject();
593  $configuration = array(
594  'variables.' => array(
595  'aVar' => 'TEXT',
596  'aVar.' => array(
597  'value' => 'foo',
598  ),
599  ),
600  );
601  $this->contentObjectRenderer
602  ->expects($this->once())
603  ->method('cObjGetSingle')
604  ->will($this->returnValue('foo'));
605  $this->standaloneView
606  ->expects($this->at(1))
607  ->method('assign')
608  ->with('aVar', 'foo');
609  $this->subject->render($configuration);
610  }
611 
616  $this->addMockViewToSubject();
617  $this->contentObjectRenderer->data = array('foo');
618  $this->standaloneView
619  ->expects($this->at(1))
620  ->method('assign')
621  ->with('data', array('foo'));
622  $this->subject->render(array());
623  }
624 
629  $this->addMockViewToSubject();
630  $this->contentObjectRenderer->data = array('currentKey' => 'currentValue');
631  $this->contentObjectRenderer->currentValKey= 'currentKey';
632  $this->standaloneView
633  ->expects($this->at(2))
634  ->method('assign')
635  ->with('current', 'currentValue');
636  $this->subject->render(array());
637  }
638 
643  $this->addMockViewToSubject();
644  $this->standaloneView
645  ->expects($this->once())
646  ->method('render');
647  $this->subject->render(array());
648  }
649 
654  $this->addMockViewToSubject();
655  $configuration = array(
656  'stdWrap.' => array(
657  'foo' => 'bar',
658  ),
659  );
660  $this->standaloneView
661  ->expects($this->any())
662  ->method('render')
663  ->will($this->returnValue('baz'));
664  $this->contentObjectRenderer
665  ->expects($this->once())
666  ->method('stdWrap')
667  ->with('baz', array('foo' => 'bar'));
668  $this->subject->render($configuration);
669  }
670 }
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]