d8e766debd183b08800796404a3e8d784aa512d3
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Functional / View / TemplatesPathsTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Functional\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\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
18 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
19
20 class TemplatesPathsTest extends FunctionalTestCase
21 {
22 /**
23 * @var array
24 */
25 protected $testExtensionsToLoad = [
26 'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
27 ];
28
29 /**
30 * @var array
31 */
32 protected $coreExtensionsToLoad = [
33 'fluid',
34 ];
35
36 /**
37 * @var array
38 */
39 protected $configurationToUseInTestInstance = [
40 'EXTCONF' => [
41 'extbase' => [
42 'extensions' => [
43 'FluidTest' => [
44 'plugins' => [
45 'Pi' => [
46 'controllers' => [
47 'Template' => [
48 'actions' => [
49 'baseTemplate',
50 ],
51 'nonCacheableActions' => [
52 'baseTemplate',
53 ],
54 ],
55 ],
56 ],
57 ],
58 ],
59 ],
60 ],
61 ],
62 ];
63
64 public function setUp()
65 {
66 parent::setUp();
67
68 $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
69 $this->setUpFrontendRootPage(1, ['EXT:fluid_test/Configuration/TypoScript/Basic.ts']);
70 }
71
72 /**
73 * @return array
74 */
75 public function differentOverrideScenariosDataProvider(): array
76 {
77 return [
78 'base' => [
79 'base',
80 'Base Template',
81 'Base Partial',
82 'Base Layout',
83 ],
84 'overrideAll' => [
85 'overrideAll',
86 'Override Template',
87 'Override Partial',
88 'Override Layout',
89 ],
90 'templateOverride' => [
91 'templateOverride',
92 'TemplateOverride',
93 'Base Partial',
94 'Base Layout',
95 ],
96 'templateOverrideManual' => [
97 'templateOverrideManual',
98 'TemplateOverride',
99 'Base Partial',
100 'Base Layout',
101 ],
102 'partialOverride' => [
103 'partialOverride',
104 'Base Template',
105 'PartialOverride',
106 'Base Layout',
107 ],
108 'partialOverrideManual' => [
109 'partialOverrideManual',
110 'Base Template',
111 'PartialOverride',
112 'Base Layout',
113 ],
114 'layoutOverride' => [
115 'layoutOverride',
116 'Base Template',
117 'Base Partial',
118 'LayoutOverride',
119 ],
120 'layoutOverrideManual' => [
121 'layoutOverrideManual',
122 'Base Template',
123 'Base Partial',
124 'LayoutOverride',
125 ],
126 ];
127 }
128
129 /**
130 * @test
131 * @param string $overrideType
132 * @param string $expectedTemplate
133 * @param string $expectedPartial
134 * @param string $expectedLayout
135 * @dataProvider differentOverrideScenariosDataProvider
136 */
137 public function baseRenderingWorksForCObject($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
138 {
139 $requestArguments = [
140 'id' => '1',
141 'override' => $overrideType,
142 'mode' => 'fluidTemplate',
143 ];
144
145 $content = $this->fetchFrontendResponseBody($requestArguments);
146
147 $this->assertContains($expectedTemplate, $content);
148 $this->assertContains($expectedPartial, $content);
149 $this->assertContains($expectedLayout, $content);
150 }
151
152 /**
153 * @test
154 * @param string $overrideType
155 * @param string $expectedTemplate
156 * @param string $expectedPartial
157 * @param string $expectedLayout
158 * @dataProvider differentOverrideScenariosDataProvider
159 */
160 public function baseRenderingWorksForControllerAsGlobalUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
161 {
162 $requestArguments = [
163 'id' => '1',
164 'override' => $overrideType,
165 'mode' => 'controller',
166 ];
167
168 $content = $this->fetchFrontendResponseBody($requestArguments);
169
170 $this->assertContains($expectedTemplate, $content);
171 $this->assertContains($expectedPartial, $content);
172 $this->assertContains($expectedLayout, $content);
173 }
174
175 /**
176 * @test
177 * @param string $overrideType
178 * @param string $expectedTemplate
179 * @param string $expectedPartial
180 * @param string $expectedLayout
181 * @dataProvider differentOverrideScenariosDataProvider
182 */
183 public function baseRenderingWorksForControllerAsPluginUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
184 {
185 $requestArguments = [
186 'id' => '1',
187 'override' => $overrideType,
188 'mode' => 'plugin',
189 'pluginConfig' => 'extensionKey',
190 ];
191
192 $content = $this->fetchFrontendResponseBody($requestArguments);
193
194 $this->assertContains($expectedTemplate, $content);
195 $this->assertContains($expectedPartial, $content);
196 $this->assertContains($expectedLayout, $content);
197 }
198
199 /**
200 * @test
201 * @param string $overrideType
202 * @param string $expectedTemplate
203 * @param string $expectedPartial
204 * @param string $expectedLayout
205 * @dataProvider differentOverrideScenariosDataProvider
206 */
207 public function baseRenderingWorksForControllerAsPluginUsageWithPluginConfig($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
208 {
209 $requestArguments = [
210 'id' => '1',
211 'override' => $overrideType,
212 'mode' => 'plugin',
213 'pluginConfig' => 'pluginName',
214 ];
215
216 $content = $this->fetchFrontendResponseBody($requestArguments);
217
218 $this->assertContains($expectedTemplate, $content);
219 $this->assertContains($expectedPartial, $content);
220 $this->assertContains($expectedLayout, $content);
221 }
222
223 /**
224 * @test
225 */
226 public function widgetTemplateCanBeOverridden()
227 {
228 $requestArguments = [
229 'id' => '1',
230 'override' => 'base',
231 'mode' => 'controller',
232 'widgetConfig' => 'new',
233 ];
234
235 $content = $this->fetchFrontendResponseBody($requestArguments);
236
237 $this->assertContains('PAGINATE WIDGET', $content);
238 }
239
240 /**
241 * @test
242 */
243 public function widgetTemplateCanBeOverriddenWithLegacyConfig()
244 {
245 $requestArguments = [
246 'id' => '1',
247 'override' => 'base',
248 'mode' => 'controller',
249 'widgetConfig' => 'old',
250 ];
251
252 $content = $this->fetchFrontendResponseBody($requestArguments);
253
254 $this->assertContains('PAGINATE WIDGET', $content);
255 }
256
257 /**
258 * @test
259 */
260 public function baseRenderingWorksForControllerAsPluginUsageWithIncompleteConfig()
261 {
262 $requestArguments = [
263 'id' => '1',
264 'override' => 'base',
265 'mode' => 'plugin',
266 'pluginConfig' => 'incomplete',
267 ];
268
269 $content = $this->fetchFrontendResponseBody($requestArguments);
270
271 $this->assertContains('Base Template', $content);
272 $this->assertContains('Default Layout', $content);
273 $this->assertContains('Default Partial', $content);
274 }
275
276 /**
277 * @test
278 */
279 public function baseRenderingWorksForControllerWithTwoPlugins()
280 {
281 $requestArguments = [
282 'id' => '1',
283 'mode' => '2plugins',
284 ];
285
286 $content = $this->fetchFrontendResponseBody($requestArguments);
287
288 $this->assertContains('Base Template', $content);
289 $this->assertContains('Override Template', $content);
290 }
291
292 /**
293 * @param array $requestArguments
294 * @return string
295 */
296 protected function fetchFrontendResponseBody(array $requestArguments): string
297 {
298 $response = $this->executeFrontendRequest(
299 (new InternalRequest())->withQueryParameters($requestArguments)
300 );
301
302 return (string)$response->getBody();
303 }
304 }