Skip to content
Permalink
Browse files

Reworking parameter munging specific to requestAction into requestAct…

…ion. Updating tests cases for Object. As request->data is an array() not null. And leading / is trimmed off of [url][url].
  • Loading branch information...
markstory committed Nov 14, 2010
1 parent 55cc329 commit f02e0483ee5202aa26bfa857deaae078837d0e35
Showing with 23 additions and 35 deletions.
  1. +0 −27 cake/libs/dispatcher.php
  2. +16 −4 cake/libs/object.php
  3. +7 −4 cake/tests/cases/libs/object.test.php
@@ -87,19 +87,8 @@ public function __construct($url = null, $base = false) {
* are encountered.
*/
public function dispatch(CakeRequest $request, $additionalParams = array()) {
/* Should move to Object::requestAction()
if (is_array($url)) {
$url = $this->_extractParams($url, $additionalParams);
}
if ($url instanceof CakeRequest) {
$request = $url;
} else {
$request = new CakeRequest($url);
}
*/
$this->here = $request->here;
if ($this->asset($request->url) || $this->cached($request->url)) {
return;
}
@@ -180,22 +169,6 @@ protected function _invoke(&$controller, $request) {
$response->send();
}
/**
* Sets the params when $url is passed as an array to Object::requestAction();
* Merges the $url and $additionalParams and creates a string url.
*
* @param array $url Array or request parameters
* @param array $additionalParams Array of additional parameters.
* @return string $url The generated url string.
*/
protected function _extractParams($url, $additionalParams = array()) {
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
$params = array_merge($defaults, $url, $additionalParams);
$params += array('base' => false, 'url' => array());
return ltrim(Router::reverse($params), '/');
}
/**
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
*
@@ -67,17 +67,29 @@ public function requestAction($url, $extra = array()) {
return false;
}
if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php';
require LIBS . 'dispatcher.php';
}
if (in_array('return', $extra, true)) {
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
}
if (is_array($url) && !isset($extra['url'])) {
$extra['url'] = array();
}
$params = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$dispatcher = new Dispatcher;
return $dispatcher->dispatch($url, $params);
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
if (is_string($url)) {
$request = new CakeRequest($url);
} 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);
if (isset($params['data'])) {
$request->data = $params['data'];
}
}
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($request, $extra);
}
/**
@@ -716,7 +716,7 @@ function testRequestAction() {
$result = $this->object->requestAction('/request_action/normal_request_action');
$expected = 'Hello World';
$this->assertEqual($result, $expected);
App::build();
}
@@ -824,7 +824,7 @@ function testRequestActionArray() {
function testRequestActionParamParseAndPass() {
$result = $this->object->requestAction('/request_action/params_pass');
$this->assertTrue(isset($result['url']['url']));
$this->assertEqual($result['url']['url'], '/request_action/params_pass');
$this->assertEqual($result['url']['url'], 'request_action/params_pass');
$this->assertEqual($result['controller'], 'request_action');
$this->assertEqual($result['action'], 'params_pass');
$this->assertEqual($result['form'], array());
@@ -855,9 +855,12 @@ function testRequestActionPostPassing() {
));
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
$expected = null;
$this->assertEqual($expected, $result);
$this->assertEmpty($result);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data']));
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'post_pass'),
array('data' => $_POST['data'])
);
$expected = $_POST['data'];
$this->assertEqual($expected, $result);

0 comments on commit f02e048

Please sign in to comment.
You can’t perform that action at this time.