Skip to content

Commit

Permalink
Fix missing query arguments in array urls.
Browse files Browse the repository at this point in the history
Adding documented features that previously wasn't implemented.

Fixes #3328
  • Loading branch information
markstory committed Nov 2, 2012
1 parent 093275a commit 9ce7004
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/Cake/Core/Object.php
Expand Up @@ -73,9 +73,13 @@ public function requestAction($url, $extra = array()) {
$extra['autoRender'] = 1;
unset($extra[$index]);
}
if (is_array($url) && !isset($extra['url'])) {
$arrayUrl = is_array($url);
if ($arrayUrl && !isset($extra['url'])) {
$extra['url'] = array();
}
if ($arrayUrl && !isset($extra['data'])) {
$extra['data'] = array();
}
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$data = isset($extra['data']) ? $extra['data'] : null;
unset($extra['data']);
Expand All @@ -88,11 +92,12 @@ public function requestAction($url, $extra = array()) {
} elseif (is_array($url)) {
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
$params = array_merge($params, $extra);
$request = new CakeRequest(Router::reverse($params), false);
$request = new CakeRequest(Router::reverse($params));
}
if (isset($data)) {
$request->data = $data;
}

$dispatcher = new Dispatcher();
$result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
Router::popRequest();
Expand Down
19 changes: 18 additions & 1 deletion lib/Cake/Test/Case/Core/ObjectTest.php
Expand Up @@ -619,6 +619,24 @@ public function testRequestActionParamParseAndPass() {
$this->assertEquals($expected, $result['named']);
}

/**
* Test that requestAction handles get parameters correctly.
*
* @return void
*/
public function testRequestActionGetParameters() {
$result = $this->object->requestAction(
'/request_action/params_pass?get=value&limit=5'
);
$this->assertEquals('value', $result->query['get']);

$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'params_pass'),
array('url' => array('get' => 'value', 'limit' => 5))
);
$this->assertEquals('value', $result->query['get']);
}

/**
* test that requestAction does not fish data out of the POST
* superglobal.
Expand All @@ -632,7 +650,6 @@ public function testRequestActionNoPostPassing() {
'item' => 'value'
));
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
$expected = null;
$this->assertEmpty($result);

$result = $this->object->requestAction(
Expand Down

0 comments on commit 9ce7004

Please sign in to comment.