Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 f611ed0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -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));
Expand All @@ -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);

Expand Down Expand Up @@ -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];
Expand Down
11 changes: 8 additions & 3 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -238,7 +239,7 @@ public function testGetHttpServer()
*
* @return void
*/
public function testQueryStringHttpServer()
public function testGetQueryStringHttpServer()
{
$this->useHttpServer(true);

Expand All @@ -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());
}

/**
Expand Down

0 comments on commit f611ed0

Please sign in to comment.