Permalink
Browse files

Fix incorrect PSR7 request target.

The IntegrationTestCase was not setting the correct server keys to set
the URI state correctly for PSR7 methods.

Refs #10800
  • Loading branch information...
markstory committed Jun 22, 2017
1 parent 42d4388 commit f611ed0fa8c76348d456633bb65725cf90bb866f
Showing with 18 additions and 10 deletions.
  1. +10 −7 src/TestSuite/IntegrationTestCase.php
  2. +8 −3 tests/TestCase/TestSuite/IntegrationTestCaseTest.php
@@ -548,20 +548,25 @@ protected function _buildRequest($url, $method, $data)
$tokenUrl = $url;
if ($query) {
$tokenUrl .= '?' . http_build_query($query);
$tokenUrl .= '?' . $query;
}
parse_str($query, $queryData);
$props = [
'url' => $url,
'post' => $this->_addTokens($tokenUrl, $data),
'cookies' => $this->_cookie,
'session' => $session,
'query' => $query
'query' => $queryData
];
if (is_string($data)) {
$props['input'] = $data;
}
$env = [];
$env = [
'REQUEST_METHOD' => $method,
'QUERY_STRING' => $query,
'REQUEST_URI' => $url,
];
if (isset($this->_request['headers'])) {
foreach ($this->_request['headers'] as $k => $v) {
$name = strtoupper(str_replace('-', '_', $k));
@@ -572,7 +577,6 @@ protected function _buildRequest($url, $method, $data)
}
unset($this->_request['headers']);
}
$env['REQUEST_METHOD'] = $method;
$props['environment'] = $env;
$props = Hash::merge($props, $this->_request);
@@ -618,11 +622,10 @@ protected function _addTokens($url, $data)
protected function _url($url)
{
$url = Router::url($url);
$query = [];
$query = '';
if (strpos($url, '?') !== false) {
list($url, $parameters) = explode('?', $url, 2);
parse_str($parameters, $query);
list($url, $query) = explode('?', $url, 2);
}
return [$url, $query];
@@ -151,8 +151,9 @@ public function testRequestBuildingQueryParameters()
{
$request = $this->_buildRequest('/tasks/view?archived=yes', 'GET', []);
$this->assertEquals('/tasks/view', $request['url']);
$this->assertEquals('yes', $request['query']['archived']);
$this->assertSame('/tasks/view', $request['url']);
$this->assertSame('archived=yes', $request['environment']['QUERY_STRING']);
$this->assertSame('/tasks/view', $request['environment']['REQUEST_URI']);
}
/**
@@ -238,7 +239,7 @@ public function testGetHttpServer()
*
* @return void
*/
public function testQueryStringHttpServer()
public function testGetQueryStringHttpServer()
{
$this->useHttpServer(true);
@@ -248,6 +249,10 @@ public function testQueryStringHttpServer()
$this->assertResponseContains('"q":"query"');
$this->assertResponseContains('"contentType":"text\/plain"');
$this->assertHeader('X-Middleware', 'true');
$request = $this->_controller->request;
$this->assertContains('/request_action/params_pass?q=query', $request->here());
$this->assertContains('/request_action/params_pass?q=query', $request->getRequestTarget());
}
/**

0 comments on commit f611ed0

Please sign in to comment.