diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index 0f2467ffd897..ffbc780c6bce 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -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', diff --git a/tests/system/Test/FeatureTestTraitTest.php b/tests/system/Test/FeatureTestTraitTest.php index be3d590bd15a..cd1c845342f1 100644 --- a/tests/system/Test/FeatureTestTraitTest.php +++ b/tests/system/Test/FeatureTestTraitTest.php @@ -557,7 +557,7 @@ public function testCallPutWithJsonRequestAndREQUEST(): void $this->assertStringContainsString('[]', $response->getBody()); } - public function testCallWithJsonRequest(): void + public function testCallWithAssociativeJsonRequest(): void { $this->withRoutes([ [ @@ -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');