Skip to content

Commit

Permalink
Merge pull request #6481 from robbertnoordzij/fix-integrationtest-get
Browse files Browse the repository at this point in the history
Fix for query parameters in integration test
  • Loading branch information
markstory committed May 4, 2015
2 parents 62ad00c + f82bf59 commit 25092c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/TestSuite/IntegrationTestCase.php
Expand Up @@ -350,11 +350,13 @@ protected function _buildRequest($url, $method, $data)
$session = Session::create($sessionConfig);
$session->write($this->_session);

list ($url, $query) = $this->_url($url);
$props = [
'url' => Router::url($url),
'url' => $url,
'post' => $data,
'cookies' => $this->_cookie,
'session' => $session,
'query' => $query
];
$env = [];
if (isset($this->_request['headers'])) {
Expand All @@ -369,6 +371,25 @@ protected function _buildRequest($url, $method, $data)
return new Request($props);
}

/**
* Creates a valid request url and parameter array more like Request::_url()
*
* @param string|array $url The URL
* @return array Qualified URL and the query parameters
*/
protected function _url($url)
{
$url = Router::url($url);
$query = [];

if (strpos($url, '?') !== false) {
list($url, $parameters) = explode('?', $url, 2);
parse_str($parameters, $query);
}

return [$url, $query];
}

/**
* Fetches a view variable by name.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -72,6 +72,19 @@ public function testRequestBuilding()
$this->assertEquals('bar', $request->env('PHP_AUTH_PW'));
}

/**
* Test building a request, with query parameters
*
* @return void
*/
public function testRequestBuildingQueryParameters()
{
$request = $this->_buildRequest('/tasks/view?archived=yes', 'GET', []);

$this->assertEquals('/tasks/view?archived=yes', $request->here());
$this->assertEquals('yes', $request->query('archived'));
}

/**
* Test sending get requests.
*
Expand Down

0 comments on commit 25092c8

Please sign in to comment.