From bcf953952402e769dc244ef4c5caac8585dac27f Mon Sep 17 00:00:00 2001 From: Walther Lalk Date: Mon, 11 Jul 2016 11:45:56 +0200 Subject: [PATCH] Fix issue with integration tests and Content-Type headers --- src/TestSuite/IntegrationTestCase.php | 6 +++++- tests/TestCase/TestSuite/IntegrationTestCaseTest.php | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/TestSuite/IntegrationTestCase.php b/src/TestSuite/IntegrationTestCase.php index 1056c8b09d9..77037837c5d 100644 --- a/src/TestSuite/IntegrationTestCase.php +++ b/src/TestSuite/IntegrationTestCase.php @@ -448,7 +448,11 @@ protected function _buildRequest($url, $method, $data) $env = []; if (isset($this->_request['headers'])) { foreach ($this->_request['headers'] as $k => $v) { - $env['HTTP_' . str_replace('-', '_', strtoupper($k))] = $v; + $name = strtoupper(str_replace('-', '_', $k)); + if (!in_array($name, ['CONTENT_LENGTH', 'CONTENT_TYPE'])) { + $name = 'HTTP_' . $name; + } + $env[$name] = $v; } unset($this->_request['headers']); } diff --git a/tests/TestCase/TestSuite/IntegrationTestCaseTest.php b/tests/TestCase/TestSuite/IntegrationTestCaseTest.php index c60b1a15dc4..15397ef221e 100644 --- a/tests/TestCase/TestSuite/IntegrationTestCaseTest.php +++ b/tests/TestCase/TestSuite/IntegrationTestCaseTest.php @@ -53,7 +53,11 @@ public function setUp() public function testRequestBuilding() { $this->configRequest([ - 'headers' => ['X-CSRF-Token' => 'abc123'], + 'headers' => [ + 'X-CSRF-Token' => 'abc123', + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + ], 'base' => '', 'webroot' => '/', 'environment' => [ @@ -66,6 +70,7 @@ public function testRequestBuilding() $request = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'First post']); $this->assertEquals('abc123', $request->header('X-CSRF-Token')); + $this->assertEquals('application/json', $request->header('Content-Type')); $this->assertEquals('tasks/add', $request->url); $this->assertArrayHasKey('split_token', $request->cookies); $this->assertEquals('def345', $request->cookies['split_token']);