TYPO3 CMS  TYPO3_6-2
TemplateViewTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
14 include_once(__DIR__ . '/Fixtures/TransparentSyntaxTreeNode.php');
15 include_once(__DIR__ . '/Fixtures/TemplateViewFixture.php');
16 
20 
25 
32  $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'ViewHelpers_Widget', 'Paginate', 'html');
33  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
34  $templateView->_set('controllerContext', $mockControllerContext);
35  $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
36  $expected = array(ExtensionManagementUtility::extPath('frontend') . 'Resources/Private/Templates/ViewHelpers/Widget/Paginate/@action.html');
37  $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE);
38  $this->assertEquals($expected, $actual);
39  }
40 
47  $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'ViewHelpers\\Widget', 'Paginate', 'html');
48  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
49  $templateView->_set('controllerContext', $mockControllerContext);
50  $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
51  $expected = array(ExtensionManagementUtility::extPath('frontend') . 'Resources/Private/Templates/ViewHelpers/Widget/Paginate/@action.html');
52  $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE);
53  $this->assertEquals($expected, $actual);
54  }
55 
65  protected function setupMockControllerContextForPathResolving($packageKey, $subPackageKey, $controllerName, $format) {
66  $controllerObjectName = "TYPO3\\$packageKey\\" . ($subPackageKey != $subPackageKey . '\\' ? : '') . 'Controller\\' . $controllerName . 'Controller';
67  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
68  $mockRequest->expects($this->any())->method('getControllerExtensionKey')->will($this->returnValue('frontend'));
69  $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue($packageKey));
70  $mockRequest->expects($this->any())->method('getControllerSubPackageKey')->will($this->returnValue($subPackageKey));
71  $mockRequest->expects($this->any())->method('getControllerName')->will($this->returnValue($controllerName));
72  $mockRequest->expects($this->any())->method('getControllerObjectName')->will($this->returnValue($controllerObjectName));
73  $mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue($format));
74 
75  $mockControllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array('getRequest'), array(), '', FALSE);
76  $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest));
77 
78  return $mockControllerContext;
79  }
80 
82  return array(
83  // bubbling controller & subpackage parts and optional format
84  array(
85  'package' => 'Some.Package',
86  'subPackage' => 'Some\\Sub\\Package',
87  'controller' => 'SomeController',
88  'format' => 'html',
89  'templateRootPath' => 'Resources/Private/Templates',
90  'templateRootPaths' => NULL,
91  'partialRootPath' => 'Resources/Private/Partials',
92  'partialRootPaths' => NULL,
93  'layoutRootPath' => 'Resources/Private/Layouts',
94  'layoutRootPaths' => NULL,
95  'bubbleControllerAndSubpackage' => TRUE,
96  'formatIsOptional' => TRUE,
97  'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
98  'expectedResult' => array(
99  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
100  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
101  'Resources/Private/Templates/Some/Sub/Package/@action.html',
102  'Resources/Private/Templates/Some/Sub/Package/@action',
103  'Resources/Private/Templates/Sub/Package/@action.html',
104  'Resources/Private/Templates/Sub/Package/@action',
105  'Resources/Private/Templates/Package/@action.html',
106  'Resources/Private/Templates/Package/@action',
107  'Resources/Private/Templates/@action.html',
108  'Resources/Private/Templates/@action',
109  )
110  ),
111  // just optional format
112  array(
113  'package' => 'Some.Package',
114  'subPackage' => 'Some\\Sub\\Package',
115  'controller' => 'SomeController',
116  'format' => 'html',
117  'templateRootPath' => 'Resources/Private/Templates/',
118  'templateRootPaths' => NULL,
119  'partialRootPath' => 'Resources/Private/Partials',
120  'partialRootPaths' => NULL,
121  'layoutRootPath' => 'Resources/Private/Layouts',
122  'layoutRootPaths' => NULL,
123  'bubbleControllerAndSubpackage' => FALSE,
124  'formatIsOptional' => TRUE,
125  'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
126  'expectedResult' => array(
127  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
128  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
129  )
130  ),
131  // just bubbling controller & subpackage parts
132  array(
133  'package' => 'Some.Package',
134  'subPackage' => 'Some\\Sub\\Package',
135  'controller' => 'SomeController',
136  'format' => 'json',
137  'templateRootPath' => 'Resources/Private/Templates',
138  'templateRootPaths' => NULL,
139  'partialRootPath' => 'Resources/Private/Partials',
140  'partialRootPaths' => NULL,
141  'layoutRootPath' => 'Resources/Private/Layouts',
142  'layoutRootPaths' => NULL,
143  'bubbleControllerAndSubpackage' => TRUE,
144  'formatIsOptional' => FALSE,
145  'pattern' => '@partialRoot/@subpackage/@controller/@action.@format',
146  'expectedResult' => array(
147  'Resources/Private/Partials/Some/Sub/Package/SomeController/@action.json',
148  'Resources/Private/Partials/Some/Sub/Package/@action.json',
149  'Resources/Private/Partials/Sub/Package/@action.json',
150  'Resources/Private/Partials/Package/@action.json',
151  'Resources/Private/Partials/@action.json',
152  )
153  ),
154  // layoutRootPath
155  array(
156  'package' => 'Some.Package',
157  'subPackage' => NULL,
158  'controller' => NULL,
159  'format' => 'xml',
160  'templateRootPath' => 'Resources/Private/Templates',
161  'templateRootPaths' => NULL,
162  'partialRootPath' => 'Resources/Private/Partials',
163  'partialRootPaths' => NULL,
164  'layoutRootPath' => 'Resources/Private/Layouts',
165  'layoutRootPaths' => NULL,
166  'bubbleControllerAndSubpackage' => TRUE,
167  'formatIsOptional' => TRUE,
168  'pattern' => '@layoutRoot/@subpackage/@controller/@action.@format',
169  'expectedResult' => array(
170  'Resources/Private/Layouts/@action.xml',
171  'Resources/Private/Layouts/@action',
172  )
173  ),
174  // partialRootPath
175  array(
176  'package' => 'Some.Package',
177  'subPackage' => 'Some\\Sub\\Package',
178  'controller' => NULL,
179  'format' => 'html',
180  'templateRootPath' => 'Resources/Private/Templates',
181  'templateRootPaths' => NULL,
182  'partialRootPath' => 'Resources/Private/Partials',
183  'partialRootPaths' => NULL,
184  'layoutRootPath' => 'Resources/Private/Layouts',
185  'layoutRootPaths' => NULL,
186  'bubbleControllerAndSubpackage' => TRUE,
187  'formatIsOptional' => TRUE,
188  'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
189  'expectedResult' => array(
190  'Resources/Private/Templates/Some/Sub/Package/@action.html',
191  'Resources/Private/Templates/Some/Sub/Package/@action',
192  'Resources/Private/Templates/Sub/Package/@action.html',
193  'Resources/Private/Templates/Sub/Package/@action',
194  'Resources/Private/Templates/Package/@action.html',
195  'Resources/Private/Templates/Package/@action',
196  'Resources/Private/Templates/@action.html',
197  'Resources/Private/Templates/@action',
198  )
199  ),
200  // optional format as directory name
201  array(
202  'package' => 'Some.Package',
203  'subPackage' => 'Some\\Sub\\Package',
204  'controller' => 'SomeController',
205  'format' => 'xml',
206  'templateRootPath' => 'Resources/Private/Templates_@format',
207  'templateRootPaths' => NULL,
208  'partialRootPath' => 'Resources/Private/Partials',
209  'partialRootPaths' => NULL,
210  'layoutRootPath' => 'Resources/Private/Layouts',
211  'layoutRootPaths' => NULL,
212  'bubbleControllerAndSubpackage' => FALSE,
213  'formatIsOptional' => TRUE,
214  'pattern' => '@templateRoot/@subpackage/@controller/@action',
215  'expectedResult' => array(
216  'Resources/Private/Templates_xml/Some/Sub/Package/SomeController/@action',
217  'Resources/Private/Templates_/Some/Sub/Package/SomeController/@action',
218  )
219  ),
220  // mandatory format as directory name
221  array(
222  'package' => 'Some.Package',
223  'subPackage' => 'Some\\Sub\\Package',
224  'controller' => 'SomeController',
225  'format' => 'json',
226  'templateRootPath' => 'Resources/Private/Templates_@format',
227  'templateRootPaths' => NULL,
228  'partialRootPath' => 'Resources/Private/Partials',
229  'partialRootPaths' => NULL,
230  'layoutRootPath' => 'Resources/Private/Layouts',
231  'layoutRootPaths' => NULL,
232  'bubbleControllerAndSubpackage' => FALSE,
233  'formatIsOptional' => FALSE,
234  'pattern' => '@templateRoot/@subpackage/@controller/@action',
235  'expectedResult' => array(
236  'Resources/Private/Templates_json/Some/Sub/Package/SomeController/@action',
237  )
238  ),
239  // paths must not contain double slashes
240  array(
241  'package' => 'Some.Package',
242  'subPackage' => NULL,
243  'controller' => 'SomeController',
244  'format' => 'html',
245  'templateRootPath' => 'Resources/Private/Templates',
246  'templateRootPaths' => NULL,
247  'partialRootPath' => 'Resources/Private/Partials',
248  'partialRootPaths' => NULL,
249  'layoutRootPath' => 'Some/Root/Path/',
250  'layoutRootPaths' => NULL,
251  'bubbleControllerAndSubpackage' => TRUE,
252  'formatIsOptional' => TRUE,
253  'pattern' => '@layoutRoot/@subpackage/@controller/@action.@format',
254  'expectedResult' => array(
255  'Some/Root/Path/SomeController/@action.html',
256  'Some/Root/Path/SomeController/@action',
257  'Some/Root/Path/@action.html',
258  'Some/Root/Path/@action',
259  )
260  ),
261  // paths must be unique
262  array(
263  'package' => 'Some.Package',
264  'subPackage' => 'Some\\Sub\\Package',
265  'controller' => 'SomeController',
266  'format' => 'json',
267  'templateRootPath' => 'Resources/Private/Templates',
268  'templateRootPaths' => NULL,
269  'partialRootPath' => 'Resources/Private/Partials',
270  'partialRootPaths' => NULL,
271  'layoutRootPath' => 'Resources/Private/Layouts',
272  'layoutRootPaths' => NULL,
273  'bubbleControllerAndSubpackage' => TRUE,
274  'formatIsOptional' => FALSE,
275  'pattern' => 'foo',
276  'expectedResult' => array(
277  'foo',
278  )
279  ),
280  // template fallback paths
281  array(
282  'package' => 'Some.Package',
283  'subPackage' => 'Some\\Sub\\Package',
284  'controller' => 'SomeController',
285  'format' => 'html',
286  'templateRootPath' => 'Resources/Private/Templates',
287  'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
288  'partialRootPath' => 'Resources/Private/Partials',
289  'partialRootPaths' => NULL,
290  'layoutRootPath' => 'Resources/Private/Layouts',
291  'layoutRootPaths' => NULL,
292  'bubbleControllerAndSubpackage' => FALSE,
293  'formatIsOptional' => TRUE,
294  'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
295  'expectedResult' => array(
296  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
297  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
298  'Some/Fallback/Path/Some/Sub/Package/SomeController/@action.html',
299  'Some/Fallback/Path/Some/Sub/Package/SomeController/@action',
300  )
301  ),
302  // template fallback paths with bubbleControllerAndSubpackage
303  array(
304  'package' => 'Some.Package',
305  'subPackage' => 'Some\\Sub\\Package',
306  'controller' => 'SomeController',
307  'format' => 'html',
308  'templateRootPath' => 'Resources/Private/Templates',
309  'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
310  'partialRootPath' => 'Resources/Private/Partials',
311  'partialRootPaths' => NULL,
312  'layoutRootPath' => 'Resources/Private/Layouts',
313  'layoutRootPaths' => NULL,
314  'bubbleControllerAndSubpackage' => TRUE,
315  'formatIsOptional' => FALSE,
316  'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
317  'expectedResult' => array(
318  'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
319  'Resources/Private/Templates/Some/Sub/Package/@action.html',
320  'Resources/Private/Templates/Sub/Package/@action.html',
321  'Resources/Private/Templates/Package/@action.html',
322  'Resources/Private/Templates/@action.html',
323  'Some/Fallback/Path/Some/Sub/Package/SomeController/@action.html',
324  'Some/Fallback/Path/Some/Sub/Package/@action.html',
325  'Some/Fallback/Path/Sub/Package/@action.html',
326  'Some/Fallback/Path/Package/@action.html',
327  'Some/Fallback/Path/@action.html',
328  )
329  ),
330  // partial fallback paths
331  array(
332  'package' => 'Some.Package',
333  'subPackage' => 'Some\\Sub\\Package',
334  'controller' => 'SomeController',
335  'format' => 'html',
336  'templateRootPath' => 'Resources/Private/Templates',
337  'templateRootPaths' => NULL,
338  'partialRootPath' => 'Resources/Private/Partials',
339  'partialRootPaths' => array('Default/Resources/Path', 'Fallback/'),
340  'layoutRootPath' => 'Resources/Private/Layouts',
341  'layoutRootPaths' => NULL,
342  'bubbleControllerAndSubpackage' => FALSE,
343  'formatIsOptional' => TRUE,
344  'pattern' => '@partialRoot/@subpackage/@controller/@partial.@format',
345  'expectedResult' => array(
346  'Default/Resources/Path/Some/Sub/Package/SomeController/@partial.html',
347  'Default/Resources/Path/Some/Sub/Package/SomeController/@partial',
348  'Fallback/Some/Sub/Package/SomeController/@partial.html',
349  'Fallback/Some/Sub/Package/SomeController/@partial',
350  )
351  ),
352  // partial fallback paths with bubbleControllerAndSubpackage
353  array(
354  'package' => 'Some.Package',
355  'subPackage' => 'Some\\Sub\\Package',
356  'controller' => 'SomeController',
357  'format' => 'html',
358  'templateRootPath' => 'Resources/Private/Templates',
359  'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
360  'partialRootPath' => 'Resources/Private/Partials',
361  'partialRootPaths' => array('Default/Resources/Path', 'Fallback1/', 'Fallback2'),
362  'layoutRootPath' => 'Resources/Private/Layouts',
363  'layoutRootPaths' => NULL,
364  'bubbleControllerAndSubpackage' => TRUE,
365  'formatIsOptional' => TRUE,
366  'pattern' => '@partialRoot/@controller/@subpackage/@partial',
367  'expectedResult' => array(
368  'Default/Resources/Path/SomeController/Some/Sub/Package/@partial',
369  'Default/Resources/Path/Some/Sub/Package/@partial',
370  'Default/Resources/Path/Sub/Package/@partial',
371  'Default/Resources/Path/Package/@partial',
372  'Default/Resources/Path/@partial',
373  'Fallback1/SomeController/Some/Sub/Package/@partial',
374  'Fallback1/Some/Sub/Package/@partial',
375  'Fallback1/Sub/Package/@partial',
376  'Fallback1/Package/@partial',
377  'Fallback1/@partial',
378  'Fallback2/SomeController/Some/Sub/Package/@partial',
379  'Fallback2/Some/Sub/Package/@partial',
380  'Fallback2/Sub/Package/@partial',
381  'Fallback2/Package/@partial',
382  'Fallback2/@partial',
383  )
384  ),
385  // layout fallback paths
386  array(
387  'package' => 'Some.Package',
388  'subPackage' => 'Some\\Sub\\Package',
389  'controller' => 'SomeController',
390  'format' => 'html',
391  'templateRootPath' => 'Resources/Private/Templates',
392  'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
393  'partialRootPath' => 'Resources/Private/Partials',
394  'partialRootPaths' => array('foo', 'bar'),
395  'layoutRootPath' => 'Resources/Private/Layouts',
396  'layoutRootPaths' => array('Default/Layout/Path', 'Fallback/Path'),
397  'bubbleControllerAndSubpackage' => FALSE,
398  'formatIsOptional' => FALSE,
399  'pattern' => '@layoutRoot/@subpackage/@controller/@layout.@format',
400  'expectedResult' => array(
401  'Default/Layout/Path/Some/Sub/Package/SomeController/@layout.html',
402  'Fallback/Path/Some/Sub/Package/SomeController/@layout.html',
403  )
404  ),
405  // layout fallback paths with bubbleControllerAndSubpackage
406  array(
407  'package' => 'Some.Package',
408  'subPackage' => 'Some\\Sub\\Package',
409  'controller' => 'SomeController',
410  'format' => 'html',
411  'templateRootPath' => 'Resources/Private/Templates',
412  'templateRootPaths' => NULL,
413  'partialRootPath' => 'Resources/Private/Partials',
414  'partialRootPaths' => NULL,
415  'layoutRootPath' => 'Resources/Private/Layouts',
416  'layoutRootPaths' => array('Resources/Layouts', 'Some/Fallback/Path'),
417  'bubbleControllerAndSubpackage' => TRUE,
418  'formatIsOptional' => TRUE,
419  'pattern' => 'Static/@layoutRoot/@subpackage/@controller/@layout.@format',
420  'expectedResult' => array(
421  'Static/Resources/Layouts/Some/Sub/Package/SomeController/@layout.html',
422  'Static/Resources/Layouts/Some/Sub/Package/SomeController/@layout',
423  'Static/Resources/Layouts/Some/Sub/Package/@layout.html',
424  'Static/Resources/Layouts/Some/Sub/Package/@layout',
425  'Static/Resources/Layouts/Sub/Package/@layout.html',
426  'Static/Resources/Layouts/Sub/Package/@layout',
427  'Static/Resources/Layouts/Package/@layout.html',
428  'Static/Resources/Layouts/Package/@layout',
429  'Static/Resources/Layouts/@layout.html',
430  'Static/Resources/Layouts/@layout',
431  'Static/Some/Fallback/Path/Some/Sub/Package/SomeController/@layout.html',
432  'Static/Some/Fallback/Path/Some/Sub/Package/SomeController/@layout',
433  'Static/Some/Fallback/Path/Some/Sub/Package/@layout.html',
434  'Static/Some/Fallback/Path/Some/Sub/Package/@layout',
435  'Static/Some/Fallback/Path/Sub/Package/@layout.html',
436  'Static/Some/Fallback/Path/Sub/Package/@layout',
437  'Static/Some/Fallback/Path/Package/@layout.html',
438  'Static/Some/Fallback/Path/Package/@layout',
439  'Static/Some/Fallback/Path/@layout.html',
440  'Static/Some/Fallback/Path/@layout',
441  )
442  ),
443  // combined fallback paths
444  array(
445  'package' => 'Some.Package',
446  'subPackage' => 'Some\\Sub\\Package',
447  'controller' => 'SomeController',
448  'format' => 'html',
449  'templateRootPath' => 'Resources/Private/Templates',
450  'templateRootPaths' => array('Resources/Templates', 'Templates/Fallback1', 'Templates/Fallback2'),
451  'partialRootPath' => 'Resources/Private/Partials',
452  'partialRootPaths' => array('Resources/Partials'),
453  'layoutRootPath' => 'Resources/Private/Layouts',
454  'layoutRootPaths' => array('Resources/Layouts', 'Layouts/Fallback1'),
455  'bubbleControllerAndSubpackage' => FALSE,
456  'formatIsOptional' => TRUE,
457  'pattern' => '@layoutRoot/@templateRoot/@partialRoot/@subpackage/@controller/foo',
458  'expectedResult' => array(
459  'Resources/Layouts/Resources/Templates/Resources/Partials/Some/Sub/Package/SomeController/foo',
460  'Layouts/Fallback1/Resources/Templates/Resources/Partials/Some/Sub/Package/SomeController/foo',
461  'Resources/Layouts/Templates/Fallback1/Resources/Partials/Some/Sub/Package/SomeController/foo',
462  'Layouts/Fallback1/Templates/Fallback1/Resources/Partials/Some/Sub/Package/SomeController/foo',
463  'Resources/Layouts/Templates/Fallback2/Resources/Partials/Some/Sub/Package/SomeController/foo',
464  'Layouts/Fallback1/Templates/Fallback2/Resources/Partials/Some/Sub/Package/SomeController/foo',
465  )
466  ),
467  );
468  }
469 
489  public function expandGenericPathPatternTests($package, $subPackage, $controller, $format, $templateRootPath, array $templateRootPaths = NULL, $partialRootPath, array $partialRootPaths = NULL, $layoutRootPath, array $layoutRootPaths = NULL, $bubbleControllerAndSubpackage, $formatIsOptional, $pattern, $expectedResult) {
490  $mockControllerContext = $this->setupMockControllerContextForPathResolving($package, $subPackage, $controller, $format);
491 
493  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
494  $templateView->setControllerContext($mockControllerContext);
495  if ($templateRootPath !== NULL) {
496  $templateView->setTemplateRootPath($templateRootPath);
497  }
498  if ($templateRootPaths !== NULL) {
499  $templateView->setTemplateRootPaths($templateRootPaths);
500  }
501 
502  if ($partialRootPath !== NULL) {
503  $templateView->setPartialRootPath($partialRootPath);
504  }
505  if ($partialRootPaths !== NULL) {
506  $templateView->setPartialRootPaths($partialRootPaths);
507  }
508 
509  if ($layoutRootPath !== NULL) {
510  $templateView->setLayoutRootPath($layoutRootPath);
511  }
512  if ($layoutRootPaths !== NULL) {
513  $templateView->setLayoutRootPaths($layoutRootPaths);
514  }
515 
516  $actualResult = $templateView->_call('expandGenericPathPattern', $pattern, $bubbleControllerAndSubpackage, $formatIsOptional);
517  $this->assertEquals($expectedResult, $actualResult);
518  }
519 
524  $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', NULL, 'My', 'html');
525 
526  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
527  $templateView->_set('controllerContext', $mockControllerContext);
528  $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
529 
530  $expected = array('Resources/Private/Templates/My/@action.html');
531  $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
532  $this->assertEquals($expected, $actual);
533  }
534 
535 
540  $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
541 
542  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
543  $templateView->_set('controllerContext', $mockControllerContext);
544  $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
545  $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
546 
547  $expected = array(
548  'Resources/Private/Templates/MySubPackage/My/@action.html'
549  );
550  $this->assertEquals($expected, $actual);
551  }
552 
557  $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
558 
559  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
560  $templateView->_set('controllerContext', $mockControllerContext);
561  $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
562  $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, TRUE);
563 
564  $expected = array(
565  'Resources/Private/Templates/MySubPackage/My/@action.html',
566  'Resources/Private/Templates/MySubPackage/My/@action'
567  );
568  $this->assertEquals($expected, $actual);
569  }
570 
575  $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
576 
577  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
578  $templateView->_set('controllerContext', $mockControllerContext);
579  $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
580  $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', TRUE, TRUE);
581 
582  $expected = array(
583  'Resources/Private/Templates/MySubPackage/My/@action.html',
584  'Resources/Private/Templates/MySubPackage/My/@action',
585  'Resources/Private/Templates/MySubPackage/@action.html',
586  'Resources/Private/Templates/MySubPackage/@action',
587  'Resources/Private/Templates/@action.html',
588  'Resources/Private/Templates/@action'
589  );
590  $this->assertEquals($expected, $actual);
591  }
592 
597  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
598  $templateView->setTemplateRootPath('/foo/bar');
599  $expected = array('/foo/bar');
600  $actual = $templateView->_call('getTemplateRootPaths');
601  $this->assertEquals($expected, $actual, 'A set template root path was not returned correctly.');
602  }
603 
608  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
609  $templateView->setTemplateRootPath('/foo/bar');
610  $templateView->setTemplateRootPaths(array('/overruled/path'));
611  $expected = array('/overruled/path');
612  $actual = $templateView->_call('getTemplateRootPaths');
613  $this->assertEquals($expected, $actual, 'A set template root path was not returned correctly.');
614  }
615 
620  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
621  $templateView->setPartialRootPath('/foo/bar');
622  $expected = array('/foo/bar');
623  $actual = $templateView->_call('getPartialRootPaths');
624  $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
625  }
626 
631  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
632  $templateView->setLayoutRootPath('/foo/bar');
633  $expected = array('/foo/bar');
634  $actual = $templateView->_call('getLayoutRootPaths');
635  $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
636  }
637 
642  vfsStreamWrapper::register();
643  mkdir('vfs://MyPartials');
644  \file_put_contents('vfs://MyPartials/SomePartial', 'contentsOfSomePartial');
645 
646  $paths = array(
647  'vfs://NonExistantDir/UnknowFile.html',
648  'vfs://MyPartials/SomePartial.html',
649  'vfs://MyPartials/SomePartial'
650  );
651 
652  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('expandGenericPathPattern', 'resolveFileNamePath'), array(), '', FALSE);
653  $templateView->expects($this->once())->method('expandGenericPathPattern')->with('@partialRoot/@subpackage/@partial.@format', TRUE, TRUE)->will($this->returnValue($paths));
654  $templateView->expects($this->any())->method('resolveFileNamePath')->will($this->onConsecutiveCalls(
655  $paths[0],
656  $paths[1],
657  $paths[2]
658  ));
659 
660  $templateView->setTemplateRootPath('MyTemplates');
661  $templateView->setPartialRootPath('MyPartials');
662  $templateView->setLayoutRootPath('MyLayouts');
663 
664  $this->assertSame('contentsOfSomePartial', $templateView->_call('getPartialSource', 'SomePartial'));
665  }
666 
671  vfsStreamWrapper::register();
672  mkdir('vfs://MyTemplates');
673  \file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
674 
675  $paths = array(
676  'vfs://NonExistantDir/UnknownFile.html',
677  'vfs://MyTemplates/@action.html'
678  );
679 
680  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('expandGenericPathPattern', 'resolveFileNamePath'), array(), '', FALSE);
681  $templateView->expects($this->once())->method('expandGenericPathPattern')->with('@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE)->will($this->returnValue($paths));
682  $templateView->expects($this->any())->method('resolveFileNamePath')->will($this->onConsecutiveCalls(
683  $paths[0],
684  'vfs://MyTemplates/MyCoolAction.html'
685  ));
686 
687  $templateView->setTemplateRootPath('MyTemplates');
688  $templateView->setPartialRootPath('MyPartials');
689  $templateView->setLayoutRootPath('MyLayouts');
690 
691  $this->assertSame('contentsOfMyCoolAction', $templateView->_call('getTemplateSource', 'myCoolAction'));
692 
693  }
694 
699  vfsStreamWrapper::register();
700  mkdir('vfs://MyTemplates');
701  \file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
702 
703  $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
704  $templateView->_set('templatePathAndFilename', 'vfs://MyTemplates/MyCoolAction.html');
705 
706  $this->assertSame('contentsOfMyCoolAction', $templateView->_call('getTemplateSource'));
707  }
708 }
setupMockControllerContextForPathResolving($packageKey, $subPackageKey, $controllerName, $format)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)