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