‪TYPO3CMS  ‪main
TypoScriptFrontendControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪TypoScriptFrontendControllerTest extends FunctionalTestCase
27 {
29 
30  protected const ‪LANGUAGE_PRESETS = [
31  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
32  ];
33 
34  protected array ‪$configurationToUseInTestInstance = [
35  'SYS' => [
36  'caching' => [
37  'cacheConfigurations' => [
38  'pages' => [
39  // Test headerAndFooterMarkersAreReplacedDuringIntProcessing() relies on persisted page cache:
40  // It calls FE rendering twice to verify USER_INT stuff is called for page-cache-exists-but-has-INT.
41  // testing-framework usually sets these to NullBackend which would defeat this case.
42  'backend' => Typo3DatabaseBackend::class,
43  ],
44  ],
45  ],
46  ],
47  ];
48 
53  {
54  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
55  $this->setUpFrontendRootPage(
56  2,
57  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageWithUserInt.typoscript']
58  );
60  'test',
61  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
62  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
63  );
64 
65  // Call page first time to trigger page cache with result
66  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
67  $body = (string)$response->getBody();
68  self::assertStringContainsString('userIntContent', $body);
69  self::assertStringContainsString('headerDataFromUserInt', $body);
70  self::assertStringContainsString('footerDataFromUserInt', $body);
71 
72  // Call page second time to see if it works with page cache and user_int is still executed.
73  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
74  $body = (string)$response->getBody();
75  self::assertStringContainsString('userIntContent', $body);
76  self::assertStringContainsString('headerDataFromUserInt', $body);
77  self::assertStringContainsString('footerDataFromUserInt', $body);
78  }
79 
83  public function ‪jsIncludesWithUserIntIsRendered(): void
84  {
85  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
86  $this->setUpFrontendRootPage(
87  2,
88  );
90  'test',
91  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
92  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
93  );
94 
95  $response = $this->executeFrontendSubRequest(
96  (new InternalRequest('https://website.local/en/'))
97  ->withPageId(2)
98  ->withInstructions([
99  (new TypoScriptInstruction())
100  ->withTypoScript([
101  'page' => 'PAGE',
102  'page.' => [
103  'jsInline.' => [
104  '10' => 'COA_INT',
105  '10.' => [
106  '10' => 'TEXT',
107  '10.' => [
108  'value' => 'alert(yes);',
109  ],
110  ],
111  ],
112  ],
113  ]),
114  ]),
115  );
116 
117  $body = (string)$response->getBody();
118  self::assertStringContainsString('/*TS_inlineJSint*/
119 alert(yes);', $body);
120  }
121 
126  {
127  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
128  $this->setUpFrontendRootPage(
129  2,
130  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageWithUserObjectUsingSlWithoutLLL.typoscript']
131  );
133  'test',
134  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
135  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
136  );
137 
138  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
139  $body = (string)$response->getBody();
140  self::assertStringContainsString('notprefixedWithLLL', $body);
141  }
142 
147  {
148  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
149  $this->setUpFrontendRootPage(
150  2,
151  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageWithUserObjectUsingSlWithLLL.typoscript']
152  );
154  'test',
155  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
156  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
157  );
158 
159  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
160  $body = (string)$response->getBody();
161  self::assertStringContainsString('Pagetree Overview', $body);
162  }
163 
165  {
166  return [
167  'no MP Parameter given' => [
168  '',
169  'empty',
170  ],
171  'single MP parameter given' => [
172  '592-182',
173  'foo592-182bar',
174  ],
175  'invalid characters included' => [
176  '12-13,a34-45/',
177  'foo12-13,34-45bar',
178  ],
179  ];
180  }
181 
186  public function ‪mountPointParameterContainsOnlyValidMPValues(string $inputMp, string $expected): void
187  {
188  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
189  $this->setUpFrontendRootPage(
190  2,
191  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageExposingTsfeMpParameter.typoscript']
192  );
194  'test',
195  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
196  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
197  );
198 
199  $response = $this->executeFrontendSubRequest(
200  (new InternalRequest('https://website.local/en/'))
201  ->withPageId(88)
202  ->withQueryParameter('MP', $inputMp)
203  );
204  $body = (string)$response->getBody();
205  self::assertStringContainsString($expected, $body);
206  }
207 
209  {
210  $page1 = [
211  'pid' => 0,
212  'uid' => 1,
213  't3ver_oid' => 0,
214  't3ver_wsid' => 0,
215  't3ver_state' => 0,
216  'title' => 'Pre page without template',
217  'nav_title' => '',
218  'media' => '',
219  'layout' => 0,
220  'hidden' => 0,
221  'starttime' => 0,
222  'endtime' => 0,
223  'fe_group' => '0',
224  'extendToSubpages' => 0,
225  'doktype' => 1,
226  'TSconfig' => null,
227  'tsconfig_includes' => null,
228  'is_siteroot' => 0,
229  'mount_pid' => 0,
230  'mount_pid_ol' => 0,
231  'backend_layout_next_level' => '',
232  ];
233  $page2 = [
234  'pid' => 1,
235  'uid' => 2,
236  't3ver_oid' => 0,
237  't3ver_wsid' => 0,
238  't3ver_state' => 0,
239  'title' => 'Root page having template with root flag set by tests',
240  'nav_title' => '',
241  'media' => '',
242  'layout' => 0,
243  'hidden' => 0,
244  'starttime' => 0,
245  'endtime' => 0,
246  'fe_group' => '0',
247  'extendToSubpages' => 0,
248  'doktype' => 1,
249  'TSconfig' => null,
250  'tsconfig_includes' => null,
251  'is_siteroot' => 1,
252  'mount_pid' => 0,
253  'mount_pid_ol' => 0,
254  'backend_layout_next_level' => '',
255  ];
256  $page88 = [
257  'pid' => 2,
258  'uid' => 88,
259  't3ver_oid' => 0,
260  't3ver_wsid' => 0,
261  't3ver_state' => 0,
262  'title' => 'Sub page 1',
263  'nav_title' => '',
264  'media' => '',
265  'layout' => 0,
266  'hidden' => 0,
267  'starttime' => 0,
268  'endtime' => 0,
269  'fe_group' => '0',
270  'extendToSubpages' => 0,
271  'doktype' => 1,
272  'TSconfig' => null,
273  'tsconfig_includes' => null,
274  'is_siteroot' => 0,
275  'mount_pid' => 0,
276  'mount_pid_ol' => 0,
277  'backend_layout_next_level' => '',
278  ];
279  $page89 = [
280  'pid' => 88,
281  'uid' => 89,
282  't3ver_oid' => 0,
283  't3ver_wsid' => 0,
284  't3ver_state' => 0,
285  'title' => 'Sub sub page 1',
286  'nav_title' => '',
287  'media' => '',
288  'layout' => 0,
289  'hidden' => 0,
290  'starttime' => 0,
291  'endtime' => 0,
292  'fe_group' => '0',
293  'extendToSubpages' => 0,
294  'doktype' => 1,
295  'TSconfig' => null,
296  'tsconfig_includes' => null,
297  'is_siteroot' => 0,
298  'mount_pid' => 0,
299  'mount_pid_ol' => 0,
300  'backend_layout_next_level' => '',
301  ];
302  $page98 = [
303  'pid' => 2,
304  'uid' => 98,
305  't3ver_oid' => 0,
306  't3ver_wsid' => 0,
307  't3ver_state' => 0,
308  'title' => 'Sub page 2 having template with root flag',
309  'nav_title' => '',
310  'media' => '',
311  'layout' => 0,
312  'hidden' => 0,
313  'starttime' => 0,
314  'endtime' => 0,
315  'fe_group' => '0',
316  'extendToSubpages' => 0,
317  'doktype' => 1,
318  'TSconfig' => null,
319  'tsconfig_includes' => null,
320  'is_siteroot' => 0,
321  'mount_pid' => 0,
322  'mount_pid_ol' => 0,
323  'backend_layout_next_level' => '',
324  ];
325  $page99 = [
326  'pid' => 98,
327  'uid' => 99,
328  't3ver_oid' => 0,
329  't3ver_wsid' => 0,
330  't3ver_state' => 0,
331  'title' => 'Sub sub page 2',
332  'nav_title' => '',
333  'media' => '',
334  'layout' => 0,
335  'hidden' => 0,
336  'starttime' => 0,
337  'endtime' => 0,
338  'fe_group' => '0',
339  'extendToSubpages' => 0,
340  'doktype' => 1,
341  'TSconfig' => null,
342  'tsconfig_includes' => null,
343  'is_siteroot' => 0,
344  'mount_pid' => 0,
345  'mount_pid_ol' => 0,
346  'backend_layout_next_level' => '',
347  ];
348  return [
349  'page with one root template on pid 2' => [
350  89,
351  [ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
352  [ 0 => $page2, 1 => $page88, 2 => $page89 ],
353  false,
354  ],
355  'page with one root template on pid 2 no cache' => [
356  89,
357  [ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
358  [ 0 => $page2, 1 => $page88, 2 => $page89 ],
359  true,
360  ],
361  'page with one root template on pid 2 and one on pid 98' => [
362  99,
363  [ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
364  [ 0 => $page98, 1 => $page99 ],
365  false,
366  ],
367  'page with one root template on pid 2 and one on pid 98 no cache' => [
368  99,
369  [ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
370  [ 0 => $page98, 1 => $page99 ],
371  true,
372  ],
373  ];
374  }
375 
380  public function ‪getFromCacheSetsConfigRootlineToLocalRootline(int $pid, array $expectedRootLine, array $expectedConfigRootLine, bool $nocache): void
381  {
382  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
383  $this->setUpFrontendRootPage(
384  2,
385  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageExposingTsfeMpParameter.typoscript']
386  );
388  'test',
389  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
390  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
391  );
392 
393  $request = (new InternalRequest('https://website.local/en/'))->withPageId($pid);
394  if ($nocache) {
395  $request = $request->withAttribute('noCache', true);
396  }
397  $this->executeFrontendSubRequest($request);
398  self::assertSame($expectedRootLine, ‪$GLOBALS['TSFE']->rootLine);
399  self::assertSame($expectedConfigRootLine, ‪$GLOBALS['TSFE']->config['rootLine']);
400  // @deprecated: b/w compat. Drop when TemplateService is removed.
401  self::assertSame($expectedConfigRootLine, ‪$GLOBALS['TSFE']->tmpl->rootLine);
402  }
403 
407  public function ‪applicationConsidersTrueConditionVerdict(): void
408  {
409  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
410  $this->setUpFrontendRootPage(
411  2,
412  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageHttpsConditionHelloWorld.typoscript']
413  );
415  'test',
416  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
417  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
418  );
419  $request = (new InternalRequest('https://website.local/en/'))->withPageId(2);
420  $response = $this->executeFrontendSubRequest($request);
421  self::assertStringContainsString('https-condition-on', (string)$response->getBody());
422  }
423 
428  {
429  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
430  $this->setUpFrontendRootPage(
431  2,
432  ['typo3/sysext/frontend/Tests/Functional/Controller/Fixtures/PageHttpsConditionHelloWorld.typoscript']
433  );
435  'test',
436  $this->‪buildSiteConfiguration(2, 'http://website.local/'),
437  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
438  );
439  $request = (new InternalRequest('http://website.local/en/'))->withPageId(2);
440  $response = $this->executeFrontendSubRequest($request);
441  self::assertStringContainsString('https-condition-off', (string)$response->getBody());
442  }
443 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:96
‪TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend
Definition: Typo3DatabaseBackend.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\localizationReturnsUnchangedStringIfNotLocallangLabel
‪localizationReturnsUnchangedStringIfNotLocallangLabel()
Definition: TypoScriptFrontendControllerTest.php:124
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\mountPointParameterContainsOnlyValidMPValuesDataProvider
‪static mountPointParameterContainsOnlyValidMPValuesDataProvider()
Definition: TypoScriptFrontendControllerTest.php:163
‪TYPO3\CMS\Frontend\Tests\Functional\Controller
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\getFromCacheSetsConfigRootlineToLocalRootlineDataProvider
‪static getFromCacheSetsConfigRootlineToLocalRootlineDataProvider()
Definition: TypoScriptFrontendControllerTest.php:207
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\applicationConsidersTrueConditionVerdict
‪applicationConsidersTrueConditionVerdict()
Definition: TypoScriptFrontendControllerTest.php:406
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: TypoScriptFrontendControllerTest.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: TypoScriptFrontendControllerTest.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\getFromCacheSetsConfigRootlineToLocalRootline
‪getFromCacheSetsConfigRootlineToLocalRootline(int $pid, array $expectedRootLine, array $expectedConfigRootLine, bool $nocache)
Definition: TypoScriptFrontendControllerTest.php:379
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\jsIncludesWithUserIntIsRendered
‪jsIncludesWithUserIntIsRendered()
Definition: TypoScriptFrontendControllerTest.php:82
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\headerAndFooterMarkersAreReplacedDuringIntProcessing
‪headerAndFooterMarkersAreReplacedDuringIntProcessing()
Definition: TypoScriptFrontendControllerTest.php:51
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\localizationReturnsLocalizedStringWithLocallangLabel
‪localizationReturnsLocalizedStringWithLocallangLabel()
Definition: TypoScriptFrontendControllerTest.php:145
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:106
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest
Definition: TypoScriptFrontendControllerTest.php:27
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\applicationConsidersFalseConditionVerdictToElseBranch
‪applicationConsidersFalseConditionVerdictToElseBranch()
Definition: TypoScriptFrontendControllerTest.php:426
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\mountPointParameterContainsOnlyValidMPValues
‪mountPointParameterContainsOnlyValidMPValues(string $inputMp, string $expected)
Definition: TypoScriptFrontendControllerTest.php:185