Skip to content

Commit

Permalink
fix: populateGlobals for JSON and XML body format
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Freeman <libsys@hacktivista.org>
  • Loading branch information
michalsn and 3ynm committed Oct 4, 2024
1 parent 118c2c4 commit f5d98b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions system/Test/FeatureTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ protected function populateGlobals(string $name, Request $request, ?array $param

$request->setGlobal('get', $get);

if ($name === 'get') {
if ($name === 'get' || ($name === 'post' && in_array($this->bodyFormat, ['json', 'xml'], true))) {
$request->setGlobal('request', $request->fetchGlobal('get'));
}

if ($name === 'post') {
if ($name === 'post' && ! in_array($this->bodyFormat, ['json', 'xml'], true)) {
$request->setGlobal($name, $params);
$request->setGlobal(
'request',
Expand Down
22 changes: 21 additions & 1 deletion tests/system/Test/FeatureTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function testCallPutWithJsonRequestAndREQUEST(): void
$this->assertStringContainsString('[]', $response->getBody());
}

public function testCallWithJsonRequest(): void
public function testCallWithAssociativeJsonRequest(): void
{
$this->withRoutes([
[
Expand All @@ -581,6 +581,26 @@ public function testCallWithJsonRequest(): void
$response->assertJSONExact($data);
}

public function testCallWithListJsonRequest(): void
{
$this->withRoutes([
[
'POST',
'home',
'\Tests\Support\Controllers\Popcorn::echoJson',
],
]);
$data = [
['one' => 1, 'two' => 2],
['one' => 2, 'two' => 2],
];
$response = $this->withBodyFormat('json')
->call(Method::POST, 'home', $data);

$response->assertOK();
$response->assertJSONExact($data);
}

public function testSetupRequestBodyWithParams(): void
{
$request = $this->setupRequest('post', 'home');
Expand Down

0 comments on commit f5d98b8

Please sign in to comment.