‪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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
26 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 final class ‪TypoScriptFrontendControllerTest extends FunctionalTestCase
30 {
32 
33  protected const ‪LANGUAGE_PRESETS = [
34  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
35  ];
36 
37  protected array ‪$configurationToUseInTestInstance = [
38  'SYS' => [
39  'caching' => [
40  'cacheConfigurations' => [
41  'pages' => [
42  // Test headerAndFooterMarkersAreReplacedDuringIntProcessing() relies on persisted page cache:
43  // It calls FE rendering twice to verify USER_INT stuff is called for page-cache-exists-but-has-INT.
44  // testing-framework usually sets these to NullBackend which would defeat this case.
45  'backend' => Typo3DatabaseBackend::class,
46  ],
47  ],
48  ],
49  ],
50  ];
51 
52  #[Test]
54  {
55  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
56  $this->setUpFrontendRootPage(
57  2,
58  ['EXT:frontend/Tests/Functional/Controller/Fixtures/PageWithUserInt.typoscript']
59  );
61  'test',
62  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
63  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
64  );
65 
66  // Call page first time to trigger page cache with result
67  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
68  $body = (string)$response->getBody();
69  self::assertStringContainsString('userIntContent', $body);
70  self::assertStringContainsString('headerDataFromUserInt', $body);
71  self::assertStringContainsString('footerDataFromUserInt', $body);
72 
73  // Call page second time to see if it works with page cache and user_int is still executed.
74  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
75  $body = (string)$response->getBody();
76  self::assertStringContainsString('userIntContent', $body);
77  self::assertStringContainsString('headerDataFromUserInt', $body);
78  self::assertStringContainsString('footerDataFromUserInt', $body);
79  }
80 
81  #[Test]
82  public function ‪jsIncludesWithUserIntIsRendered(): void
83  {
84  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
85  $this->setUpFrontendRootPage(2);
87  'test',
88  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
89  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
90  );
91 
92  $response = $this->executeFrontendSubRequest(
93  (new InternalRequest('https://website.local/en/'))
94  ->withPageId(2)
95  ->withInstructions([
96  (new TypoScriptInstruction())
97  ->withTypoScript([
98  'page' => 'PAGE',
99  'page.' => [
100  'jsInline.' => [
101  '10' => 'COA_INT',
102  '10.' => [
103  '10' => 'TEXT',
104  '10.' => [
105  'value' => 'alert(yes);',
106  ],
107  ],
108  ],
109  ],
110  ]),
111  ]),
112  );
113 
114  $body = (string)$response->getBody();
115  self::assertStringContainsString('/*TS_inlineJSint*/
116 alert(yes);', $body);
117  }
118 
119  #[Test]
121  {
122  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
123  $this->setUpFrontendRootPage(
124  2,
125  ['EXT:frontend/Tests/Functional/Controller/Fixtures/PageWithUserObjectUsingSlWithoutLLL.typoscript']
126  );
128  'test',
129  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
130  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
131  );
132 
133  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
134  $body = (string)$response->getBody();
135  self::assertStringContainsString('notprefixedWithLLL', $body);
136  }
137 
138  #[Test]
140  {
141  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
142  $this->setUpFrontendRootPage(
143  2,
144  ['EXT:frontend/Tests/Functional/Controller/Fixtures/PageWithUserObjectUsingSlWithLLL.typoscript']
145  );
147  'test',
148  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
149  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
150  );
151 
152  $response = $this->executeFrontendSubRequest((new InternalRequest('https://website.local/en/'))->withPageId(88));
153  $body = (string)$response->getBody();
154  self::assertStringContainsString('Pagetree Overview', $body);
155  }
156 
158  {
159  $page1 = [
160  'pid' => 0,
161  'uid' => 1,
162  't3ver_oid' => 0,
163  't3ver_wsid' => 0,
164  't3ver_state' => 0,
165  'title' => 'Pre page without template',
166  'nav_title' => '',
167  'media' => '',
168  'layout' => 0,
169  'hidden' => 0,
170  'starttime' => 0,
171  'endtime' => 0,
172  'fe_group' => '0',
173  'extendToSubpages' => 0,
174  'doktype' => 1,
175  'TSconfig' => null,
176  'tsconfig_includes' => '',
177  'is_siteroot' => 0,
178  'mount_pid' => 0,
179  'mount_pid_ol' => 0,
180  'backend_layout_next_level' => '',
181  ];
182  $page2 = [
183  'pid' => 1,
184  'uid' => 2,
185  't3ver_oid' => 0,
186  't3ver_wsid' => 0,
187  't3ver_state' => 0,
188  'title' => 'Root page having template with root flag set by tests',
189  'nav_title' => '',
190  'media' => '',
191  'layout' => 0,
192  'hidden' => 0,
193  'starttime' => 0,
194  'endtime' => 0,
195  'fe_group' => '0',
196  'extendToSubpages' => 0,
197  'doktype' => 1,
198  'TSconfig' => null,
199  'tsconfig_includes' => '',
200  'is_siteroot' => 1,
201  'mount_pid' => 0,
202  'mount_pid_ol' => 0,
203  'backend_layout_next_level' => '',
204  ];
205  $page88 = [
206  'pid' => 2,
207  'uid' => 88,
208  't3ver_oid' => 0,
209  't3ver_wsid' => 0,
210  't3ver_state' => 0,
211  'title' => 'Sub page 1',
212  'nav_title' => '',
213  'media' => '',
214  'layout' => 0,
215  'hidden' => 0,
216  'starttime' => 0,
217  'endtime' => 0,
218  'fe_group' => '0',
219  'extendToSubpages' => 0,
220  'doktype' => 1,
221  'TSconfig' => null,
222  'tsconfig_includes' => '',
223  'is_siteroot' => 0,
224  'mount_pid' => 0,
225  'mount_pid_ol' => 0,
226  'backend_layout_next_level' => '',
227  ];
228  $page89 = [
229  'pid' => 88,
230  'uid' => 89,
231  't3ver_oid' => 0,
232  't3ver_wsid' => 0,
233  't3ver_state' => 0,
234  'title' => 'Sub sub page 1',
235  'nav_title' => '',
236  'media' => '',
237  'layout' => 0,
238  'hidden' => 0,
239  'starttime' => 0,
240  'endtime' => 0,
241  'fe_group' => '0',
242  'extendToSubpages' => 0,
243  'doktype' => 1,
244  'TSconfig' => null,
245  'tsconfig_includes' => '',
246  'is_siteroot' => 0,
247  'mount_pid' => 0,
248  'mount_pid_ol' => 0,
249  'backend_layout_next_level' => '',
250  ];
251  $page98 = [
252  'pid' => 2,
253  'uid' => 98,
254  't3ver_oid' => 0,
255  't3ver_wsid' => 0,
256  't3ver_state' => 0,
257  'title' => 'Sub page 2 having template with root flag',
258  'nav_title' => '',
259  'media' => '',
260  'layout' => 0,
261  'hidden' => 0,
262  'starttime' => 0,
263  'endtime' => 0,
264  'fe_group' => '0',
265  'extendToSubpages' => 0,
266  'doktype' => 1,
267  'TSconfig' => null,
268  'tsconfig_includes' => '',
269  'is_siteroot' => 0,
270  'mount_pid' => 0,
271  'mount_pid_ol' => 0,
272  'backend_layout_next_level' => '',
273  ];
274  $page99 = [
275  'pid' => 98,
276  'uid' => 99,
277  't3ver_oid' => 0,
278  't3ver_wsid' => 0,
279  't3ver_state' => 0,
280  'title' => 'Sub sub page 2',
281  'nav_title' => '',
282  'media' => '',
283  'layout' => 0,
284  'hidden' => 0,
285  'starttime' => 0,
286  'endtime' => 0,
287  'fe_group' => '0',
288  'extendToSubpages' => 0,
289  'doktype' => 1,
290  'TSconfig' => null,
291  'tsconfig_includes' => '',
292  'is_siteroot' => 0,
293  'mount_pid' => 0,
294  'mount_pid_ol' => 0,
295  'backend_layout_next_level' => '',
296  ];
297  return [
298  'page with one root template on pid 2' => [
299  89,
300  [ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
301  [ 0 => $page2, 1 => $page88, 2 => $page89 ],
302  false,
303  ],
304  'page with one root template on pid 2 no cache' => [
305  89,
306  [ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
307  [ 0 => $page2, 1 => $page88, 2 => $page89 ],
308  true,
309  ],
310  'page with one root template on pid 2 and one on pid 98' => [
311  99,
312  [ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
313  [ 0 => $page98, 1 => $page99 ],
314  false,
315  ],
316  'page with one root template on pid 2 and one on pid 98 no cache' => [
317  99,
318  [ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
319  [ 0 => $page98, 1 => $page99 ],
320  true,
321  ],
322  ];
323  }
324 
325  #[DataProvider('getFromCacheSetsConfigRootlineToLocalRootlineDataProvider')]
326  #[Test]
327  public function ‪getFromCacheSetsConfigRootlineToLocalRootline(int $pid, array $expectedRootLine, array $expectedConfigRootLine, bool $nocache): void
328  {
329  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
330  $this->setUpFrontendRootPage(
331  2,
332  ['EXT:frontend/Tests/Functional/Controller/Fixtures/PageHelloWorld.typoscript']
333  );
335  'test',
336  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
337  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
338  );
339 
340  $request = (new InternalRequest('https://website.local/en/'))->withPageId($pid);
341  if ($nocache) {
342  $cacheInstruction = new ‪CacheInstruction();
343  $cacheInstruction->disableCache('EXT:frontend: Testing disables caching.');
344  $request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
345  }
346  $this->executeFrontendSubRequest($request);
347  self::assertSame($expectedRootLine, ‪$GLOBALS['TSFE']->rootLine);
348  self::assertSame($expectedConfigRootLine, ‪$GLOBALS['TSFE']->config['rootLine']);
349  }
350 
351  #[Test]
352  public function ‪applicationConsidersTrueConditionVerdict(): void
353  {
354  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
355  $this->setUpFrontendRootPage(
356  2,
357  ['EXT:frontend/Tests/Functional/Controller/Fixtures/PageHttpsConditionHelloWorld.typoscript']
358  );
360  'test',
361  $this->‪buildSiteConfiguration(2, 'https://website.local/'),
362  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
363  );
364  $request = (new InternalRequest('https://website.local/en/'))->withPageId(2);
365  $response = $this->executeFrontendSubRequest($request);
366  self::assertStringContainsString('https-condition-on', (string)$response->getBody());
367  }
368 
369  #[Test]
371  {
372  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
373  $this->setUpFrontendRootPage(
374  2,
375  ['EXT:frontend/Tests/Functional/Controller/Fixtures/PageHttpsConditionHelloWorld.typoscript']
376  );
378  'test',
379  $this->‪buildSiteConfiguration(2, 'http://website.local/'),
380  [$this->‪buildDefaultLanguageConfiguration('EN', '/en/')]
381  );
382  $request = (new InternalRequest('http://website.local/en/'))->withPageId(2);
383  $response = $this->executeFrontendSubRequest($request);
384  self::assertStringContainsString('https-condition-off', (string)$response->getBody());
385  }
386 }
‪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:88
‪TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend
Definition: Typo3DatabaseBackend.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\localizationReturnsUnchangedStringIfNotLocallangLabel
‪localizationReturnsUnchangedStringIfNotLocallangLabel()
Definition: TypoScriptFrontendControllerTest.php:119
‪TYPO3\CMS\Frontend\Tests\Functional\Controller
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\getFromCacheSetsConfigRootlineToLocalRootlineDataProvider
‪static getFromCacheSetsConfigRootlineToLocalRootlineDataProvider()
Definition: TypoScriptFrontendControllerTest.php:156
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\applicationConsidersTrueConditionVerdict
‪applicationConsidersTrueConditionVerdict()
Definition: TypoScriptFrontendControllerTest.php:351
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: TypoScriptFrontendControllerTest.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: TypoScriptFrontendControllerTest.php:32
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\getFromCacheSetsConfigRootlineToLocalRootline
‪getFromCacheSetsConfigRootlineToLocalRootline(int $pid, array $expectedRootLine, array $expectedConfigRootLine, bool $nocache)
Definition: TypoScriptFrontendControllerTest.php:326
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\jsIncludesWithUserIntIsRendered
‪jsIncludesWithUserIntIsRendered()
Definition: TypoScriptFrontendControllerTest.php:81
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\headerAndFooterMarkersAreReplacedDuringIntProcessing
‪headerAndFooterMarkersAreReplacedDuringIntProcessing()
Definition: TypoScriptFrontendControllerTest.php:52
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\localizationReturnsLocalizedStringWithLocallangLabel
‪localizationReturnsLocalizedStringWithLocallangLabel()
Definition: TypoScriptFrontendControllerTest.php:138
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest
Definition: TypoScriptFrontendControllerTest.php:30
‪TYPO3\CMS\Frontend\Cache\CacheInstruction
Definition: CacheInstruction.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\Controller\TypoScriptFrontendControllerTest\applicationConsidersFalseConditionVerdictToElseBranch
‪applicationConsidersFalseConditionVerdictToElseBranch()
Definition: TypoScriptFrontendControllerTest.php:369