[!!!][TASK] Deprecate useCacheHash/noCacheHash
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / View / TemplatePathsTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\View;
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
17 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
18 use TYPO3\CMS\Fluid\View\TemplatePaths;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class TemplatePathsTest extends UnitTestCase
25 {
26 /**
27 * @return array
28 */
29 public function getPathSetterMethodTestValues()
30 {
31 $generator = function ($method, $indexType = 'numeric') {
32 switch ($indexType) {
33 default:
34 case 'numeric':
35 $set = [
36 20 => 'bar',
37 0 => 'baz',
38 100 => 'boz',
39 10 => 'foo',
40 ];
41 $expected = [
42 0 => 'baz',
43 10 => 'foo',
44 20 => 'bar',
45 100 => 'boz',
46 ];
47 break;
48 case 'alpha':
49 $set = [
50 'bcd' => 'bar',
51 'abc' => 'foo',
52 ];
53 $expected = [
54 'bcd' => 'bar',
55 'abc' => 'foo',
56 ];
57 break;
58 case 'alphanumeric':
59 $set = [
60 0 => 'baz',
61 'bcd' => 'bar',
62 15 => 'boz',
63 'abc' => 'foo',
64 ];
65 $expected = [
66 0 => 'baz',
67 'bcd' => 'bar',
68 15 => 'boz',
69 'abc' => 'foo',
70 ];
71 break;
72 }
73 return [$method, $set, $expected];
74 };
75 return [
76 'simple numeric index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'numeric'),
77 'alpha index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'alpha'),
78 'alpha-numeric index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'alphanumeric'),
79 'simple numeric index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'numeric'),
80 'alpha index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'alpha'),
81 'alpha-numeric index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'alphanumeric'),
82 'simple numeric index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'numeric'),
83 'alpha index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'alpha'),
84 'alpha-numeric index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'alphanumeric'),
85 ];
86 }
87
88 /**
89 * @test
90 * @dataProvider getPathSetterMethodTestValues
91 * @param string $method
92 * @param array $paths
93 * @param array $expected
94 */
95 public function pathSetterMethodSortsPathsByKeyDescending($method, array $paths, array $expected)
96 {
97 $setter = 'set' . ucfirst($method);
98 $getter = 'get' . ucfirst($method);
99 $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['sanitizePath'])->getMock();
100 $subject->expects($this->any())->method('sanitizePath')->willReturnArgument(0);
101 $subject->$setter($paths);
102 $this->assertEquals($expected, $subject->$getter());
103 }
104
105 /**
106 * @test
107 */
108 public function getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInFrontendMode()
109 {
110 $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
111 $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
112 'plugin.' => [
113 'tx_test.' => [
114 'view.' => [
115 'templateRootPaths.' => [
116 '30' => 'third',
117 '10' => 'first',
118 '20' => 'second'
119 ],
120 'partialRootPaths.' => [
121 '20' => '2',
122 '30' => '3',
123 '10' => '1'
124 ],
125 'layoutRootPaths.' => [
126 '130' => '3.',
127 '10' => '1.',
128 '120' => '2.'
129 ],
130 ]
131 ]
132 ]
133 ]);
134 $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
135 $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
136 $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
137 $subject->expects($this->once())->method('isBackendMode')->willReturn(false);
138 $subject->expects($this->once())->method('isFrontendMode')->willReturn(true);
139 $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
140 $this->assertSame([
141 'templateRootPaths' => [
142 'test/Templates/',
143 'first',
144 'second',
145 'third'
146 ],
147 'partialRootPaths' => [
148 'test/Partials/',
149 '1',
150 '2',
151 '3'
152 ],
153 'layoutRootPaths' => [
154 'test/Layouts/',
155 '1.',
156 '2.',
157 '3.'
158 ]
159 ], $result);
160 }
161
162 /**
163 * @test
164 */
165 public function getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInBackendMode()
166 {
167 $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
168 $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
169 'module.' => [
170 'tx_test.' => [
171 'view.' => [
172 'templateRootPaths.' => [
173 '30' => 'third',
174 '10' => 'first',
175 '20' => 'second'
176 ],
177 'partialRootPaths.' => [
178 '20' => '2',
179 '30' => '3',
180 '10' => '1'
181 ],
182 'layoutRootPaths.' => [
183 '130' => '3.',
184 '10' => '1.',
185 '120' => '2.'
186 ],
187 ]
188 ]
189 ]
190 ]);
191 $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
192 $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
193 $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
194 $subject->expects($this->once())->method('isBackendMode')->willReturn(true);
195 $subject->expects($this->never())->method('isFrontendMode');
196 $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
197 $this->assertSame([
198 'templateRootPaths' => [
199 'test/Templates/',
200 'first',
201 'second',
202 'third'
203 ],
204 'partialRootPaths' => [
205 'test/Partials/',
206 '1',
207 '2',
208 '3'
209 ],
210 'layoutRootPaths' => [
211 'test/Layouts/',
212 '1.',
213 '2.',
214 '3.'
215 ]
216 ], $result);
217 }
218
219 /**
220 * @test
221 */
222 public function getContextSpecificViewConfigurationDoesNotResolveFromTypoScriptAndDoesNotSortInUnspecifiedMode()
223 {
224 $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
225 $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
226 'plugin.' => [
227 'tx_test.' => [
228 'view.' => [
229 'templateRootPaths.' => [
230 '30' => 'third',
231 '10' => 'first',
232 '20' => 'second'
233 ],
234 'partialRootPaths.' => [
235 '20' => '2',
236 '30' => '3',
237 '10' => '1'
238 ],
239 'layoutRootPaths.' => [
240 '130' => '3.',
241 '10' => '1.',
242 '120' => '2.'
243 ],
244 ]
245 ]
246 ]
247 ]);
248 $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
249 $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
250 $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
251 $subject->expects($this->once())->method('isBackendMode')->willReturn(false);
252 $subject->expects($this->once())->method('isFrontendMode')->willReturn(false);
253 $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
254 $this->assertSame([
255 'templateRootPaths' => [
256 'test/Templates/'
257 ],
258 'partialRootPaths' => [
259 'test/Partials/'
260 ],
261 'layoutRootPaths' => [
262 'test/Layouts/'
263 ]
264 ], $result);
265 }
266 }