diff --git a/src/Symfony/Component/BrowserKit/HttpBrowser.php b/src/Symfony/Component/BrowserKit/HttpBrowser.php index a1e6dd9af0119..9c2b3fcf57e58 100644 --- a/src/Symfony/Component/BrowserKit/HttpBrowser.php +++ b/src/Symfony/Component/BrowserKit/HttpBrowser.php @@ -75,7 +75,7 @@ private function getBodyAndExtraHeaders(Request $request): array $fields = $request->getParameters(); if ($uploadedFiles = $this->getUploadedFiles($request->getFiles())) { - $part = new FormDataPart($uploadedFiles); + $part = new FormDataPart(array_merge($fields, $uploadedFiles)); return [$part->bodyToIterable(), $part->getPreparedHeaders()->toArray()]; } diff --git a/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php b/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php index fa3d531aa986d..77586f44e7744 100644 --- a/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php @@ -134,6 +134,28 @@ public function testMultiPartRequestWithInvalidItem() ]); } + public function testMultiPartRequestWithAdditionalParameters() + { + $client = $this->createMock(HttpClientInterface::class); + $this->expectClientToSendRequestWithFiles($client, ['file1_content', 'baz']); + + $browser = new HttpBrowser($client); + $browser->request('POST', 'http://example.com/', ['bar' => 'baz'], [ + 'file1' => $this->getUploadedFile('file1'), + ]); + } + + public function testMultiPartRequestWithAdditionalParametersOfTheSameName() + { + $client = $this->createMock(HttpClientInterface::class); + $this->expectClientToNotSendRequestWithFiles($client, ['baz']); + + $browser = new HttpBrowser($client); + $browser->request('POST', 'http://example.com/', ['file1' => 'baz'], [ + 'file1' => $this->getUploadedFile('file1'), + ]); + } + private function uploadFile(string $data): string { $path = tempnam(sys_get_temp_dir(), 'http'); @@ -167,4 +189,22 @@ protected function expectClientToSendRequestWithFiles(HttpClientInterface $clien })) ->willReturn($this->createMock(ResponseInterface::class)); } + + protected function expectClientToNotSendRequestWithFiles(HttpClientInterface $client, $fileContents) + { + $client + ->expects($this->once()) + ->method('request') + ->with('POST', 'http://example.com/', $this->callback(function ($options) use ($fileContents) { + $this->assertStringContainsString('Content-Type: multipart/form-data', implode('', $options['headers'])); + $this->assertInstanceOf('\Generator', $options['body']); + $body = implode('', iterator_to_array($options['body'], false)); + foreach ($fileContents as $content) { + $this->assertStringNotContainsString($content, $body); + } + + return true; + })) + ->willReturn($this->createMock(ResponseInterface::class)); + } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: