‪TYPO3CMS  10.4
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 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
25 
30 {
35 
39  protected ‪$testExtensionsToLoad = [
40  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_eid',
41  ];
42 
43  public static function ‪setUpBeforeClass(): void
44  {
45  parent::setUpBeforeClass();
46  static::initializeDatabaseSnapshot();
47  }
48 
49  public static function ‪tearDownAfterClass(): void
50  {
51  static::destroyDatabaseSnapshot();
52  parent::tearDownAfterClass();
53  }
54 
55  protected function ‪setUp(): void
56  {
57  parent::setUp();
58 
59  // these settings are forwarded to the frontend sub-request as well
60  $this->internalRequestContext = (new InternalRequestContext())
61  ->withGlobalSettings(['TYPO3_CONF_VARS' => static::TYPO3_CONF_VARS]);
62 
63  $this->withDatabaseSnapshot(function () {
64  $this->‪setUpDatabase();
65  });
66  }
67 
68  protected function ‪setUpDatabase(): void
69  {
70  $backendUser = $this->setUpBackendUserFromFixture(1);
72 
73  $scenarioFile = __DIR__ . '/Fixtures/PlainScenario.yaml';
74  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
75  $writer = DataHandlerWriter::withBackendUser($backendUser);
76  $writer->invokeFactory($factory);
77  static::failIfArrayIsNotEmpty(
78  $writer->getErrors()
79  );
80 
81  $this->setUpFrontendRootPage(
82  1000,
83  [
84  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript',
85  'typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/JsonRenderer.typoscript',
86  ],
87  [
88  'title' => 'ACME Root',
89  ]
90  );
92  'website-local',
93  $this->‪buildSiteConfiguration(1000, 'https://website.local/')
94  );
95  }
96 
100  public function ‪ensureEidRequestsWorkDataProvider(): array
101  {
102  return [
103  'eid without index.php' => [
104  'https://website.local/?eID=test_eid&id=123&some_parameter=1',
105  200,
106  [
107  'content-type' => [
108  'application/json',
109  ],
110  'eid_responder' => [
111  'responded',
112  ],
113  ],
114  [
115  'eid_responder' => true,
116  'uri' => 'https://website.local/?eID=test_eid&id=123&some_parameter=1',
117  'method' => 'GET',
118  'queryParams' => [
119  'eID' => 'test_eid',
120  'id' => '123',
121  'some_parameter' => '1',
122  ],
123  ],
124  ],
125  'eid with index.php' => [
126  'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1',
127  200,
128  [
129  'content-type' => [
130  'application/json',
131  ],
132  'eid_responder' => [
133  'responded',
134  ],
135  ],
136  [
137  'eid_responder' => true,
138  'uri' => 'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1',
139  'method' => 'GET',
140  'queryParams' => [
141  'eID' => 'test_eid',
142  'id' => '123',
143  'some_parameter' => '1',
144  ],
145  ],
146  ],
147  'eid on slug page' => [
148  'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1',
149  200,
150  [
151  'content-type' => [
152  'application/json',
153  ],
154  'eid_responder' => [
155  'responded',
156  ],
157  ],
158  [
159  'eid_responder' => true,
160  'uri' => 'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1',
161  'method' => 'GET',
162  'queryParams' => [
163  'eID' => 'test_eid',
164  'id' => '123',
165  'some_parameter' => '1',
166  ],
167  ],
168  ],
169  'eid without index.php with type' => [
170  'https://website.local/?eID=test_eid&id=123&some_parameter=1&type=0',
171  200,
172  [
173  'content-type' => [
174  'application/json',
175  ],
176  'eid_responder' => [
177  'responded',
178  ],
179  ],
180  [
181  'eid_responder' => true,
182  'uri' => 'https://website.local/?eID=test_eid&id=123&some_parameter=1&type=0',
183  'method' => 'GET',
184  'queryParams' => [
185  'eID' => 'test_eid',
186  'id' => '123',
187  'some_parameter' => '1',
188  'type' => '0',
189  ],
190  ],
191  ],
192  'eid with index.php with type' => [
193  'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1&type=0',
194  200,
195  [
196  'content-type' => [
197  'application/json',
198  ],
199  'eid_responder' => [
200  'responded',
201  ],
202  ],
203  [
204  'eid_responder' => true,
205  'uri' => 'https://website.local/index.php?eID=test_eid&id=123&some_parameter=1&type=0',
206  'method' => 'GET',
207  'queryParams' => [
208  'eID' => 'test_eid',
209  'id' => '123',
210  'some_parameter' => '1',
211  'type' => '0',
212  ],
213  ],
214  ],
215  'eid on slug page with type' => [
216  'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1&type=0',
217  200,
218  [
219  'content-type' => [
220  'application/json',
221  ],
222  'eid_responder' => [
223  'responded',
224  ],
225  ],
226  [
227  'eid_responder' => true,
228  'uri' => 'https://website.local/en-welcome/?eID=test_eid&id=123&some_parameter=1&type=0',
229  'method' => 'GET',
230  'queryParams' => [
231  'eID' => 'test_eid',
232  'id' => '123',
233  'some_parameter' => '1',
234  'type' => '0',
235  ],
236  ],
237  ],
238  'eid with empty array as eID identifier' => [
239  'https://website.local/en-welcome/?eID[]=',
240  400,
241  [],
242  null,
243  ],
244  ];
245  }
246 
256  public function ‪ensureEidRequestsWork(
257  string $uri,
258  int $expectedStatusCode,
259  array $expectedHeaders,
260  ?array $expectedResponseData
261  ): void {
262  $response = $this->executeFrontendRequest(
263  new InternalRequest($uri),
264  $this->internalRequestContext
265  );
266 
267  self::assertSame($expectedStatusCode, $response->getStatusCode());
268  self::assertSame($expectedHeaders, $response->getHeaders());
269  if ($expectedResponseData !== null) {
270  self::assertSame($expectedResponseData, json_decode((string)$response->getBody(), true));
271  }
272  }
273 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\ensureEidRequestsWork
‪ensureEidRequestsWork(string $uri, int $expectedStatusCode, array $expectedHeaders, ?array $expectedResponseData)
Definition: EidRequestTest.php:254
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest
Definition: EidRequestTest.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\tearDownAfterClass
‪static tearDownAfterClass()
Definition: EidRequestTest.php:47
‪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:98
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\setUpBeforeClass
‪static setUpBeforeClass()
Definition: EidRequestTest.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\$testExtensionsToLoad
‪string[] $testExtensionsToLoad
Definition: EidRequestTest.php:37
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\setUpDatabase
‪setUpDatabase()
Definition: EidRequestTest.php:66
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\$internalRequestContext
‪InternalRequestContext $internalRequestContext
Definition: EidRequestTest.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:109
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EidRequestTest\setUp
‪setUp()
Definition: EidRequestTest.php:53