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