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