‪TYPO3CMS  ‪main
TypoScriptFrontendInitializationTest.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\Test;
22 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪TypoScriptFrontendInitializationTest extends FunctionalTestCase
27 {
29 
30  protected const ‪LANGUAGE_PRESETS = [
31  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
32  ];
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
38  'acme-com',
39  $this->‪buildSiteConfiguration(1, 'https://acme.com/'),
40  [
41  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
42  ]
43  );
44  }
45 
46  #[Test]
47  public function ‪notFoundFromHiddenPage(): void
48  {
49  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
50  $response = $this->executeFrontendSubRequest(
51  new InternalRequest('https://acme.com/hidden/')
52  );
53  self::assertEquals(404, $response->getStatusCode());
54  self::assertStringContainsString('The requested page does not exist!', (string)$response->getBody());
55  }
56 
57  #[Test]
58  public function ‪okFromHiddenPageWithBackendUser(): void
59  {
60  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
61  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationSysTemplate.csv');
62  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationBeUsers.csv');
63  $response = $this->executeFrontendSubRequest(
64  new InternalRequest('https://acme.com/hidden/'),
65  (new InternalRequestContext())->withBackendUserId(1)
66  );
67  self::assertEquals(200, $response->getStatusCode());
68  self::assertStringContainsString('testing-typoScriptFrontendInitialization', (string)$response->getBody());
69  }
70 
71  #[Test]
72  public function ‪notAccessibleFromLoginRestrictedPage(): void
73  {
74  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
75  $response = $this->executeFrontendSubRequest(
76  new InternalRequest('https://acme.com/login-restricted/')
77  );
78  self::assertEquals(403, $response->getStatusCode());
79  self::assertStringContainsString('ID was not an accessible page', (string)$response->getBody());
80  }
81 
82  #[Test]
83  public function ‪okFromLoginRestrictedPage(): void
84  {
85  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
86  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationSysTemplate.csv');
87  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationFeGroupsFeUsers.csv');
88  $response = $this->executeFrontendSubRequest(
89  new InternalRequest('https://acme.com/login-restricted/'),
90  (new InternalRequestContext())->withFrontendUserId(1)
91  );
92  self::assertEquals(200, $response->getStatusCode());
93  self::assertStringContainsString('testing-typoScriptFrontendInitialization', (string)$response->getBody());
94  }
95 
96  #[Test]
98  {
99  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
100  $response = $this->executeFrontendSubRequest(
101  new InternalRequest('https://acme.com/login-restricted-group-one/')
102  );
103  self::assertEquals(403, $response->getStatusCode());
104  self::assertStringContainsString('ID was not an accessible page', (string)$response->getBody());
105  }
106 
107  #[Test]
109  {
110  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
111  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationFeGroupsFeUsers.csv');
112  $response = $this->executeFrontendSubRequest(
113  new InternalRequest('https://acme.com/login-restricted-group-one/'),
114  (new InternalRequestContext())->withFrontendUserId(2)
115  );
116  self::assertEquals(403, $response->getStatusCode());
117  self::assertStringContainsString('ID was not an accessible page', (string)$response->getBody());
118  }
119 
120  #[Test]
122  {
123  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
124  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationSysTemplate.csv');
125  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationFeGroupsFeUsers.csv');
126  $response = $this->executeFrontendSubRequest(
127  new InternalRequest('https://acme.com/login-restricted-group-one/'),
128  (new InternalRequestContext())->withFrontendUserId(1)
129  );
130  self::assertEquals(200, $response->getStatusCode());
131  self::assertStringContainsString('testing-typoScriptFrontendInitialization', (string)$response->getBody());
132  }
133 
134  #[Test]
135  public function ‪notFoundFromSpacerPage(): void
136  {
137  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
138  $response = $this->executeFrontendSubRequest(
139  new InternalRequest('https://acme.com/spacer/')
140  );
141  self::assertEquals(404, $response->getStatusCode());
142  self::assertStringContainsString('The requested page does not exist!', (string)$response->getBody());
143  }
144 
145  #[Test]
146  public function ‪notFoundFromSysFolderPage(): void
147  {
148  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
149  $response = $this->executeFrontendSubRequest(
150  new InternalRequest('https://acme.com/sysfolder/')
151  );
152  self::assertEquals(404, $response->getStatusCode());
153  self::assertStringContainsString('The requested page does not exist!', (string)$response->getBody());
154  }
155 
156  #[Test]
157  public function ‪notFoundFromShortcutTargetDoesNotExist(): void
158  {
159  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
160  $response = $this->executeFrontendSubRequest(
161  new InternalRequest('https://acme.com/shortcut-target-not-exists/')
162  );
163  self::assertEquals(404, $response->getStatusCode());
164  self::assertStringContainsString('ID was not an accessible page', (string)$response->getBody());
165  }
166 
167  #[Test]
168  public function ‪redirectFoundFromValidShortcutTarget(): void
169  {
170  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
171  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationSysTemplate.csv');
172  $response = $this->executeFrontendSubRequest(
173  new InternalRequest('https://acme.com/shortcut/')
174  );
175  self::assertEquals(307, $response->getStatusCode());
176  }
177 
178  #[Test]
179  public function ‪okFromDirectlyRequestedId(): void
180  {
181  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
182  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationSysTemplate.csv');
183  $response = $this->executeFrontendSubRequest(
184  new InternalRequest('https://acme.com/?id=9')
185  );
186  self::assertEquals(200, $response->getStatusCode());
187  self::assertStringContainsString('testing-typoScriptFrontendInitialization', (string)$response->getBody());
188  }
189 
190  #[Test]
192  {
193  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationCases.csv');
194  $this->importCSVDataSet(__DIR__ . '/Fixtures/typoScriptFrontendInitializationSysTemplate.csv');
195  $response = $this->executeFrontendSubRequest(
196  new InternalRequest('https://acme.com/?id=10')
197  );
198  self::assertEquals(404, $response->getStatusCode());
199  self::assertStringContainsString('ID was outside the domain', (string)$response->getBody());
200  }
201 }
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notAccessibleFromLoginRestrictedGroupOnePageWithGroupTwo
‪notAccessibleFromLoginRestrictedGroupOnePageWithGroupTwo()
Definition: TypoScriptFrontendInitializationTest.php:107
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notFoundFromSysFolderPage
‪notFoundFromSysFolderPage()
Definition: TypoScriptFrontendInitializationTest.php:145
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notFoundFromHiddenPage
‪notFoundFromHiddenPage()
Definition: TypoScriptFrontendInitializationTest.php:46
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: TypoScriptFrontendInitializationTest.php:29
‪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\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\okFromLoginRestrictedPage
‪okFromLoginRestrictedPage()
Definition: TypoScriptFrontendInitializationTest.php:82
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notAccessibleFromLoginRestrictedGroupOnePage
‪notAccessibleFromLoginRestrictedGroupOnePage()
Definition: TypoScriptFrontendInitializationTest.php:96
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notAccessibleFromLoginRestrictedPage
‪notAccessibleFromLoginRestrictedPage()
Definition: TypoScriptFrontendInitializationTest.php:71
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\redirectFoundFromValidShortcutTarget
‪redirectFoundFromValidShortcutTarget()
Definition: TypoScriptFrontendInitializationTest.php:167
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notFoundFromSpacerPage
‪notFoundFromSpacerPage()
Definition: TypoScriptFrontendInitializationTest.php:134
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notFoundFromDirectlyRequestedIdOfDifferentDomain
‪notFoundFromDirectlyRequestedIdOfDifferentDomain()
Definition: TypoScriptFrontendInitializationTest.php:190
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\okFromHiddenPageWithBackendUser
‪okFromHiddenPageWithBackendUser()
Definition: TypoScriptFrontendInitializationTest.php:57
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware
Definition: BackendUserAuthenticatorTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\okFromLoginRestrictedGroupOnePageWithGroupOne
‪okFromLoginRestrictedGroupOnePageWithGroupOne()
Definition: TypoScriptFrontendInitializationTest.php:120
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\okFromDirectlyRequestedId
‪okFromDirectlyRequestedId()
Definition: TypoScriptFrontendInitializationTest.php:178
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\setUp
‪setUp()
Definition: TypoScriptFrontendInitializationTest.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest\notFoundFromShortcutTargetDoesNotExist
‪notFoundFromShortcutTargetDoesNotExist()
Definition: TypoScriptFrontendInitializationTest.php:156
‪TYPO3\CMS\Frontend\Tests\Functional\Middleware\TypoScriptFrontendInitializationTest
Definition: TypoScriptFrontendInitializationTest.php:27