‪TYPO3CMS  11.5
TemplatePathsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪TemplatePathsTest extends UnitTestCase
28 {
32  public function ‪getPathSetterMethodTestValues(): array
33  {
34  $generator = static function ($method, $indexType = 'numeric') {
35  switch ($indexType) {
36  default:
37  case 'numeric':
38  $set = [
39  20 => 'bar',
40  0 => 'baz',
41  100 => 'boz',
42  10 => 'foo',
43  ];
44  $expected = [
45  0 => 'baz',
46  10 => 'foo',
47  20 => 'bar',
48  100 => 'boz',
49  ];
50  break;
51  case 'alpha':
52  $set = [
53  'bcd' => 'bar',
54  'abc' => 'foo',
55  ];
56  $expected = [
57  'bcd' => 'bar',
58  'abc' => 'foo',
59  ];
60  break;
61  case 'alphanumeric':
62  $set = [
63  0 => 'baz',
64  'bcd' => 'bar',
65  15 => 'boz',
66  'abc' => 'foo',
67  ];
68  $expected = [
69  0 => 'baz',
70  'bcd' => 'bar',
71  15 => 'boz',
72  'abc' => 'foo',
73  ];
74  break;
75  }
76  return [$method, $set, $expected];
77  };
78  return [
79  'simple numeric index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'numeric'),
80  'alpha index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'alpha'),
81  'alpha-numeric index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'alphanumeric'),
82  'simple numeric index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'numeric'),
83  'alpha index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'alpha'),
84  'alpha-numeric index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'alphanumeric'),
85  'simple numeric index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'numeric'),
86  'alpha index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'alpha'),
87  'alpha-numeric index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'alphanumeric'),
88  ];
89  }
90 
98  public function ‪pathSetterMethodSortsPathsByKeyDescending($method, array $paths, array $expected): void
99  {
100  $setter = 'set' . ucfirst($method);
101  $getter = 'get' . ucfirst($method);
102  $subject = $this->getMockBuilder(TemplatePaths::class)->onlyMethods(['sanitizePath'])->getMock();
103  $subject->method('sanitizePath')->willReturnArgument(0);
104  $subject->$setter($paths);
105  self::assertEquals($expected, $subject->$getter());
106  }
107 
112  {
113  $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
114  $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([
115  'plugin.' => [
116  'tx_test.' => [
117  'view.' => [
118  'templateRootPaths.' => [
119  '30' => 'third',
120  '10' => 'first',
121  '20' => 'second',
122  ],
123  'partialRootPaths.' => [
124  '20' => '2',
125  '30' => '3',
126  '10' => '1',
127  ],
128  'layoutRootPaths.' => [
129  '130' => '3.',
130  '10' => '1.',
131  '120' => '2.',
132  ],
133  ],
134  ],
135  ],
136  ]);
137  $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode']);
138  $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
139  $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager);
140  $subject->expects(self::once())->method('isBackendMode')->willReturn(false);
141  $subject->expects(self::once())->method('isFrontendMode')->willReturn(true);
142  $result = $subject->_call('getContextSpecificViewConfiguration', 'test');
143  self::assertSame([
144  'templateRootPaths' => [
145  'test/Templates/',
146  'first',
147  'second',
148  'third',
149  ],
150  'partialRootPaths' => [
151  'test/Partials/',
152  '1',
153  '2',
154  '3',
155  ],
156  'layoutRootPaths' => [
157  'test/Layouts/',
158  '1.',
159  '2.',
160  '3.',
161  ],
162  ], $result);
163  }
164 
169  {
170  $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
171  $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([
172  'module.' => [
173  'tx_test.' => [
174  'view.' => [
175  'templateRootPaths.' => [
176  '30' => 'third',
177  '10' => 'first',
178  '20' => 'second',
179  ],
180  'partialRootPaths.' => [
181  '20' => '2',
182  '30' => '3',
183  '10' => '1',
184  ],
185  'layoutRootPaths.' => [
186  '130' => '3.',
187  '10' => '1.',
188  '120' => '2.',
189  ],
190  ],
191  ],
192  ],
193  ]);
194  $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode']);
195  $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
196  $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager);
197  $subject->expects(self::once())->method('isBackendMode')->willReturn(true);
198  $subject->expects(self::never())->method('isFrontendMode');
199  $result = $subject->_call('getContextSpecificViewConfiguration', 'test');
200  self::assertSame([
201  'templateRootPaths' => [
202  'test/Templates/',
203  'first',
204  'second',
205  'third',
206  ],
207  'partialRootPaths' => [
208  'test/Partials/',
209  '1',
210  '2',
211  '3',
212  ],
213  'layoutRootPaths' => [
214  'test/Layouts/',
215  '1.',
216  '2.',
217  '3.',
218  ],
219  ], $result);
220  }
221 
226  {
227  $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
228  $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([
229  'plugin.' => [
230  'tx_test.' => [
231  'view.' => [
232  'templateRootPaths.' => [
233  '30' => 'third',
234  '10' => 'first',
235  '20' => 'second',
236  ],
237  'partialRootPaths.' => [
238  '20' => '2',
239  '30' => '3',
240  '10' => '1',
241  ],
242  'layoutRootPaths.' => [
243  '130' => '3.',
244  '10' => '1.',
245  '120' => '2.',
246  ],
247  ],
248  ],
249  ],
250  ]);
251  $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode']);
252  $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
253  $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager);
254  $subject->expects(self::once())->method('isBackendMode')->willReturn(false);
255  $subject->expects(self::once())->method('isFrontendMode')->willReturn(false);
256  $result = $subject->_call('getContextSpecificViewConfiguration', 'test');
257  self::assertSame([
258  'templateRootPaths' => [
259  'test/Templates/',
260  ],
261  'partialRootPaths' => [
262  'test/Partials/',
263  ],
264  'layoutRootPaths' => [
265  'test/Layouts/',
266  ],
267  ], $result);
268  }
269 
274  {
275  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
276  $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([
277  'plugin.' => [
278  'tx_test.' => [
279  'view.' => [
280  'templateRootPaths.' => [
281  '0' => 'base/Templates/',
282  '10' => 'test/Templates/',
283  ],
284  'partialRootPaths.' => [
285  '0' => 'base/Partials/',
286  '10' => 'test/Partials/',
287  ],
288  'layoutRootPaths.' => [
289  '0' => 'base/Layouts/',
290  '10' => 'test/Layouts/',
291  ],
292  ],
293  ],
294  ],
295  ]);
296  $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'isBackendMode', 'isFrontendMode']);
297  $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
298  $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager);
299  $subject->expects(self::once())->method('isBackendMode')->willReturn(false);
300  $subject->expects(self::once())->method('isFrontendMode')->willReturn(true);
301  $result = $subject->_call('getContextSpecificViewConfiguration', 'test');
302  self::assertSame([
303  'templateRootPaths' => [
304  'base/Templates/',
305  'test/Templates/',
306  ],
307  'partialRootPaths' => [
308  'base/Partials/',
309  'test/Partials/',
310  ],
311  'layoutRootPaths' => [
312  'base/Layouts/',
313  'test/Layouts/',
314  ],
315  ], $result);
316  }
317 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInBackendMode
‪getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInBackendMode()
Definition: TemplatePathsTest.php:168
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\pathSetterMethodSortsPathsByKeyDescending
‪pathSetterMethodSortsPathsByKeyDescending($method, array $paths, array $expected)
Definition: TemplatePathsTest.php:98
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationRespectsTypoScriptConfiguredPaths
‪getContextSpecificViewConfigurationRespectsTypoScriptConfiguredPaths()
Definition: TemplatePathsTest.php:273
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest
Definition: TemplatePathsTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationDoesNotResolveFromTypoScriptAndDoesNotSortInUnspecifiedMode
‪getContextSpecificViewConfigurationDoesNotResolveFromTypoScriptAndDoesNotSortInUnspecifiedMode()
Definition: TemplatePathsTest.php:225
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getPathSetterMethodTestValues
‪array getPathSetterMethodTestValues()
Definition: TemplatePathsTest.php:32
‪TYPO3\CMS\Fluid\Tests\Unit\View
Definition: AbstractTemplateViewTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInFrontendMode
‪getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInFrontendMode()
Definition: TemplatePathsTest.php:111