Updating some uses of Router::setRequestInfo().

This commit is contained in:
Mark Story 2010-05-02 01:43:37 -04:00
parent 9a1858367f
commit e336df6de8
3 changed files with 263 additions and 178 deletions

View file

@ -138,9 +138,7 @@ class Dispatcher extends Object {
} }
} }
Router::setRequestInfo(array( Router::setRequestInfo($request);
$request->params, array('base' => $request->base, 'here' => $request->here, 'webroot' => $request->webroot)
));
if ($privateAction) { if ($privateAction) {
return $this->cakeError('privateAction', array(array( return $this->cakeError('privateAction', array(array(

View file

@ -594,20 +594,23 @@ class Router {
* @param array $params Parameters and path information * @param array $params Parameters and path information
* @return void * @return void
*/ */
public static function setRequestInfo($params) { public static function setRequestInfo(CakeRequest $request) {
$self =& Router::getInstance(); $self = Router::getInstance();
$defaults = array('plugin' => null, 'controller' => null, 'action' => null); $self->__params[] = $request;
$params[0] = array_merge($defaults, (array)$params[0]); }
$params[1] = array_merge($defaults, (array)$params[1]);
list($self->__params[], $self->__paths[]) = $params;
if (count($self->__paths)) { /**
if (isset($self->__paths[0]['namedArgs'])) { * Get the either the current request object, or the first one.
foreach ($self->__paths[0]['namedArgs'] as $arg => $value) { *
$self->named['rules'][$arg] = true; * @param boolean $current Whether you want the request from the top of the stack or the first one.
} * @return CakeRequest or null.
} */
public static function getRequest($current = false) {
$self = Router::getInstance();
if ($current) {
return $self->__params[count($self->__params) - 1];
} }
return isset($self->__params[0]) ? $self->__params[0] : null;
} }
/** /**
@ -617,7 +620,7 @@ class Router {
* @return array Parameter information * @return array Parameter information
*/ */
public static function getParams($current = false) { public static function getParams($current = false) {
$self =& Router::getInstance(); $self = Router::getInstance();
if ($current) { if ($current) {
return $self->__params[count($self->__params) - 1]; return $self->__params[count($self->__params) - 1];
} }
@ -649,14 +652,14 @@ class Router {
* @return array * @return array
*/ */
public static function getPaths($current = false) { public static function getPaths($current = false) {
$self =& Router::getInstance(); $self = Router::getInstance();
if ($current) { if ($current) {
return $self->__paths[count($self->__paths) - 1]; return $self->__params[count($self->__params) - 1];
} }
if (!isset($self->__paths[0])) { if (!isset($self->__params[0])) {
return array('base' => null); return array('base' => null);
} }
return $self->__paths[0]; return array('base' => $self->__params[0]->base);
} }
/** /**
@ -666,7 +669,7 @@ class Router {
* @return void * @return void
*/ */
public static function reload() { public static function reload() {
$self =& Router::getInstance(); $self = Router::getInstance();
foreach (get_class_vars('Router') as $key => $val) { foreach (get_class_vars('Router') as $key => $val) {
$self->{$key} = $val; $self->{$key} = $val;
} }
@ -681,7 +684,7 @@ class Router {
* @return boolean Retuns false if no route exists at the position specified by $which. * @return boolean Retuns false if no route exists at the position specified by $which.
*/ */
public static function promote($which = null) { public static function promote($which = null) {
$self =& Router::getInstance(); $self = Router::getInstance();
if ($which === null) { if ($which === null) {
$which = count($self->routes) - 1; $which = count($self->routes) - 1;
} }
@ -724,7 +727,7 @@ class Router {
* @return string Full translated URL with base path. * @return string Full translated URL with base path.
*/ */
public static function url($url = null, $full = false) { public static function url($url = null, $full = false) {
$self =& Router::getInstance(); $self = Router::getInstance();
$defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index'); $defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index');
if (is_bool($full)) { if (is_bool($full)) {
@ -733,22 +736,18 @@ class Router {
extract($full + array('escape' => false, 'full' => false)); extract($full + array('escape' => false, 'full' => false));
} }
if (!empty($self->__params)) {
if (isset($this) && !isset($this->params['requested'])) {
$params = $self->__params[0];
} else {
$params = end($self->__params);
}
}
$path = array('base' => null); $path = array('base' => null);
if (!empty($self->__params)) {
if (!empty($self->__paths)) { // bad hack for detecting if doing a request action.
if (isset($this) && !isset($this->params['requested'])) { if (isset($this) && !isset($this->params['requested'])) {
$path = $self->__paths[0]; $request = $self->__params[0];
} else { } else {
$path = end($self->__paths); $request = end($self->__params);
} }
$params = $request->params;
$path = array('base' => $request->base, 'here' => $request->here);
} }
$base = $path['base']; $base = $path['base'];
$extension = $output = $mapped = $q = $frag = null; $extension = $output = $mapped = $q = $frag = null;
@ -1038,10 +1037,10 @@ class Router {
} elseif (preg_match('/^[a-z\-]+:\/\//', $url)) { } elseif (preg_match('/^[a-z\-]+:\/\//', $url)) {
return $url; return $url;
} }
$paths = Router::getPaths(); $request = Router::getRequest();
if (!empty($paths['base']) && stristr($url, $paths['base'])) { if (!empty($request->base) && stristr($url, $request->base)) {
$url = preg_replace('/^' . preg_quote($paths['base'], '/') . '/', '', $url, 1); $url = preg_replace('/^' . preg_quote($request->base, '/') . '/', '', $url, 1);
} }
$url = '/' . $url; $url = '/' . $url;

View file

@ -212,13 +212,17 @@ class RouterTest extends CakeTestCase {
$result = Router::normalize('/recipe/recipes/add'); $result = Router::normalize('/recipe/recipes/add');
$this->assertEqual($result, '/recipe/recipes/add'); $this->assertEqual($result, '/recipe/recipes/add');
Router::setRequestInfo(array(array(), array('base' => '/us'))); $request = new CakeRequest();
$request->base = '/us';
Router::setRequestInfo($request);
$result = Router::normalize('/us/users/logout/'); $result = Router::normalize('/us/users/logout/');
$this->assertEqual($result, '/users/logout'); $this->assertEqual($result, '/users/logout');
Router::reload(); Router::reload();
Router::setRequestInfo(array(array(), array('base' => '/cake_12'))); $request = new CakeRequest();
$request->base = '/cake_12';
Router::setRequestInfo($request);
$result = Router::normalize('/cake_12/users/logout/'); $result = Router::normalize('/cake_12/users/logout/');
$this->assertEqual($result, '/users/logout'); $this->assertEqual($result, '/users/logout');
@ -226,13 +230,17 @@ class RouterTest extends CakeTestCase {
$_back = Configure::read('App.baseUrl'); $_back = Configure::read('App.baseUrl');
Configure::write('App.baseUrl', '/'); Configure::write('App.baseUrl', '/');
Router::setRequestInfo(array(array(), array('base' => '/'))); $request = new CakeRequest();
$request->base = '/';
Router::setRequestInfo($request);
$result = Router::normalize('users/login'); $result = Router::normalize('users/login');
$this->assertEqual($result, '/users/login'); $this->assertEqual($result, '/users/login');
Configure::write('App.baseUrl', $_back); Configure::write('App.baseUrl', $_back);
Router::reload(); Router::reload();
Router::setRequestInfo(array(array(), array('base' => 'beer'))); $request = new CakeRequest();
$request->base = 'beer';
Router::setRequestInfo($request);
$result = Router::normalize('beer/admin/beers_tags/add'); $result = Router::normalize('beer/admin/beers_tags/add');
$this->assertEqual($result, '/admin/beers_tags/add'); $this->assertEqual($result, '/admin/beers_tags/add');
@ -249,16 +257,15 @@ class RouterTest extends CakeTestCase {
function testUrlGenerationBasic() { function testUrlGenerationBasic() {
extract(Router::getNamedExpressions()); extract(Router::getNamedExpressions());
Router::setRequestInfo(array( $request = new CakeRequest();
array( $request->addParams(array(
'pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'subscribe', 'action' => 'index', 'plugin' => null, 'controller' => 'subscribe', 'admin' => true
'admin' => true, 'url' => array('url' => '')
),
array(
'base' => '/magazine', 'here' => '/magazine',
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
)
)); ));
$request->base = '/magazine';
$request->here = '/magazine';
$request->webroot = '/magazine/';
Router::setRequestInfo($request);
$result = Router::url(); $result = Router::url();
$this->assertEqual('/magazine', $result); $this->assertEqual('/magazine', $result);
@ -312,13 +319,15 @@ class RouterTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array('pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'real_controller_name', 'url' => array('url' => '')), $request->addParams(array(
array( 'action' => 'index', 'plugin' => null, 'controller' => 'real_controller_name'
'base' => '/', 'here' => '/',
'webroot' => '/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
)
)); ));
$request->base = '/';
$request->here = '/';
$request->webroot = '/';
Router::setRequestInfo($request);
Router::connect('short_controller_name/:action/*', array('controller' => 'real_controller_name')); Router::connect('short_controller_name/:action/*', array('controller' => 'real_controller_name'));
Router::parse('/'); Router::parse('/');
@ -332,13 +341,14 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( $request = new CakeRequest();
array('pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')), $request->addParams(array(
array( 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')
'base' => '/', 'here' => '/',
'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(),
)
)); ));
$request->base = '/';
$request->here = '/';
$request->webroot = '/';
Router::setRequestInfo($request);
$result = Router::url(array('action' => 'login')); $result = Router::url(array('action' => 'login'));
$expected = '/users/login'; $expected = '/users/login';
@ -362,16 +372,14 @@ class RouterTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array( $request->addParams(array(
'pass' => array(), 'action' => 'index', 'plugin' => 'myplugin', 'controller' => 'mycontroller', 'action' => 'index', 'plugin' => 'myplugin', 'controller' => 'mycontroller', 'admin' => false
'admin' => false, 'url' => array('url' => array())
),
array(
'base' => '/', 'here' => '/',
'webroot' => '/', 'passedArgs' => array(), 'namedArgs' => array(),
)
)); ));
$request->base = '/';
$request->here = '/';
$request->webroot = '/';
Router::setRequestInfo($request);
$result = Router::url(array('plugin' => null, 'controller' => 'myothercontroller')); $result = Router::url(array('plugin' => null, 'controller' => 'myothercontroller'));
$expected = '/myothercontroller'; $expected = '/myothercontroller';
@ -507,26 +515,33 @@ class RouterTest extends CakeTestCase {
Router::connect('/tests', array('controller' => 'tests', 'action' => 'index')); Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));
Router::parseExtensions('rss'); Router::parseExtensions('rss');
Router::setRequestInfo(array( $request = new CakeRequest();
array('pass' => array(), 'named' => array(), 'controller' => 'registrations', 'action' => 'admin_index', 'plugin' => '', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/registrations/index'), 'form' => array()), $request->addParams(array(
array('base' => '', 'here' => '/admin/registrations/index', 'webroot' => '/') 'controller' => 'registrations', 'action' => 'admin_index',
'plugin' => null, 'prefix' => 'admin', 'admin' => true,
'url' => array('ext' => 'html', 'url' => 'admin/registrations/index')
)); ));
$request->base = '';
$request->here = '/admin/registrations/index';
$request->webroot = '/';
Router::setRequestInfo($request);
$result = Router::url(array('page' => 2)); $result = Router::url(array('page' => 2));
$expected = '/admin/registrations/index/page:2'; $expected = '/admin/registrations/index/page:2';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array( $request->addParams(array(
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscriptions', 'controller' => 'subscriptions', 'action' => 'admin_index',
'admin' => true, 'url' => array('url' => 'admin/subscriptions/index/page:2'), 'plugin' => null, 'admin' => true,
), 'url' => array('url' => 'admin/subscriptions/index/page:2')
array(
'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/index/page:2',
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2),
)
)); ));
$request->base = '/magazine';
$request->here = '/magazine/admin/subscriptions/index/page:2';
$request->webroot = '/magazine/';
Router::setRequestInfo($request);
Router::parse('/'); Router::parse('/');
$result = Router::url(array('page' => 3)); $result = Router::url(array('page' => 3));
@ -536,16 +551,16 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin')); Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array(
array( $request = new CakeRequest();
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe', $request->addParams(array(
'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1') 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
), 'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1')
array(
'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/edit/1',
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
)
)); ));
$request->base = '/magazine';
$request->here = '/magazine/admin/subscriptions/edit/1';
$request->webroot = '/magazine/';
Router::setRequestInfo($request);
$result = Router::url(array('action' => 'edit', 1)); $result = Router::url(array('action' => 'edit', 1));
$expected = '/magazine/admin/subscriptions/edit/1'; $expected = '/magazine/admin/subscriptions/edit/1';
@ -557,13 +572,16 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array('pass' => array(), 'admin' => true, 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')), $request->addParams(array(
array( 'admin' => true, 'action' => 'index', 'plugin' => null, 'controller' => 'users',
'base' => '/', 'here' => '/', 'url' => array('url' => 'users')
'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(),
)
)); ));
$request->base = '/';
$request->here = '/';
$request->webroot = '/';
Router::setRequestInfo($request);
Router::connect('/page/*', array('controller' => 'pages', 'action' => 'view', 'admin' => true, 'prefix' => 'admin')); Router::connect('/page/*', array('controller' => 'pages', 'action' => 'view', 'admin' => true, 'prefix' => 'admin'));
Router::parse('/'); Router::parse('/');
@ -573,10 +591,15 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')), $request->addParams(array(
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/') 'plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'prefix' => 'admin', 'admin' => true,
'url' => array('url' => 'admin/pages/add')
)); ));
$request->base = '';
$request->here = '/admin/pages/add';
$request->webroot = '/';
Router::setRequestInfo($request);
Router::parse('/'); Router::parse('/');
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false)); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
@ -586,10 +609,15 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( $request = new CakeRequest();
array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')), $request->addParams(array(
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/') 'plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'prefix' => 'admin', 'admin' => true,
'url' => array('url' => 'admin/pages/add')
)); ));
$request->base = '';
$request->here = '/admin/pages/add';
$request->webroot = '/';
Router::setRequestInfo($request);
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false)); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
$expected = '/admin/pages/add'; $expected = '/admin/pages/add';
@ -598,10 +626,16 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+')); Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+'));
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( $request = new CakeRequest();
array ('plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/edit/284')), Router::setRequestInfo(
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/') $request->addParams(array(
)); 'plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'),
'prefix' => 'admin', 'admin' => true,
'url' => array('url' => 'admin/pages/edit/284')
))->addPaths(array(
'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/'
))
);
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284')); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
$expected = '/admin/pages/edit/284'; $expected = '/admin/pages/edit/284';
@ -610,10 +644,16 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array(
array ('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')), $request = new CakeRequest();
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/') Router::setRequestInfo(
)); $request->addParams(array(
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'prefix' => 'admin',
'admin' => true, 'url' => array('url' => 'admin/pages/add')
))->addPaths(array(
'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/'
))
);
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false)); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
$expected = '/admin/pages/add'; $expected = '/admin/pages/add';
@ -622,10 +662,16 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/edit/284')), $request = new CakeRequest();
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/') Router::setRequestInfo(
)); $request->addParams(array(
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'prefix' => 'admin',
'admin' => true, 'pass' => array('284'), 'url' => array('url' => 'admin/pages/edit/284')
))->addPaths(array(
'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/'
))
);
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 284)); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 284));
$expected = '/admin/pages/edit/284'; $expected = '/admin/pages/edit/284';
@ -635,10 +681,14 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true)); Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( Router::setRequestInfo(
array('pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'posts', 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/posts')), $request->addParams(array(
array('base' => '', 'here' => '/admin/posts', 'webroot' => '/') 'plugin' => null, 'controller' => 'posts', 'action' => 'admin_index', 'prefix' => 'admin',
)); 'admin' => true, 'pass' => array('284'), 'url' => array('url' => 'admin/posts')
))->addPaths(array(
'base' => '', 'here' => '/admin/posts', 'webroot' => '/'
))
);
$result = Router::url(array('all')); $result = Router::url(array('all'));
$expected = '/admin/posts/all'; $expected = '/admin/posts/all';
@ -677,31 +727,30 @@ class RouterTest extends CakeTestCase {
* @return void * @return void
*/ */
function testUrlGenerationPlugins() { function testUrlGenerationPlugins() {
Router::setRequestInfo(array( $request = new CakeRequest();
array( Router::setRequestInfo(
'controller' => 'controller', 'action' => 'index', 'form' => array(), $request->addParams(array(
'url' => array(), 'plugin' => 'test' 'plugin' => 'test', 'controller' => 'controller', 'action' => 'index'
), ))->addPaths(array(
array( 'base' => '/base', 'here' => '/clients/sage/portal/donations', 'webroot' => '/base/'
'base' => '/base', 'here' => '/clients/sage/portal/donations', 'webroot' => '/base/', ))
'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array() );
)
));
$this->assertEqual(Router::url('read/1'), '/base/test/controller/read/1'); $this->assertEqual(Router::url('read/1'), '/base/test/controller/read/1');
Router::reload(); Router::reload();
Router::connect('/:lang/:plugin/:controller/*', array('action' => 'index')); Router::connect('/:lang/:plugin/:controller/*', array('action' => 'index'));
Router::setRequestInfo(array( $request = new CakeRequest();
array( Router::setRequestInfo(
$request->addParams(array(
'lang' => 'en', 'lang' => 'en',
'plugin' => 'shows', 'controller' => 'shows', 'action' => 'index', 'pass' => 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'index',
array(), 'form' => array(), 'url' => 'url' => array('url' => 'en/shows/'),
array('url' => 'en/shows/')), ))->addPaths(array(
array('plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'base' => '', 'here' => '/en/shows', 'webroot' => '/'
'here' => '/en/shows/', 'webroot' => '/') ))
)); );
Router::parse('/en/shows/'); Router::parse('/en/shows/');
@ -728,8 +777,9 @@ class RouterTest extends CakeTestCase {
'prefix' => 'admin' 'prefix' => 'admin'
) )
); );
Router::setRequestInfo(array( $request = new CakeRequest();
array( Router::setRequestInfo(
$request->addParams(array(
'pass' => array(), 'pass' => array(),
'admin' => true, 'admin' => true,
'prefix' => 'admin', 'prefix' => 'admin',
@ -737,14 +787,12 @@ class RouterTest extends CakeTestCase {
'action' => 'admin_index', 'action' => 'admin_index',
'controller' => 'interesting', 'controller' => 'interesting',
'url' => array('url' => 'admin/this/interesting/index'), 'url' => array('url' => 'admin/this/interesting/index'),
), ))->addPaths(array(
array(
'base' => '', 'base' => '',
'here' => '/admin/this/interesting/index', 'here' => '/admin/this/interesting/index',
'webroot' => '/', 'webroot' => '/',
'passedArgs' => array(), ))
) );
));
$result = Router::url(array('plugin' => null, 'controller' => 'posts', 'action' => 'index')); $result = Router::url(array('plugin' => null, 'controller' => 'posts', 'action' => 'index'));
$this->assertEqual($result, '/admin/posts'); $this->assertEqual($result, '/admin/posts');
@ -894,10 +942,22 @@ class RouterTest extends CakeTestCase {
Router::connect('/about', array('controller' => 'pages', 'action' => 'view', 'about')); Router::connect('/about', array('controller' => 'pages', 'action' => 'view', 'about'));
Router::parse('/en/red/posts/view/5'); Router::parse('/en/red/posts/view/5');
Router::setRequestInfo(array(
array('controller' => 'posts', 'action' => 'view', 'lang' => 'en', 'color' => 'red', 'form' => array(), 'url' => array(), 'plugin' => null), $request = new CakeRequest();
array('base' => '/', 'here' => '/en/red/posts/view/5', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) Router::setRequestInfo(
)); $request->addParams(array(
'lang' => 'en',
'color' => 'red',
'prefix' => 'admin',
'plugin' => null,
'action' => 'view',
'controller' => 'posts',
))->addPaths(array(
'base' => '/',
'here' => '/en/red/posts/view/5',
'webroot' => '/',
))
);
$expected = '/en/red/posts/view/6'; $expected = '/en/red/posts/view/6';
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 6)); $result = Router::url(array('controller' => 'posts', 'action' => 'view', 6));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -1018,12 +1078,17 @@ class RouterTest extends CakeTestCase {
App::objects('plugin', null, false); App::objects('plugin', null, false);
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array('admin' => true, 'controller' => 'controller', 'action' => 'action', Router::setRequestInfo(
'form' => array(), 'url' => array(), 'plugin' => null, 'prefix' => 'admin'), $request->addParams(array(
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'admin' => true, 'controller' => 'controller', 'action' => 'action',
'argSeparator' => ':', 'namedArgs' => array()) 'plugin' => null, 'prefix' => 'admin'
)); ))->addPaths(array(
'base' => '/',
'here' => '/',
'webroot' => '/base/',
))
);
Router::parse('/'); Router::parse('/');
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index')); $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
@ -1032,17 +1097,18 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( $request = new CakeRequest();
array( Router::setRequestInfo(
$request->addParams(array(
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'admin_edit', 'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'admin_edit',
'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(),
'url' => array('url' => 'admin/shows/show_tickets/edit/6') 'url' => array('url' => 'admin/shows/show_tickets/edit/6')
), ))->addPaths(array(
array( 'base' => '/',
'plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/shows/show_tickets/edit/6',
'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/' 'webroot' => '/',
) ))
)); );
$result = Router::url(array( $result = Router::url(array(
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 6, 'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 6,
@ -1216,10 +1282,16 @@ class RouterTest extends CakeTestCase {
Configure::write('Routing.prefixes', array('admin')); Configure::write('Routing.prefixes', array('admin'));
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest();
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), Router::setRequestInfo(
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) $request->addParams(array(
)); 'admin' => true, 'controller' => 'controller', 'action' => 'index', 'plugin' => null
))->addPaths(array(
'base' => '/',
'here' => '/',
'webroot' => '/base/',
))
);
Router::parse('/'); Router::parse('/');
$result = Router::url(array('page' => 1, 0 => null, 'sort' => 'controller', 'direction' => 'asc', 'order' => null)); $result = Router::url(array('page' => 1, 0 => null, 'sort' => 'controller', 'direction' => 'asc', 'order' => null));
@ -1227,10 +1299,12 @@ class RouterTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
Router::reload(); Router::reload();
Router::setRequestInfo(array( $request = new CakeRequest('admin/controller/index');
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), $request->addParams(array(
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array('type'=> 'whatever'), 'argSeparator' => ':', 'namedArgs' => array('type'=> 'whatever')) 'admin' => true, 'controller' => 'controller', 'action' => 'index', 'plugin' => null
)); ));
$request->base = '/';
Router::setRequestInfo($request);
$result = Router::parse('/admin/controller/index/type:whatever'); $result = Router::parse('/admin/controller/index/type:whatever');
$result = Router::url(array('type'=> 'new')); $result = Router::url(array('type'=> 'new'));
@ -1320,10 +1394,17 @@ class RouterTest extends CakeTestCase {
)); ));
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( $request = new CakeRequest();
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'admin' => false, 'form' => array(), 'url' => array('url' => 'images/index')), Router::setRequestInfo(
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/images/index', 'webroot' => '/') $request->addParams(array(
)); 'plugin' => null, 'controller' => 'images', 'action' => 'index',
'prefix' => null, 'admin' => false,'url' => array('url' => 'images/index')
))->addPaths(array(
'base' => '',
'here' => '/images/index',
'webroot' => '/',
))
);
$result = Router::url(array('protected' => true)); $result = Router::url(array('protected' => true));
$expected = '/protected/images/index'; $expected = '/protected/images/index';
@ -1381,10 +1462,17 @@ class RouterTest extends CakeTestCase {
Router::reload(); Router::reload();
Router::parse('/'); Router::parse('/');
Router::setRequestInfo(array( $request = new CakeRequest();
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'protected' => false, 'form' => array(), 'url' => array('url' => 'images/index')), Router::setRequestInfo(
array('base' => '', 'here' => '/images/index', 'webroot' => '/') $request->addParams(array(
)); 'plugin' => null, 'controller' => 'images', 'action' => 'index',
'prefix' => null, 'protected' => false, 'url' => array('url' => 'images/index')
))->addPaths(array(
'base' => '',
'here' => '/images/index',
'webroot' => '/',
))
);
$result = Router::url(array('controller' => 'images', 'action' => 'add')); $result = Router::url(array('controller' => 'images', 'action' => 'add'));
$expected = '/images/add'; $expected = '/images/add';