‪TYPO3CMS  9.5
TemplatePathsTest.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪TemplatePathsTest extends UnitTestCase
25 {
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 
95  public function ‪pathSetterMethodSortsPathsByKeyDescending($method, array $paths, array $expected)
96  {
97  $setter = 'set' . ucfirst($method);
98  $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['sanitizePath'])->getMock();
99  $subject->expects($this->any())->method('sanitizePath')->willReturnArgument(0);
100  $subject->$setter($paths);
101  $this->assertAttributeSame($expected, $method, $subject);
102  }
103 
108  {
109  $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
110  $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
111  'plugin.' => [
112  'tx_test.' => [
113  'view.' => [
114  'templateRootPaths.' => [
115  '30' => 'third',
116  '10' => 'first',
117  '20' => 'second'
118  ],
119  'partialRootPaths.' => [
120  '20' => '2',
121  '30' => '3',
122  '10' => '1'
123  ],
124  'layoutRootPaths.' => [
125  '130' => '3.',
126  '10' => '1.',
127  '120' => '2.'
128  ],
129  ]
130  ]
131  ]
132  ]);
133  $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
134  $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
135  $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
136  $subject->expects($this->once())->method('isBackendMode')->willReturn(false);
137  $subject->expects($this->once())->method('isFrontendMode')->willReturn(true);
138  $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
139  $this->assertSame([
140  'templateRootPaths' => [
141  'test/Templates/',
142  'first',
143  'second',
144  'third'
145  ],
146  'partialRootPaths' => [
147  'test/Partials/',
148  '1',
149  '2',
150  '3'
151  ],
152  'layoutRootPaths' => [
153  'test/Layouts/',
154  '1.',
155  '2.',
156  '3.'
157  ]
158  ], $result);
159  }
160 
165  {
166  $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
167  $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
168  'module.' => [
169  'tx_test.' => [
170  'view.' => [
171  'templateRootPaths.' => [
172  '30' => 'third',
173  '10' => 'first',
174  '20' => 'second'
175  ],
176  'partialRootPaths.' => [
177  '20' => '2',
178  '30' => '3',
179  '10' => '1'
180  ],
181  'layoutRootPaths.' => [
182  '130' => '3.',
183  '10' => '1.',
184  '120' => '2.'
185  ],
186  ]
187  ]
188  ]
189  ]);
190  $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
191  $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
192  $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
193  $subject->expects($this->once())->method('isBackendMode')->willReturn(true);
194  $subject->expects($this->never())->method('isFrontendMode');
195  $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
196  $this->assertSame([
197  'templateRootPaths' => [
198  'test/Templates/',
199  'first',
200  'second',
201  'third'
202  ],
203  'partialRootPaths' => [
204  'test/Partials/',
205  '1',
206  '2',
207  '3'
208  ],
209  'layoutRootPaths' => [
210  'test/Layouts/',
211  '1.',
212  '2.',
213  '3.'
214  ]
215  ], $result);
216  }
217 
222  {
223  $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
224  $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
225  'plugin.' => [
226  'tx_test.' => [
227  'view.' => [
228  'templateRootPaths.' => [
229  '30' => 'third',
230  '10' => 'first',
231  '20' => 'second'
232  ],
233  'partialRootPaths.' => [
234  '20' => '2',
235  '30' => '3',
236  '10' => '1'
237  ],
238  'layoutRootPaths.' => [
239  '130' => '3.',
240  '10' => '1.',
241  '120' => '2.'
242  ],
243  ]
244  ]
245  ]
246  ]);
247  $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
248  $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
249  $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
250  $subject->expects($this->once())->method('isBackendMode')->willReturn(false);
251  $subject->expects($this->once())->method('isFrontendMode')->willReturn(false);
252  $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
253  $this->assertSame([
254  'templateRootPaths' => [
255  'test/Templates/'
256  ],
257  'partialRootPaths' => [
258  'test/Partials/'
259  ],
260  'layoutRootPaths' => [
261  'test/Layouts/'
262  ]
263  ], $result);
264  }
265 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:34
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInBackendMode
‪getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInBackendMode()
Definition: TemplatePathsTest.php:164
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\pathSetterMethodSortsPathsByKeyDescending
‪pathSetterMethodSortsPathsByKeyDescending($method, array $paths, array $expected)
Definition: TemplatePathsTest.php:95
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest
Definition: TemplatePathsTest.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationDoesNotResolveFromTypoScriptAndDoesNotSortInUnspecifiedMode
‪getContextSpecificViewConfigurationDoesNotResolveFromTypoScriptAndDoesNotSortInUnspecifiedMode()
Definition: TemplatePathsTest.php:221
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getPathSetterMethodTestValues
‪array getPathSetterMethodTestValues()
Definition: TemplatePathsTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\View
Definition: AbstractTemplateViewTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\View\TemplatePathsTest\getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInFrontendMode
‪getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInFrontendMode()
Definition: TemplatePathsTest.php:107