Browse Source

Fix header manipulation.

Convert headers from the format humans expect to the format PHP uses
internally.
mark_story 11 years ago
parent
commit
210fd89661

+ 5 - 1
src/TestSuite/IntegrationTestCase.php

@@ -226,7 +226,11 @@ class IntegrationTestCase extends TestCase {
 			'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;

+ 2 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -54,6 +54,7 @@ class IntegrationTestCaseTest extends IntegrationTestCase {
 		$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'));
@@ -70,6 +71,7 @@ class IntegrationTestCaseTest extends IntegrationTestCase {
 		$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());
 	}
 
 }