‪TYPO3CMS  ‪main
EidRequestTest.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;
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
24 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
26 
28 {
29  protected array ‪$testExtensionsToLoad = [
30  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_eid',
31  ];
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->withDatabaseSnapshot(function () {
37  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
38  $backendUser = $this->setUpBackendUser(1);
39  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
40  $scenarioFile = __DIR__ . '/Fixtures/PlainScenario.yaml';
41  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
42  $writer = DataHandlerWriter::withBackendUser($backendUser);
43  $writer->invokeFactory($factory);
44  static::failIfArrayIsNotEmpty(
45  $writer->getErrors()
46  );
47  });
48  }
49 
50  public static function ‪ensureEidRequestsWorkDataProvider(): array
51  {
52  return [
53  'eid without index.php' => [
54  'https://website.local/?eID=test_eid&id=123&some_parameter=1',
55  200,
56  [
57  'content-type' => [
58  'application/json',
59  ],
60  'eid_responder' => [
61  'responded',
62  ],
63  ],
64  [
65  'eid_responder' => true,
66  'uri' => 'https://website.local/?eID=test_eid&id=123&some_parameter=1',
67  'method' => 'GET',
68  'queryParams' => [
69  'eID' => 'test_eid',
70  'id' => '123',
71  'some_parameter' => '1',
72  ],
73  ],
74  ],
75  'eid with index.php' => [
76  'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1',
77  200,
78  [
79  'content-type' => [
80  'application/json',
81  ],
82  'eid_responder' => [
83  'responded',
84  ],
85  ],
86  [
87  'eid_responder' => true,
88  'uri' => 'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1',
89  'method' => 'GET',
90  'queryParams' => [
91  'eID' => 'test_eid',
92  'id' => '123',
93  'some_parameter' => '1',
94  ],
95  ],
96  ],
97  'eid on slug page' => [
98  'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1',
99  200,
100  [
101  'content-type' => [
102  'application/json',
103  ],
104  'eid_responder' => [
105  'responded',
106  ],
107  ],
108  [
109  'eid_responder' => true,
110  'uri' => 'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1',
111  'method' => 'GET',
112  'queryParams' => [
113  'eID' => 'test_eid',
114  'id' => '123',
115  'some_parameter' => '1',
116  ],
117  ],
118  ],
119  'eid without index.php with type' => [
120  'https://website.local/?eID=test_eid&id=123&some_parameter=1&type=0',
121  200,
122  [
123  'content-type' => [
124  'application/json',
125  ],
126  'eid_responder' => [
127  'responded',
128  ],
129  ],
130  [
131  'eid_responder' => true,
132  'uri' => 'https://website.local/?eID=test_eid&id=123&some_parameter=1&type=0',
133  'method' => 'GET',
134  'queryParams' => [
135  'eID' => 'test_eid',
136  'id' => '123',
137  'some_parameter' => '1',
138  'type' => '0',
139  ],
140  ],
141  ],
142  'eid with index.php with type' => [
143  'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1&type=0',
144  200,
145  [
146  'content-type' => [
147  'application/json',
148  ],
149  'eid_responder' => [
150  'responded',
151  ],
152  ],
153  [
154  'eid_responder' => true,
155  'uri' => 'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1&type=0',
156  'method' => 'GET',
157  'queryParams' => [
158  'eID' => 'test_eid',
159  'id' => '123',
160  'some_parameter' => '1',
161  'type' => '0',
162  ],
163  ],
164  ],
165  'eid on slug page with type' => [
166  'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1&type=0',
167  200,
168  [
169  'content-type' => [
170  'application/json',
171  ],
172  'eid_responder' => [
173  'responded',
174  ],
175  ],
176  [
177  'eid_responder' => true,
178  'uri' => 'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1&type=0',
179  'method' => 'GET',
180  'queryParams' => [
181  'eID' => 'test_eid',
182  'id' => '123',
183  'some_parameter' => '1',
184  'type' => '0',
185  ],
186  ],
187  ],
188  'eid with empty array as eID identifier' => [
189  'https://website.local/en-welcome/?eID[]=',
190  400,
191  [],
192  null,
193  ],
194  // without id/type parameters
195  'eid with index.php without id parameter' => [
196  'https://website.local/index.php?eID=test_eid&some_parameter=1',
197  200,
198  [
199  'content-type' => [
200  'application/json',
201  ],
202  'eid_responder' => [
203  'responded',
204  ],
205  ],
206  [
207  'eid_responder' => true,
208  'uri' => 'https://website.local/index.php?eID=test_eid&some_parameter=1',
209  'method' => 'GET',
210  'queryParams' => [
211  'eID' => 'test_eid',
212  'some_parameter' => '1',
213  ],
214  ],
215  ],
216  'eid on slug page without id parameter' => [
217  'https://website.local/en-welcome/?eID=test_eid&some_parameter=1',
218  200,
219  [
220  'content-type' => [
221  'application/json',
222  ],
223  'eid_responder' => [
224  'responded',
225  ],
226  ],
227  [
228  'eid_responder' => true,
229  'uri' => 'https://website.local/en-welcome/?eID=test_eid&some_parameter=1',
230  'method' => 'GET',
231  'queryParams' => [
232  'eID' => 'test_eid',
233  'some_parameter' => '1',
234  ],
235  ],
236  ],
237  'eid without index.php with type without id parameter' => [
238  'https://website.local/?eID=test_eid&some_parameter=1&type=0',
239  200,
240  [
241  'content-type' => [
242  'application/json',
243  ],
244  'eid_responder' => [
245  'responded',
246  ],
247  ],
248  [
249  'eid_responder' => true,
250  'uri' => 'https://website.local/?eID=test_eid&some_parameter=1&type=0',
251  'method' => 'GET',
252  'queryParams' => [
253  'eID' => 'test_eid',
254  'some_parameter' => '1',
255  'type' => '0',
256  ],
257  ],
258  ],
259  'eid with index.php with type without id parameter' => [
260  'https://website.local/index.php?eID=test_eid&some_parameter=1&type=0',
261  200,
262  [
263  'content-type' => [
264  'application/json',
265  ],
266  'eid_responder' => [
267  'responded',
268  ],
269  ],
270  [
271  'eid_responder' => true,
272  'uri' => 'https://website.local/index.php?eID=test_eid&some_parameter=1&type=0',
273  'method' => 'GET',
274  'queryParams' => [
275  'eID' => 'test_eid',
276  'some_parameter' => '1',
277  'type' => '0',
278  ],
279  ],
280  ],
281  'eid on slug page with type without id parameter' => [
282  'https://website.local/en-welcome/?eID=test_eid&some_parameter=1&type=0',
283  200,
284  [
285  'content-type' => [
286  'application/json',
287  ],
288  'eid_responder' => [
289  'responded',
290  ],
291  ],
292  [
293  'eid_responder' => true,
294  'uri' => 'https://website.local/en-welcome/?eID=test_eid&some_parameter=1&type=0',
295  'method' => 'GET',
296  'queryParams' => [
297  'eID' => 'test_eid',
298  'some_parameter' => '1',
299  'type' => '0',
300  ],
301  ],
302  ],
303  ];
304  }
305 
306  #[DataProvider('ensureEidRequestsWorkDataProvider')]
307  #[Test]
308  public function ‪ensureEidRequestsWork(
309  string $uri,
310  int $expectedStatusCode,
311  array $expectedHeaders,
312  ?array $expectedResponseData
313  ): void {
314  $this->setUpFrontendRootPage(
315  1000,
316  [
317  'EXT:core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript',
318  'EXT:frontend/Tests/Functional/SiteHandling/Fixtures/JsonRenderer.typoscript',
319  ],
320  [
321  'title' => 'ACME Root',
322  ]
323  );
325  'website-local',
326  $this->‪buildSiteConfiguration(1000, 'https://website.local/')
327  );
328 
329  $response = $this->executeFrontendSubRequest(new InternalRequest($uri));
330  self::assertSame($expectedStatusCode, $response->getStatusCode());
331  self::assertSame($expectedHeaders, $response->getHeaders());
332  if ($expectedResponseData !== null) {
333  self::assertSame($expectedResponseData, json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR));
334  }
335  }
336 
337  #[DataProvider('ensureEidRequestsWorkDataProvider')]
338  #[Test]
340  string $uri,
341  int $expectedStatusCode,
342  array $expectedHeaders,
343  ?array $expectedResponseData
344  ): void {
345  $this->setUpFrontendRootPage(
346  1000,
347  [
348  'EXT:core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript',
349  'EXT:frontend/Tests/Functional/SiteHandling/Fixtures/JsonRenderer.typoscript',
350  ],
351  [
352  'title' => 'ACME Root',
353  ]
354  );
356  'website-local',
357  array_replace(
358  $this->‪buildSiteConfiguration(1000, 'https://website.local/'),
359  [
360  'routeEnhancers' => [
361  'PageTypeSuffix' => [
362  'type' => 'PageType',
363  'default' => '.php',
364  'index' => 'index',
365  'map' => [],
366  ],
367  ],
368  ]
369  )
370  );
371 
372  $response = $this->executeFrontendSubRequest(new InternalRequest($uri));
373  self::assertSame($expectedStatusCode, $response->getStatusCode());
374  self::assertSame($expectedHeaders, $response->getHeaders());
375  if ($expectedResponseData !== null) {
376  self::assertSame($expectedResponseData, json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR));
377  }
378  }
379 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\ensureEidRequestsWork
‪ensureEidRequestsWork(string $uri, int $expectedStatusCode, array $expectedHeaders, ?array $expectedResponseData)
Definition: EidRequestTest.php:308
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest
Definition: EidRequestTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\ensureEidRequestsWorkWithDotPhpPageTypeSuffixRoutingConfiguration
‪ensureEidRequestsWorkWithDotPhpPageTypeSuffixRoutingConfiguration(string $uri, int $expectedStatusCode, array $expectedHeaders, ?array $expectedResponseData)
Definition: EidRequestTest.php:339
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\ensureEidRequestsWorkDataProvider
‪static ensureEidRequestsWorkDataProvider()
Definition: EidRequestTest.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\setUp
‪setUp()
Definition: EidRequestTest.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: EidRequestTest.php:29