Skip to content

Commit

Permalink
Fix issue with integration tests and Content-Type headers
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Jul 11, 2016
1 parent 3f89bfb commit bcf9539
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/TestSuite/IntegrationTestCase.php
Expand Up @@ -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']);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -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' => [
Expand All @@ -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']);
Expand Down

0 comments on commit bcf9539

Please sign in to comment.