Skip to content

Commit

Permalink
Fix header manipulation.
Browse files Browse the repository at this point in the history
Convert headers from the format humans expect to the format PHP uses
internally.
  • Loading branch information
markstory committed Sep 2, 2014
1 parent 07d559a commit 210fd89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/TestSuite/IntegrationTestCase.php
Expand Up @@ -226,7 +226,11 @@ protected function _buildRequest($url, $method, $data) {
'session' => $session,
];
if (isset($this->_request['headers'])) {
$props['environment'] = $this->_request['headers'];
$env = [];
foreach ($this->_request['headers'] as $k => $v) {
$env['HTTP_' . str_replace('-', '_', strtoupper($k))] = $v;
}
$props['environment'] = $env;
unset($this->_request['headers']);
}
$props += $this->_request;
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -54,6 +54,7 @@ public function testRequestBuilding() {
$this->session(['User' => ['id' => 1, 'username' => 'mark']]);
$request = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'First post']);

$this->assertEquals('abc123', $request->header('X-CSRF-Token'));
$this->assertEquals('tasks/add', $request->url);
$this->assertEquals(['split_token' => 'def345'], $request->cookies);
$this->assertEquals(['id' => '1', 'username' => 'mark'], $request->session()->read('User'));
Expand All @@ -70,6 +71,7 @@ public function testSendingGet() {
$this->get('/request_action/test_request_action');
$this->assertNotEmpty($this->_response);
$this->assertInstanceOf('Cake\Network\Response', $this->_response);
$this->assertEquals('This is a test', $this->_response->body());
}

}

0 comments on commit 210fd89

Please sign in to comment.