TYPO3 CMS  TYPO3_8-7
TemplatesPathsTest.php
Go to the documentation of this file.
1 <?php
3 
8 
9 class TemplatesPathsTest extends FunctionalTestCase
10 {
14  protected $testExtensionsToLoad = [
15  'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
16  ];
17 
21  protected $coreExtensionsToLoad = [
22  'fluid',
23  ];
24 
29  'EXTCONF' => [
30  'extbase' => [
31  'extensions' => [
32  'FluidTest' => [
33  'plugins' => [
34  'Pi' => [
35  'controllers' => [
36  'Template' => [
37  'actions' => [
38  'baseTemplate',
39  ],
40  'nonCacheableActions' => [
41  'baseTemplate',
42  ],
43  ],
44  ],
45  ],
46  ],
47  ],
48  ],
49  ],
50  ],
51  ];
52 
53  public function setUp()
54  {
55  parent::setUp();
56 
57  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
58  $this->setUpFrontendRootPage(1, ['EXT:fluid_test/Configuration/TypoScript/Basic.ts']);
59  }
60 
64  public function differentOverrideScenariosDataProvider(): array
65  {
66  return [
67  'base' => [
68  'base',
69  'Base Template',
70  'Base Partial',
71  'Base Layout',
72  ],
73  'overrideAll' => [
74  'overrideAll',
75  'Override Template',
76  'Override Partial',
77  'Override Layout',
78  ],
79  'templateOverride' => [
80  'templateOverride',
81  'TemplateOverride',
82  'Base Partial',
83  'Base Layout',
84  ],
85  'templateOverrideManual' => [
86  'templateOverrideManual',
87  'TemplateOverride',
88  'Base Partial',
89  'Base Layout',
90  ],
91  'partialOverride' => [
92  'partialOverride',
93  'Base Template',
94  'PartialOverride',
95  'Base Layout',
96  ],
97  'partialOverrideManual' => [
98  'partialOverrideManual',
99  'Base Template',
100  'PartialOverride',
101  'Base Layout',
102  ],
103  'layoutOverride' => [
104  'layoutOverride',
105  'Base Template',
106  'Base Partial',
107  'LayoutOverride',
108  ],
109  'layoutOverrideManual' => [
110  'layoutOverrideManual',
111  'Base Template',
112  'Base Partial',
113  'LayoutOverride',
114  ],
115  ];
116  }
117 
126  public function baseRenderingWorksForCObject($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
127  {
128  $requestArguments = [
129  'id' => '1',
130  'override' => $overrideType,
131  'mode' => 'fluidTemplate',
132  ];
133 
134  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
135 
136  $this->assertContains($expectedTemplate, $content);
137  $this->assertContains($expectedPartial, $content);
138  $this->assertContains($expectedLayout, $content);
139  }
140 
149  public function baseRenderingWorksForControllerAsGlobalUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
150  {
151  $requestArguments = [
152  'id' => '1',
153  'override' => $overrideType,
154  'mode' => 'controller',
155  ];
156 
157  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
158 
159  $this->assertContains($expectedTemplate, $content);
160  $this->assertContains($expectedPartial, $content);
161  $this->assertContains($expectedLayout, $content);
162  }
163 
172  public function baseRenderingWorksForControllerAsPluginUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
173  {
174  $requestArguments = [
175  'id' => '1',
176  'override' => $overrideType,
177  'mode' => 'plugin',
178  'pluginConfig' => 'extensionKey',
179  ];
180 
181  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
182 
183  $this->assertContains($expectedTemplate, $content);
184  $this->assertContains($expectedPartial, $content);
185  $this->assertContains($expectedLayout, $content);
186  }
187 
196  public function baseRenderingWorksForControllerAsPluginUsageWithPluginConfig($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
197  {
198  $requestArguments = [
199  'id' => '1',
200  'override' => $overrideType,
201  'mode' => 'plugin',
202  'pluginConfig' => 'pluginName',
203  ];
204 
205  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
206 
207  $this->assertContains($expectedTemplate, $content);
208  $this->assertContains($expectedPartial, $content);
209  $this->assertContains($expectedLayout, $content);
210  }
211 
216  {
217  $requestArguments = [
218  'id' => '1',
219  'override' => 'base',
220  'mode' => 'controller',
221  'widgetConfig' => 'new',
222  ];
223 
224  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
225 
226  $this->assertContains('PAGINATE WIDGET', $content);
227  }
228 
233  {
234  $requestArguments = [
235  'id' => '1',
236  'override' => 'base',
237  'mode' => 'controller',
238  'widgetConfig' => 'old',
239  ];
240 
241  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
242 
243  $this->assertContains('PAGINATE WIDGET', $content);
244  }
245 
250  {
251  $requestArguments = [
252  'id' => '1',
253  'override' => 'base',
254  'mode' => 'plugin',
255  'pluginConfig' => 'incomplete',
256  ];
257 
258  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
259 
260  $this->assertContains('Base Template', $content);
261  $this->assertContains('Default Layout', $content);
262  $this->assertContains('Default Partial', $content);
263  }
264 
269  {
270  $requestArguments = [
271  'id' => '1',
272  'mode' => '2plugins',
273  ];
274 
275  $content = $this->fetchFrontendResponse($requestArguments)->getContent();
276 
277  $this->assertContains('Base Template', $content);
278  $this->assertContains('Override Template', $content);
279  }
280 
286  protected function fetchFrontendResponse(array $requestArguments, $failOnFailure = true)
287  {
288  $arguments = [
289  'documentRoot' => $this->instancePath,
290  'requestUrl' => 'http://localhost' . '/?' . GeneralUtility::implodeArrayForUrl('', $requestArguments),
291  ];
292 
293  $template = new \Text_Template(TYPO3_PATH_PACKAGES . 'typo3/testing-framework/Resources/Core/Functional/Fixtures/Frontend/request.tpl');
294  $template->setVar(
295  [
296  'arguments' => var_export($arguments, true),
297  'originalRoot' => ORIGINAL_ROOT,
298  'vendorPath' => TYPO3_PATH_PACKAGES,
299  ]
300  );
301 
302  $php = AbstractPhpProcess::factory();
303  $response = $php->runJob($template->render());
304  $result = json_decode($response['stdout'], true);
305 
306  if ($result === null) {
307  $this->fail('Frontend Response is empty');
308  }
309 
310  if ($failOnFailure && $result['status'] === Response::STATUS_Failure) {
311  $this->fail('Frontend Response has failure:' . LF . $result['error']);
312  }
313 
314  $response = new Response($result['status'], $result['content'], $result['error']);
315 
316  return $response;
317  }
318 }
baseRenderingWorksForControllerAsGlobalUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
baseRenderingWorksForControllerAsPluginUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
baseRenderingWorksForControllerAsPluginUsageWithPluginConfig($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
baseRenderingWorksForCObject($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
fetchFrontendResponse(array $requestArguments, $failOnFailure=true)
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=false, $rawurlencodeParamName=false)