Commit 47227c57 authored by Stefan Bürk's avatar Stefan Bürk
Browse files

[TASK] Raise typo3/testing-framework

Along some minor changes, TF frontend requests now directly
submit the InternalRequest to the core's application chain
without explicitly transitioning them to a ServerRequestInterface
since TF InternalRequest now directly extends core's ServerRequest.

This simplifies the class chain and is the general way to go.

* tests are adjusted to test against adjusted sync between
  'body' and 'parsedBody'
* tests added for request uri query arguments and request
  queryParams syncronization in different constellations

See: https://github.com/TYPO3/testing-framework/pull/355

Used commands:

> composer u typo3/testing-framework

Resolves: #97256
Releases: main
Change-Id: I21f573933f3b853eeeda9d7b00b5702bf9c6ac3a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73990

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent 255bbd79
...@@ -8315,20 +8315,21 @@ ...@@ -8315,20 +8315,21 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/TYPO3/testing-framework.git", "url": "https://github.com/TYPO3/testing-framework.git",
"reference": "e515477b848bd6fb10e0f5244909aae6b5b88a56" "reference": "85eb4fbccacdf04c26d78828b2b93d0b61db280b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/e515477b848bd6fb10e0f5244909aae6b5b88a56", "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/85eb4fbccacdf04c26d78828b2b93d0b61db280b",
"reference": "e515477b848bd6fb10e0f5244909aae6b5b88a56", "reference": "85eb4fbccacdf04c26d78828b2b93d0b61db280b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-pdo": "*",
"guzzlehttp/psr7": "^1.7 || ^2.0", "guzzlehttp/psr7": "^1.7 || ^2.0",
"mikey179/vfsstream": "~1.6.10", "mikey179/vfsstream": "~1.6.10",
"php": "^8.1", "php": "^8.1",
"phpunit/phpunit": "^9.5.10", "phpunit/phpunit": "^9.5.10",
"psr/container": "^1.0", "psr/container": "^1.1.0 || ^2.0.0",
"typo3/cms-backend": "12.*.*@dev", "typo3/cms-backend": "12.*.*@dev",
"typo3/cms-core": "12.*.*@dev", "typo3/cms-core": "12.*.*@dev",
"typo3/cms-extbase": "12.*.*@dev", "typo3/cms-extbase": "12.*.*@dev",
...@@ -8342,7 +8343,8 @@ ...@@ -8342,7 +8343,8 @@
"doctrine/dbal": "2.13.0 || 2.13.1" "doctrine/dbal": "2.13.0 || 2.13.1"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^1.4.6", "phpstan/phpstan": "^1.6.7",
"phpstan/phpstan-phpunit": "^1.1.1",
"typo3/cms-workspaces": "12.*.*@dev", "typo3/cms-workspaces": "12.*.*@dev",
"typo3/coding-standards": "^0.5.0" "typo3/coding-standards": "^0.5.0"
}, },
...@@ -8382,7 +8384,7 @@ ...@@ -8382,7 +8384,7 @@
"issues": "https://github.com/TYPO3/testing-framework/issues", "issues": "https://github.com/TYPO3/testing-framework/issues",
"source": "https://github.com/TYPO3/testing-framework/tree/main" "source": "https://github.com/TYPO3/testing-framework/tree/main"
}, },
"time": "2022-03-04T16:38:27+00:00" "time": "2022-05-09T22:35:11+00:00"
} }
], ],
"aliases": [], "aliases": [],
......
...@@ -37,7 +37,7 @@ class RequestMirror implements MiddlewareInterface ...@@ -37,7 +37,7 @@ class RequestMirror implements MiddlewareInterface
->withHeader('Content-type', 'application/json') ->withHeader('Content-type', 'application/json')
->withBody(GeneralUtility::makeInstance(StreamFactoryInterface::class)->createStream(\json_encode( ->withBody(GeneralUtility::makeInstance(StreamFactoryInterface::class)->createStream(\json_encode(
[ [
'uri' => $request->getUri(), 'uri' => (string)$request->getUri(),
'method' => $request->getMethod(), 'method' => $request->getMethod(),
'headers' => $request->getHeaders(), 'headers' => $request->getHeaders(),
'queryParams' => $request->getQueryParams(), 'queryParams' => $request->getQueryParams(),
......
...@@ -33,6 +33,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -33,6 +33,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'POST parsedBody(_POST) as parsedBody' => [ yield 'POST parsedBody(_POST) as parsedBody' => [
'uri' => 'https://acme.com/request-mirror', 'uri' => 'https://acme.com/request-mirror',
'method' => 'POST', 'method' => 'POST',
'queryParams' => [],
'parsedBody' => ['param1' => 'value1'], 'parsedBody' => ['param1' => 'value1'],
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -42,12 +43,12 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -42,12 +43,12 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'method' => 'POST', 'method' => 'POST',
'parsedBody' => ['param1' => 'value1'], 'parsedBody' => ['param1' => 'value1'],
'queryParams' => [], 'queryParams' => [],
'body' => '', 'body' => \GuzzleHttp\Psr7\Query::build(['param1' => 'value1']),
'headers' => [ 'headers' => [
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -56,6 +57,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -56,6 +57,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'PATCH body as parsedBody' => [ yield 'PATCH body as parsedBody' => [
'uri' => 'https://acme.com/request-mirror', 'uri' => 'https://acme.com/request-mirror',
'method' => 'PATCH', 'method' => 'PATCH',
'queryParams' => [],
'parsedBody' => null, 'parsedBody' => null,
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -70,7 +72,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -70,7 +72,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -79,6 +81,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -79,6 +81,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'PUT body as parsedBody' => [ yield 'PUT body as parsedBody' => [
'uri' => 'https://acme.com/request-mirror', 'uri' => 'https://acme.com/request-mirror',
'method' => 'PUT', 'method' => 'PUT',
'queryParams' => [],
'parsedBody' => null, 'parsedBody' => null,
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -93,7 +96,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -93,7 +96,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -102,6 +105,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -102,6 +105,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'DELETE body as parsedBody' => [ yield 'DELETE body as parsedBody' => [
'uri' => 'https://acme.com/request-mirror', 'uri' => 'https://acme.com/request-mirror',
'method' => 'DELETE', 'method' => 'DELETE',
'queryParams' => [],
'parsedBody' => null, 'parsedBody' => null,
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -116,7 +120,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -116,7 +120,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -125,6 +129,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -125,6 +129,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'POST parsedBody(_POST) as parsedBody and queryParams' => [ yield 'POST parsedBody(_POST) as parsedBody and queryParams' => [
'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1', 'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1',
'method' => 'POST', 'method' => 'POST',
'queryParams' => [],
'parsedBody' => ['param1' => 'value1'], 'parsedBody' => ['param1' => 'value1'],
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -134,12 +139,12 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -134,12 +139,12 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'method' => 'POST', 'method' => 'POST',
'parsedBody' => ['param1' => 'value1'], 'parsedBody' => ['param1' => 'value1'],
'queryParams' => ['queryParam1' => 'queryValue1'], 'queryParams' => ['queryParam1' => 'queryValue1'],
'body' => '', 'body' => \GuzzleHttp\Psr7\Query::build(['param1' => 'value1']),
'headers' => [ 'headers' => [
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -148,6 +153,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -148,6 +153,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'PATCH body as parsedBody and queryParams' => [ yield 'PATCH body as parsedBody and queryParams' => [
'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1', 'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1',
'method' => 'PATCH', 'method' => 'PATCH',
'queryParams' => [],
'parsedBody' => null, 'parsedBody' => null,
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -162,7 +168,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -162,7 +168,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -171,6 +177,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -171,6 +177,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'PUT body as parsedBody and queryParams' => [ yield 'PUT body as parsedBody and queryParams' => [
'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1', 'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1',
'method' => 'PUT', 'method' => 'PUT',
'queryParams' => [],
'parsedBody' => null, 'parsedBody' => null,
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -185,7 +192,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -185,7 +192,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -194,6 +201,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -194,6 +201,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
yield 'DELETE body as parsedBody and queryParams' => [ yield 'DELETE body as parsedBody and queryParams' => [
'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1', 'uri' => 'https://acme.com/request-mirror?queryParam1=queryValue1',
'method' => 'DELETE', 'method' => 'DELETE',
'queryParams' => [],
'parsedBody' => null, 'parsedBody' => null,
'headers' => [ 'headers' => [
'Content-type' => 'application/x-www-form-urlencoded', 'Content-type' => 'application/x-www-form-urlencoded',
...@@ -208,7 +216,67 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -208,7 +216,67 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
'Content-type' => [ 'Content-type' => [
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
], ],
'host' => [ 'Host' => [
'acme.com',
],
],
],
];
yield 'GET missing parsedParams filled from request query' => [
'uri' => 'https://acme.com/request-mirror?queryParam1=value1',
'method' => 'GET',
'queryParams' => [],
'parsedBody' => null,
[],
'body' => null,
'expectedJsonKeyValues' => [
'method' => 'GET',
'uri' => 'https://acme.com/request-mirror?queryParam1=value1',
'queryParams' => ['queryParam1' => 'value1'],
'body' => '',
'headers' => [
'Host' => [
'acme.com',
],
],
],
];
yield 'GET added missing request uri query arguments from queryParams' => [
'uri' => 'https://acme.com/request-mirror',
'method' => 'GET',
'queryParams' => ['queryParam1' => 'value1'],
'parsedBody' => null,
[],
'body' => null,
'expectedJsonKeyValues' => [
'method' => 'GET',
'uri' => 'https://acme.com/request-mirror?queryParam1=value1',
'queryParams' => ['queryParam1' => 'value1'],
'body' => '',
'headers' => [
'Host' => [
'acme.com',
],
],
],
];
yield 'GET request uri queryParams and queryParams are merged' => [
'uri' => 'https://acme.com/request-mirror?queryParam2=value2',
'method' => 'GET',
'queryParams' => ['queryParam1' => 'value1'],
'parsedBody' => null,
[],
'body' => null,
'expectedJsonKeyValues' => [
'method' => 'GET',
'uri' => 'https://acme.com/request-mirror?queryParam1=value1&queryParam2=value2',
'queryParams' => [
'queryParam1' => 'value1',
'queryParam2' => 'value2',
],
'body' => '',
'headers' => [
'Host' => [
'acme.com', 'acme.com',
], ],
], ],
...@@ -223,10 +291,18 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -223,10 +291,18 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
* @test * @test
* @dataProvider ensureRequestMappingWorksDataProvider * @dataProvider ensureRequestMappingWorksDataProvider
*/ */
public function ensureRequestMappingWorks(string $uri, string $method, ?array $parsedBody, array $headers, ?string $body, array $expectedJsonKeyValues): void public function ensureRequestMappingWorks(
{ string $uri,
string $method,
array $queryParams,
?array $parsedBody,
array $headers,
?string $body,
array $expectedJsonKeyValues
): void {
$request = (new InternalRequest($uri)) $request = (new InternalRequest($uri))
->withMethod($method) ->withMethod($method)
->withQueryParams($queryParams)
->withParsedBody($parsedBody); ->withParsedBody($parsedBody);
foreach ($headers as $headerName => $headerValue) { foreach ($headers as $headerName => $headerValue) {
$request = $request->withAddedHeader($headerName, $headerValue); $request = $request->withAddedHeader($headerName, $headerValue);
...@@ -241,7 +317,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase ...@@ -241,7 +317,7 @@ class InternalRequestDataMappingTest extends FunctionalTestCase
self::assertSame(200, $response->getStatusCode()); self::assertSame(200, $response->getStatusCode());
$json = json_decode((string)$response->getBody(), null, 512, JSON_THROW_ON_ERROR | JSON_OBJECT_AS_ARRAY); $json = json_decode((string)$response->getBody(), null, 512, JSON_THROW_ON_ERROR | JSON_OBJECT_AS_ARRAY);
foreach ($expectedJsonKeyValues as $expectedKey => $expectedValue) { foreach ($expectedJsonKeyValues as $expectedKey => $expectedValue) {
self::assertSame($expectedValue, $json[$expectedKey] ?? null); self::assertSame($expectedValue, $json[$expectedKey] ?? null, 'Field "' . $expectedKey . '" must match value');
} }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment