2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* RouterTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-10-30 17:30:26 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-03 20:29:20 +00:00
|
|
|
App::import('Core', array('Router'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (!defined('FULL_BASE_URL')) {
|
|
|
|
define('FULL_BASE_URL', 'http://cakephp.org');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* RouterTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class RouterTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
2009-09-27 05:22:46 +00:00
|
|
|
$this->_routing = Configure::read('Routing');
|
|
|
|
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-09-27 05:22:46 +00:00
|
|
|
/**
|
|
|
|
* end the test and reset the environment
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-09-27 05:22:46 +00:00
|
|
|
function endTest() {
|
|
|
|
Configure::write('Routing', $this->_routing);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFullBaseURL method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFullBaseURL() {
|
|
|
|
$this->assertPattern('/^http(s)?:\/\//', Router::url('/', true));
|
|
|
|
$this->assertPattern('/^http(s)?:\/\//', Router::url(null, true));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRouteDefaultParams method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRouteDefaultParams() {
|
|
|
|
Router::connect('/:controller', array('controller' => 'posts'));
|
|
|
|
$this->assertEqual(Router::url(array('action' => 'index')), '/');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testResourceRoutes method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testResourceRoutes() {
|
2010-04-20 03:44:45 +00:00
|
|
|
$resources = Router::mapResources('Posts');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts');
|
|
|
|
$this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => 'GET'));
|
2010-04-20 03:44:45 +00:00
|
|
|
$this->assertEqual($resources, array('posts'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts/13');
|
|
|
|
$this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => '13', '[method]' => 'GET'));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$result = Router::parse('/posts');
|
|
|
|
$this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST'));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$result = Router::parse('/posts/13');
|
|
|
|
$this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '13', '[method]' => 'PUT'));
|
|
|
|
|
|
|
|
$result = Router::parse('/posts/475acc39-a328-44d3-95fb-015000000000');
|
|
|
|
$this->assertEqual($result, array('pass' => array('475acc39-a328-44d3-95fb-015000000000'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '475acc39-a328-44d3-95fb-015000000000', '[method]' => 'PUT'));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'DELETE';
|
|
|
|
$result = Router::parse('/posts/13');
|
|
|
|
$this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'delete', 'id' => '13', '[method]' => 'DELETE'));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts/add');
|
|
|
|
$this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add'));
|
|
|
|
|
|
|
|
Router::reload();
|
2010-04-20 03:44:45 +00:00
|
|
|
$resources = Router::mapResources('Posts', array('id' => '[a-z0-9_]+'));
|
|
|
|
$this->assertEqual($resources, array('posts'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts/add');
|
|
|
|
$this->assertEqual($result, array('pass' => array('add'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => 'add', '[method]' => 'GET'));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$result = Router::parse('/posts/name');
|
|
|
|
$this->assertEqual($result, array('pass' => array('name'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => 'name', '[method]' => 'PUT'));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMultipleResourceRoute method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMultipleResourceRoute() {
|
|
|
|
Router::connect('/:controller', array('action' => 'index', '[method]' => array('GET', 'POST')));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts');
|
|
|
|
$this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST')));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$result = Router::parse('/posts');
|
|
|
|
$this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST')));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-01-15 01:17:09 +00:00
|
|
|
/**
|
|
|
|
* testGenerateUrlResourceRoute method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testGenerateUrlResourceRoute() {
|
|
|
|
Router::mapResources('Posts');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '[method]' => 'GET'));
|
|
|
|
$expected = '/posts';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'add', '[method]' => 'POST'));
|
|
|
|
$expected = '/posts';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'delete', '[method]' => 'DELETE', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', '[method]' => 'POST', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testUrlNormalization method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testUrlNormalization() {
|
|
|
|
$expected = '/users/logout';
|
|
|
|
|
|
|
|
$result = Router::normalize('/users/logout/');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::normalize('//users//logout//');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::normalize('users/logout');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::normalize(array('controller' => 'users', 'action' => 'logout'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::normalize('/');
|
|
|
|
$this->assertEqual($result, '/');
|
2008-07-25 11:45:00 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('http://google.com/');
|
|
|
|
$this->assertEqual($result, 'http://google.com/');
|
|
|
|
|
|
|
|
$result = Router::normalize('http://google.com//');
|
|
|
|
$this->assertEqual($result, 'http://google.com//');
|
|
|
|
|
|
|
|
$result = Router::normalize('/users/login/scope://foo');
|
|
|
|
$this->assertEqual($result, '/users/login/scope:/foo');
|
2008-08-13 18:07:52 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('/recipe/recipes/add');
|
|
|
|
$this->assertEqual($result, '/recipe/recipes/add');
|
2009-01-14 17:55:48 +00:00
|
|
|
|
2009-07-20 13:18:38 +00:00
|
|
|
Router::setRequestInfo(array(array(), array('base' => '/us')));
|
2009-01-14 17:55:48 +00:00
|
|
|
$result = Router::normalize('/us/users/logout/');
|
|
|
|
$this->assertEqual($result, '/users/logout');
|
|
|
|
|
2009-01-14 18:27:14 +00:00
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(array(), array('base' => '/cake_12')));
|
|
|
|
$result = Router::normalize('/cake_12/users/logout/');
|
|
|
|
$this->assertEqual($result, '/users/logout');
|
|
|
|
|
2009-07-20 13:18:38 +00:00
|
|
|
Router::reload();
|
|
|
|
$_back = Configure::read('App.baseUrl');
|
|
|
|
Configure::write('App.baseUrl', '/');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-20 13:18:38 +00:00
|
|
|
Router::setRequestInfo(array(array(), array('base' => '/')));
|
|
|
|
$result = Router::normalize('users/login');
|
|
|
|
$this->assertEqual($result, '/users/login');
|
|
|
|
Configure::write('App.baseUrl', $_back);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-20 13:18:38 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(array(), array('base' => 'beer')));
|
|
|
|
$result = Router::normalize('beer/admin/beers_tags/add');
|
|
|
|
$this->assertEqual($result, '/admin/beers_tags/add');
|
|
|
|
|
|
|
|
$result = Router::normalize('/admin/beers_tags/add');
|
|
|
|
$this->assertEqual($result, '/admin/beers_tags/add');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-10-02 18:28:01 +00:00
|
|
|
* test generation of basic urls.
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-10-02 18:28:01 +00:00
|
|
|
function testUrlGenerationBasic() {
|
2008-05-30 11:40:08 +00:00
|
|
|
extract(Router::getNamedExpressions());
|
2008-06-14 21:26:01 +00:00
|
|
|
|
2008-06-14 21:12:56 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'subscribe',
|
|
|
|
'admin' => true, 'url' => array('url' => '')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/magazine', 'here' => '/magazine',
|
|
|
|
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$result = Router::url();
|
|
|
|
$this->assertEqual('/magazine', $result);
|
2008-06-14 21:26:01 +00:00
|
|
|
|
2008-06-14 21:12:56 +00:00
|
|
|
Router::reload();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$out = Router::url(array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$this->assertEqual($out, '/');
|
|
|
|
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 'about'));
|
|
|
|
$expected = '/pages/about';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::connect('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
|
|
|
$expected = '/cake_plugin/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1', '0'));
|
|
|
|
$expected = '/cake_plugin/1/0';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:controller/:action/:id', array(), array('id' => $ID));
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::parse('/');
|
2009-12-09 02:36:25 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
|
|
|
$expected = '/posts/view/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::connect('/:controller/:id', array('action' => 'view'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
|
|
|
$expected = '/posts/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0'));
|
|
|
|
$expected = '/posts/index/0';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-11-29 21:09:45 +00:00
|
|
|
Router::connect('/view/*', array('controller' => 'posts', 'action' => 'view'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::promote();
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', '1'));
|
|
|
|
$expected = '/view/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(
|
2009-10-02 18:28:01 +00:00
|
|
|
array('pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'real_controller_name', 'url' => array('url' => '')),
|
2008-05-30 11:40:08 +00:00
|
|
|
array(
|
2009-10-02 18:28:01 +00:00
|
|
|
'base' => '/', 'here' => '/',
|
|
|
|
'webroot' => '/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
));
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::connect('short_controller_name/:action/*', array('controller' => 'real_controller_name'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parse('/');
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('controller' => 'real_controller_name', 'page' => '1'));
|
|
|
|
$expected = '/short_controller_name/index/page:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'add'));
|
|
|
|
$expected = '/short_controller_name/add';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::setRequestInfo(array(
|
2009-10-02 18:28:01 +00:00
|
|
|
array('pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')),
|
2008-05-30 11:40:08 +00:00
|
|
|
array(
|
2009-10-02 18:28:01 +00:00
|
|
|
'base' => '/', 'here' => '/',
|
|
|
|
'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(),
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
));
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'login'));
|
|
|
|
$expected = '/users/login';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/page/*', array('plugin' => null, 'controller' => 'pages', 'action' => 'view'));
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'view', 'my-page'));
|
|
|
|
$expected = '/my_plugin/pages/view/my-page';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::connect('/contact/:action', array('plugin' => 'contact', 'controller' => 'contact'));
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'contact', 'controller' => 'contact', 'action' => 'me'));
|
|
|
|
|
|
|
|
$expected = '/contact/me';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(
|
2009-10-02 18:28:01 +00:00
|
|
|
array(
|
|
|
|
'pass' => array(), 'action' => 'index', 'plugin' => 'myplugin', 'controller' => 'mycontroller',
|
|
|
|
'admin' => false, 'url' => array('url' => array())
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array(
|
|
|
|
'base' => '/', 'here' => '/',
|
2009-10-02 18:28:01 +00:00
|
|
|
'webroot' => '/', 'passedArgs' => array(), 'namedArgs' => array(),
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'myothercontroller'));
|
|
|
|
$expected = '/myothercontroller';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2009-10-02 18:28:01 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
/**
|
|
|
|
* Test generation of routes with query string parameters.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testUrlGenerationWithQueryStrings() {
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', '0', '?' => array('var' => null)));
|
|
|
|
$this->assertEqual($result, '/posts/index/0');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2', '#' => 'unencoded string %'));
|
|
|
|
$expected = '/posts/index/0?var=test&var2=test2#unencoded+string+%25';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that regex validation of keyed route params is working.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testUrlGenerationWithRegexQualifiedParams() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect(
|
|
|
|
':language/galleries',
|
|
|
|
array('controller' => 'galleries', 'action' => 'index'),
|
|
|
|
array('language' => '[a-z]{3}')
|
|
|
|
);
|
|
|
|
|
|
|
|
Router::connect(
|
|
|
|
'/:language/:admin/:controller/:action/*',
|
|
|
|
array('admin' => 'admin'),
|
|
|
|
array('language' => '[a-z]{3}', 'admin' => 'admin')
|
|
|
|
);
|
|
|
|
|
|
|
|
Router::connect('/:language/:controller/:action/*',
|
|
|
|
array(),
|
|
|
|
array('language' => '[a-z]{3}')
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = Router::url(array('admin' => false, 'language' => 'dan', 'action' => 'index', 'controller' => 'galleries'));
|
|
|
|
$expected = '/dan/galleries';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('admin' => false, 'language' => 'eng', 'action' => 'index', 'controller' => 'galleries'));
|
|
|
|
$expected = '/eng/galleries';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:language/pages',
|
2008-06-20 20:17:23 +00:00
|
|
|
array('controller' => 'pages', 'action' => 'index'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('language' => '[a-z]{3}')
|
|
|
|
);
|
|
|
|
Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}'));
|
|
|
|
|
|
|
|
$result = Router::url(array('language' => 'eng', 'action' => 'index', 'controller' => 'pages'));
|
|
|
|
$expected = '/eng/pages';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('language' => 'eng', 'controller' => 'pages'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('language' => 'eng', 'controller' => 'pages', 'action' => 'add'));
|
|
|
|
$expected = '/eng/pages/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/forestillinger/:month/:year/*',
|
|
|
|
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
|
|
|
|
array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}')
|
|
|
|
);
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'month' => 10, 'year' => 2007, 'min-forestilling'));
|
|
|
|
$expected = '/forestillinger/10/2007/min-forestilling';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/kalender/:month/:year/*',
|
|
|
|
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
|
|
|
|
array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}')
|
|
|
|
);
|
|
|
|
Router::connect('/kalender/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'));
|
2009-12-01 18:37:03 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling'));
|
|
|
|
$expected = '/kalender/min-forestilling';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling'));
|
|
|
|
$expected = '/kalender/10/2007/min-forestilling';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-12-16 20:04:59 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:controller/:action/*', array(), array(
|
|
|
|
'controller' => 'source|wiki|commits|tickets|comments|view',
|
|
|
|
'action' => 'branches|history|branch|logs|view|start|add|edit|modify'
|
|
|
|
));
|
|
|
|
Router::defaults(false);
|
|
|
|
$result = Router::parse('/foo/bar');
|
2009-12-17 15:13:05 +00:00
|
|
|
$expected = array('pass' => array(), 'named' => array());
|
2009-12-16 20:04:59 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2009-10-02 18:28:01 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
/**
|
|
|
|
* Test url generation with an admin prefix
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUrlGenerationWithAdminPrefix() {
|
2010-04-21 03:40:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::connectNamed(array('event', 'lang'));
|
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
Router::connect('/pages/contact_us', array('controller' => 'pages', 'action' => 'contact_us'));
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
Router::connect('/reset/*', array('admin' => true, 'controller' => 'users', 'action' => 'reset'));
|
|
|
|
Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));
|
|
|
|
Router::parseExtensions('rss');
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
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()),
|
|
|
|
array('base' => '', 'here' => '/admin/registrations/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('page' => 2));
|
|
|
|
$expected = '/admin/registrations/index/page:2';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
2009-10-02 18:28:01 +00:00
|
|
|
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscriptions',
|
|
|
|
'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),
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
Router::parse('/');
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('page' => 3));
|
|
|
|
$expected = '/magazine/admin/subscriptions/index/page:3';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
2009-10-02 18:28:01 +00:00
|
|
|
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
|
|
|
|
'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1')
|
2008-05-30 11:40:08 +00:00
|
|
|
),
|
2009-10-02 18:28:01 +00:00
|
|
|
array(
|
|
|
|
'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/edit/1',
|
|
|
|
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1));
|
|
|
|
$expected = '/magazine/admin/subscriptions/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-11-05 04:05:25 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('admin' => true, 'controller' => 'users', 'action' => 'login'));
|
|
|
|
$expected = '/magazine/admin/users/login';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('pass' => array(), 'admin' => true, 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')),
|
2008-05-30 11:40:08 +00:00
|
|
|
array(
|
|
|
|
'base' => '/', 'here' => '/',
|
2009-10-02 18:28:01 +00:00
|
|
|
'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(),
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
));
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::connect('/page/*', array('controller' => 'pages', 'action' => 'view', 'admin' => true, 'prefix' => 'admin'));
|
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
$result = Router::url(array('admin' => true, 'controller' => 'pages', 'action' => 'view', 'my-page'));
|
|
|
|
$expected = '/page/my-page';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
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')),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2009-10-02 18:28:01 +00:00
|
|
|
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')),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+'));
|
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
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')),
|
|
|
|
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
|
|
|
|
$expected = '/admin/pages/edit/284';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
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')),
|
|
|
|
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2008-05-30 11:40:08 +00:00
|
|
|
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')),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
2009-09-30 02:53:17 +00:00
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 284));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/admin/pages/edit/284';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-08-20 03:33:52 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
|
|
|
|
Router::parse('/');
|
2009-08-20 03:33:52 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'posts', 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/posts')),
|
|
|
|
array('base' => '', 'here' => '/admin/posts', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('all'));
|
|
|
|
$expected = '/admin/posts/all';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testUrlGenerationWithExtensions method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testUrlGenerationWithExtensions() {
|
|
|
|
Router::parse('/');
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'id' => null, 'ext' => 'json'));
|
|
|
|
$expected = '/articles/add.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'ext' => 'json'));
|
|
|
|
$expected = '/articles/add.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'id' => null, 'ext' => 'json'));
|
|
|
|
$expected = '/articles.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'ext' => 'json'));
|
|
|
|
$expected = '/articles.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPluginUrlGeneration method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-12-09 02:36:25 +00:00
|
|
|
function testUrlGenerationPlugins() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'controller' => 'controller', 'action' => 'index', 'form' => array(),
|
|
|
|
'url' => array(), 'plugin' => 'test'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'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');
|
2009-02-17 18:26:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2009-11-29 21:09:45 +00:00
|
|
|
Router::connect('/:lang/:plugin/:controller/*', array('action' => 'index'));
|
2009-02-17 18:26:37 +00:00
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
2009-12-09 02:36:25 +00:00
|
|
|
array(
|
|
|
|
'lang' => 'en',
|
|
|
|
'plugin' => 'shows', 'controller' => 'shows', 'action' => 'index', 'pass' =>
|
|
|
|
array(), 'form' => array(), 'url' =>
|
|
|
|
array('url' => 'en/shows/')),
|
|
|
|
array('plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '',
|
|
|
|
'here' => '/en/shows/', 'webroot' => '/')
|
|
|
|
));
|
2009-02-17 18:26:37 +00:00
|
|
|
|
|
|
|
Router::parse('/en/shows/');
|
|
|
|
|
|
|
|
$result = Router::url(array(
|
|
|
|
'lang' => 'en',
|
|
|
|
'controller' => 'shows', 'action' => 'index', 'page' => '1',
|
|
|
|
));
|
2010-04-07 02:44:23 +00:00
|
|
|
$expected = '/en/shows/shows/page:1';
|
2009-02-17 18:26:37 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-12-09 02:36:25 +00:00
|
|
|
/**
|
|
|
|
* test that you can leave active plugin routes with plugin = null
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCanLeavePlugin() {
|
|
|
|
Router::reload();
|
|
|
|
Router::connect(
|
|
|
|
'/admin/other/:controller/:action/*',
|
|
|
|
array(
|
|
|
|
'admin' => 1,
|
|
|
|
'plugin' => 'aliased',
|
|
|
|
'prefix' => 'admin'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'pass' => array(),
|
|
|
|
'admin' => true,
|
|
|
|
'prefix' => 'admin',
|
|
|
|
'plugin' => 'this',
|
|
|
|
'action' => 'admin_index',
|
|
|
|
'controller' => 'interesting',
|
|
|
|
'url' => array('url' => 'admin/this/interesting/index'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/admin/this/interesting/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
'passedArgs' => array(),
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/admin/posts');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/admin/this/posts');
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'aliased', 'controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/admin/other/posts/index');
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testUrlParsing method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testUrlParsing() {
|
|
|
|
extract(Router::getNamedExpressions());
|
|
|
|
|
|
|
|
Router::connect('/posts/:value/:somevalue/:othervalue/*', array('controller' => 'posts', 'action' => 'view'), array('value','somevalue', 'othervalue'));
|
|
|
|
$result = Router::parse('/posts/2007/08/01/title-of-post-here');
|
|
|
|
$expected = array('value' => '2007', 'somevalue' => '08', 'othervalue' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-04-20 03:54:09 +00:00
|
|
|
Router::reload();
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
|
|
|
|
$result = Router::parse('/posts/2007/08/01/title-of-post-here');
|
|
|
|
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-04-20 03:54:09 +00:00
|
|
|
Router::reload();
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/posts/:day/:year/:month/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
|
|
|
|
$result = Router::parse('/posts/01/2007/08/title-of-post-here');
|
|
|
|
$expected = array('day' => '01', 'year' => '2007', 'month' => '08', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-04-20 03:54:09 +00:00
|
|
|
Router::reload();
|
2009-11-27 04:46:42 +00:00
|
|
|
Router::connect('/posts/:month/:day/:year/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::parse('/posts/08/01/2007/title-of-post-here');
|
|
|
|
$expected = array('month' => '08', 'day' => '01', 'year' => '2007', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-04-20 03:54:09 +00:00
|
|
|
Router::reload();
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'));
|
|
|
|
$result = Router::parse('/posts/2007/08/01/title-of-post-here');
|
|
|
|
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$result = Router::parse('/pages/display/home');
|
|
|
|
$expected = array('plugin' => null, 'pass' => array('home'), 'controller' => 'pages', 'action' => 'display', 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('pages/display/home/');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('pages/display/home');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/page/*', array('controller' => 'test'));
|
|
|
|
$result = Router::parse('/page/my-page');
|
|
|
|
$expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index');
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}'));
|
|
|
|
$result = Router::parse('/eng/contact');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/forestillinger/:month/:year/*',
|
|
|
|
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
|
|
|
|
array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}')
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = Router::parse('/forestillinger/10/2007/min-forestilling');
|
|
|
|
$expected = array('pass' => array('min-forestilling'), 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
2009-11-29 21:09:45 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/', array('plugin' => 'pages', 'controller' => 'pages', 'action' => 'display'));
|
|
|
|
$result = Router::parse('/');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'controller' => 'pages', 'action' => 'display', 'plugin' => 'pages');
|
2008-09-12 05:11:34 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-08-22 03:27:07 +00:00
|
|
|
$result = Router::parse('/posts/edit/0');
|
2008-09-12 05:11:34 +00:00
|
|
|
$expected = array('pass' => array(0), 'named' => array(), 'controller' => 'posts', 'action' => 'edit', 'plugin' => null);
|
2008-08-22 03:27:07 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-09-12 05:11:34 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect('/posts/:id::url_title', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+'));
|
|
|
|
$result = Router::parse('/posts/5:sample-post-title');
|
|
|
|
$expected = array('pass' => array('5', 'sample-post-title'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/posts/:id::url_title/*', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+'));
|
|
|
|
$result = Router::parse('/posts/5:sample-post-title/other/params/4');
|
|
|
|
$expected = array('pass' => array('5', 'sample-post-title', 'other', 'params', '4'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/posts/:url_title-(uuid::id)', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => $UUID));
|
|
|
|
$result = Router::parse('/posts/sample-post-title-(uuid:47fc97a9-019c-41d1-a058-1fa3cbdd56cb)');
|
|
|
|
$expected = array('pass' => array('47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'sample-post-title'), 'named' => array(), 'id' => '47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => false));
|
|
|
|
$result = Router::parse('/posts/view/foo:bar/routing:fun');
|
|
|
|
$expected = array('pass' => array('foo:bar', 'routing:fun'), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => array('foo', 'answer')));
|
|
|
|
$result = Router::parse('/posts/view/foo:bar/routing:fun/answer:42');
|
|
|
|
$expected = array('pass' => array('routing:fun'), 'named' => array('foo' => 'bar', 'answer' => '42'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => array('foo', 'answer'), 'greedy' => true));
|
|
|
|
$result = Router::parse('/posts/view/foo:bar/routing:fun/answer:42');
|
|
|
|
$expected = array('pass' => array(), 'named' => array('foo' => 'bar', 'routing' => 'fun', 'answer' => '42'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-11-26 04:11:50 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-11-26 04:11:50 +00:00
|
|
|
/**
|
|
|
|
* test that the persist key works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testPersistentParameters() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2009-11-26 04:11:50 +00:00
|
|
|
Router::connect(
|
|
|
|
'/:lang/:color/posts/view/*',
|
|
|
|
array('controller' => 'posts', 'action' => 'view'),
|
|
|
|
array('persist' => array('lang', 'color')
|
|
|
|
));
|
|
|
|
Router::connect(
|
|
|
|
'/:lang/:color/posts/index',
|
|
|
|
array('controller' => 'posts', 'action' => 'index'),
|
|
|
|
array('persist' => array('lang')
|
|
|
|
));
|
2009-11-30 15:15:39 +00:00
|
|
|
Router::connect('/:lang/:color/posts/edit/*', array('controller' => 'posts', 'action' => 'edit'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/about', array('controller' => 'pages', 'action' => 'view', 'about'));
|
|
|
|
Router::parse('/en/red/posts/view/5');
|
2009-11-26 04:11:50 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('controller' => 'posts', 'action' => 'view', 'lang' => 'en', 'color' => 'red', 'form' => array(), 'url' => array(), 'plugin' => null),
|
|
|
|
array('base' => '/', 'here' => '/en/red/posts/view/5', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
|
|
|
));
|
|
|
|
$expected = '/en/red/posts/view/6';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 6));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected = '/en/blue/posts/index';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'color' => 'blue'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-11-26 04:11:50 +00:00
|
|
|
$expected = '/posts/edit/6';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', 6, 'color' => null, 'lang' => null));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/posts';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected = '/posts/edit/7';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', 7));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected = '/about';
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'view', 'about'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testUuidRoutes method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testUuidRoutes() {
|
|
|
|
Router::connect(
|
|
|
|
'/subjects/add/:category_id',
|
|
|
|
array('controller' => 'subjects', 'action' => 'add'),
|
|
|
|
array('category_id' => '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}')
|
|
|
|
);
|
|
|
|
$result = Router::parse('/subjects/add/4795d601-19c8-49a6-930e-06a8b01d17b7');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'category_id' => '4795d601-19c8-49a6-930e-06a8b01d17b7', 'plugin' => null, 'controller' => 'subjects', 'action' => 'add');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRouteSymmetry method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRouteSymmetry() {
|
|
|
|
Router::connect(
|
|
|
|
"/:extra/page/:slug/*",
|
|
|
|
array('controller' => 'pages', 'action' => 'view', 'extra' => null),
|
|
|
|
array("extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+', "action" => 'view')
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = Router::parse('/some_extra/page/this_is_the_slug');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => 'some_extra');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/page/this_is_the_slug');
|
2009-11-27 04:46:42 +00:00
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => null);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect(
|
|
|
|
"/:extra/page/:slug/*",
|
|
|
|
array('controller' => 'pages', 'action' => 'view', 'extra' => null),
|
|
|
|
array("extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+')
|
|
|
|
);
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('admin' => null, 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => null));
|
|
|
|
$expected = '/page/this_is_the_slug';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('admin' => null, 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => 'some_extra'));
|
|
|
|
$expected = '/some_extra/page/this_is_the_slug';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-09-27 02:48:57 +00:00
|
|
|
/**
|
2010-04-21 03:43:51 +00:00
|
|
|
* Test that Routing.prefixes are used when a Router instance is created
|
2009-09-27 02:48:57 +00:00
|
|
|
* or reset
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-09-27 02:48:57 +00:00
|
|
|
function testRoutingPrefixesSetting() {
|
|
|
|
$restore = Configure::read('Routing');
|
|
|
|
|
2010-04-21 03:40:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin', 'member', 'super_user'));
|
2009-09-27 02:48:57 +00:00
|
|
|
Router::reload();
|
|
|
|
$result = Router::prefixes();
|
|
|
|
$expected = array('admin', 'member', 'super_user');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-04-21 03:40:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin', 'member'));
|
2009-09-27 02:48:57 +00:00
|
|
|
Router::reload();
|
|
|
|
$result = Router::prefixes();
|
|
|
|
$expected = array('admin', 'member');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Configure::write('Routing', $restore);
|
|
|
|
}
|
|
|
|
|
2009-09-27 05:22:46 +00:00
|
|
|
/**
|
|
|
|
* Test prefix routing and plugin combinations
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-09-27 05:22:46 +00:00
|
|
|
function testPrefixRoutingAndPlugins() {
|
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2009-09-20 22:38:26 +00:00
|
|
|
$paths = App::path('plugins');
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(
|
|
|
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
|
|
|
|
)
|
2009-09-20 23:02:05 +00:00
|
|
|
), true);
|
|
|
|
App::objects('plugin', null, false);
|
2009-07-17 21:35:23 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(
|
2009-07-24 19:18:37 +00:00
|
|
|
array('admin' => true, 'controller' => 'controller', 'action' => 'action',
|
2009-12-01 19:39:23 +00:00
|
|
|
'form' => array(), 'url' => array(), 'plugin' => null, 'prefix' => 'admin'),
|
2009-07-24 19:18:37 +00:00
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(),
|
2009-07-17 21:35:23 +00:00
|
|
|
'argSeparator' => ':', 'namedArgs' => array())
|
|
|
|
));
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
|
2010-04-11 01:12:48 +00:00
|
|
|
$expected = '/admin/test_plugin';
|
2009-07-17 21:35:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2009-12-09 02:36:25 +00:00
|
|
|
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'admin_edit',
|
|
|
|
'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(),
|
|
|
|
'url' => array('url' => 'admin/shows/show_tickets/edit/6')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'plugin' => null, 'controller' => null, 'action' => null, 'base' => '',
|
|
|
|
'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array(
|
|
|
|
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 6,
|
|
|
|
'admin' => true, 'prefix' => 'admin'
|
|
|
|
));
|
|
|
|
$expected = '/admin/test_plugin/show_tickets/edit/6';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-07-17 21:35:23 +00:00
|
|
|
|
2010-04-11 01:15:56 +00:00
|
|
|
$result = Router::url(array(
|
|
|
|
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'index', 'admin' => true
|
|
|
|
));
|
|
|
|
$expected = '/admin/test_plugin/show_tickets';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-09-20 22:38:26 +00:00
|
|
|
App::build(array('plugins' => $paths));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testExtensionParsingSetting method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testExtensionParsingSetting() {
|
2010-04-20 03:44:45 +00:00
|
|
|
$this->assertFalse(Router::extensions());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-20 03:54:09 +00:00
|
|
|
Router::parseExtensions('rss');
|
2010-04-20 03:44:45 +00:00
|
|
|
$this->assertEqual(Router::extensions(), array('rss'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testExtensionParsing method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testExtensionParsing() {
|
|
|
|
Router::parseExtensions();
|
|
|
|
|
|
|
|
$result = Router::parse('/posts.rss');
|
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'rss'), 'pass'=> array(), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/1.rss');
|
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'pass' => array('1'), 'named' => array(), 'url' => array('ext' => 'rss'), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/1.rss?query=test');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/1.atom');
|
|
|
|
$expected['url'] = array('ext' => 'atom');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::parseExtensions('rss', 'xml');
|
|
|
|
|
|
|
|
$result = Router::parse('/posts.xml');
|
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'xml'), 'pass'=> array(), 'named' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/posts.atom?hello=goodbye');
|
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts.atom', 'action' => 'index', 'pass' => array(), 'named' => array(), 'url' => array('ext' => 'html'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-06-29 20:24:06 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'url' => array('ext' => 'rss')));
|
|
|
|
$result = Router::parse('/controller/action');
|
|
|
|
$expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'url' => array('ext' => 'rss'), 'named' => array(), 'pass' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
2010-03-20 20:57:01 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::parseExtensions('rss');
|
|
|
|
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'url' => array('ext' => 'rss')));
|
|
|
|
$result = Router::parse('/controller/action');
|
|
|
|
$expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'url' => array('ext' => 'rss'), 'named' => array(), 'pass' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testQuerystringGeneration method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testQuerystringGeneration() {
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected .= '&more=test+data';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
// Test bug #4614
|
2008-05-30 11:40:08 +00:00
|
|
|
$restore = ini_get('arg_separator.output');
|
|
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
ini_set('arg_separator.output', $restore);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
2009-01-14 21:38:11 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')), array('escape' => true));
|
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testConnectNamed method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testConnectNamed() {
|
|
|
|
$named = Router::connectNamed(false, array('default' => true));
|
|
|
|
$this->assertFalse($named['greedy']);
|
|
|
|
$this->assertEqual(array_keys($named['rules']), $named['default']);
|
2008-06-17 15:46:49 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar'));
|
|
|
|
Router::connectNamed(array(), array('argSeparator' => '='));
|
|
|
|
$result = Router::parse('/foo/param1=value1/param2=value2');
|
|
|
|
$expected = array('pass' => array(), 'named' => array('param1' => 'value1', 'param2' => 'value2'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/controller/action/*', array('controller' => 'controller', 'action' => 'action'), array('named' => array('param1' => 'value[\d]')));
|
|
|
|
Router::connectNamed(array(), array('greedy' => false, 'argSeparator' => '='));
|
|
|
|
$result = Router::parse('/controller/action/param1=value1/param2=value2');
|
|
|
|
$expected = array('pass' => array('param2=value2'), 'named' => array('param1' => 'value1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-10-04 18:01:48 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:controller/:action/*');
|
|
|
|
Router::connectNamed(array('page'), array('default' => false, 'greedy' => false));
|
|
|
|
$result = Router::parse('/categories/index?limit=5');
|
|
|
|
$this->assertTrue(empty($result['named']));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testNamedArgsUrlGeneration method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testNamedArgsUrlGeneration() {
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1));
|
|
|
|
$expected = '/posts/index/published:1/deleted:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 0, 'deleted' => 0));
|
|
|
|
$expected = '/posts/index/published:0/deleted:0';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
extract(Router::getNamedExpressions());
|
|
|
|
Router::connectNamed(array('file'=> '[\w\.\-]+\.(html|png)'));
|
|
|
|
Router::connect('/', array('controller' => 'graphs', 'action' => 'index'));
|
|
|
|
Router::connect('/:id/*', array('controller' => 'graphs', 'action' => 'view'), array('id' => $ID));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'graphs', 'action' => 'view', 'id' => 12, 'file' => 'asdf.png'));
|
|
|
|
$expected = '/12/file:asdf.png';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-09-30 02:53:17 +00:00
|
|
|
$result = Router::url(array('controller' => 'graphs', 'action' => 'view', 12, 'file' => 'asdf.foo'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/graphs/view/12/file:asdf.foo';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-04-21 03:40:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
|
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
|
|
|
));
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('page' => 1, 0 => null, 'sort' => 'controller', 'direction' => 'asc', 'order' => null));
|
|
|
|
$expected = "/admin/controller/index/page:1/sort:controller/direction:asc";
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
|
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array('type'=> 'whatever'), 'argSeparator' => ':', 'namedArgs' => array('type'=> 'whatever'))
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::parse('/admin/controller/index/type:whatever');
|
|
|
|
$result = Router::url(array('type'=> 'new'));
|
|
|
|
$expected = "/admin/controller/index/type:new";
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testNamedArgsUrlParsing method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testNamedArgsUrlParsing() {
|
|
|
|
Router::reload();
|
|
|
|
$result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value');
|
|
|
|
$expected = array('pass' => array(), 'named' => array('param1' => 'value1:1', 'param2' => 'value2:3', 'param' => 'value'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$result = Router::connectNamed(false);
|
|
|
|
$this->assertEqual(array_keys($result['rules']), array());
|
|
|
|
$this->assertFalse($result['greedy']);
|
|
|
|
$result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value');
|
|
|
|
$expected = array('pass' => array('param1:value1:1', 'param2:value2:3', 'param:value'), 'named' => array(), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$result = Router::connectNamed(true);
|
2010-04-20 03:54:09 +00:00
|
|
|
$this->assertEqual(array_keys($result['rules']), Router::getInstance()->named['default']);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result['greedy']);
|
|
|
|
Router::reload();
|
|
|
|
Router::connectNamed(array('param1' => 'not-matching'));
|
|
|
|
$result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value');
|
|
|
|
$expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/foo/:action/*', array('controller' => 'bar'), array('named' => array('param1' => array('action' => 'index')), 'greedy' => true));
|
|
|
|
$result = Router::parse('/foo/index/param1:value1:1/param2:value2:3/param:value');
|
|
|
|
$expected = array('pass' => array(), 'named' => array('param1' => 'value1:1', 'param2' => 'value2:3', 'param' => 'value'), 'controller' => 'bar', 'action' => 'index', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/foo/view/param1:value1:1/param2:value2:3/param:value');
|
|
|
|
$expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'bar', 'action' => 'view', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connectNamed(array('param1' => '[\d]', 'param2' => '[a-z]', 'param3' => '[\d]'));
|
|
|
|
$result = Router::parse('/controller/action/param1:1/param2:2/param3:3');
|
|
|
|
$expected = array('pass' => array('param2:2'), 'named' => array('param1' => '1', 'param3' => '3'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connectNamed(array('param1' => '[\d]', 'param2' => true, 'param3' => '[\d]'));
|
|
|
|
$result = Router::parse('/controller/action/param1:1/param2:2/param3:3');
|
|
|
|
$expected = array('pass' => array(), 'named' => array('param1' => '1', 'param2' => '2', 'param3' => '3'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connectNamed(array('param1' => 'value[\d]+:[\d]+'), array('greedy' => false));
|
|
|
|
$result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param3:value');
|
|
|
|
$expected = array('pass' => array('param2:value2:3', 'param3:value'), 'named' => array('param1' => 'value1:1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar'), array('named' => array('param1' => 'value[\d]:[\d]')));
|
|
|
|
Router::connectNamed(array(), array('greedy' => false));
|
|
|
|
$result = Router::parse('/foo/param1:value1:1/param2:value2:3/param3:value');
|
|
|
|
$expected = array('pass' => array('param2:value2:3', 'param3:value'), 'named' => array('param1' => 'value1:1'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-09-27 05:22:46 +00:00
|
|
|
* test url generation with legacy (1.2) style prefix routes.
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-09-27 05:22:46 +00:00
|
|
|
* @todo Remove tests related to legacy style routes.
|
|
|
|
* @see testUrlGenerationWithAutoPrefixes
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2009-09-27 05:22:46 +00:00
|
|
|
function testUrlGenerationWithLegacyPrefixes() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect('/protected/:controller/:action/*', array(
|
2009-11-29 21:09:45 +00:00
|
|
|
'prefix' => 'protected',
|
|
|
|
'protected' => true
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'admin' => false, 'form' => array(), 'url' => array('url' => 'images/index')),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/images/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = Router::url(array('protected' => true));
|
|
|
|
$expected = '/protected/images/index';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1));
|
|
|
|
$expected = '/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1));
|
|
|
|
$expected = '/others/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-04-20 07:36:26 +00:00
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true));
|
2008-07-05 14:48:09 +00:00
|
|
|
$expected = '/protected/others/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-20 07:36:26 +00:00
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1));
|
|
|
|
$expected = '/protected/others/edit/1/page:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-20 07:36:26 +00:00
|
|
|
Router::connectNamed(array('random'));
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'random' => 'my-value'));
|
|
|
|
$expected = '/protected/others/edit/1/random:my-value';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-09-27 05:22:46 +00:00
|
|
|
/**
|
|
|
|
* test newer style automatically generated prefix routes.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-09-27 05:22:46 +00:00
|
|
|
function testUrlGenerationWithAutoPrefixes() {
|
|
|
|
Configure::write('Routing.prefixes', array('protected'));
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'protected' => false, 'form' => array(), 'url' => array('url' => 'images/index')),
|
|
|
|
array('base' => '', 'here' => '/images/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1));
|
|
|
|
$expected = '/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1));
|
|
|
|
$expected = '/others/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/others/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1));
|
|
|
|
$expected = '/protected/others/edit/1/page:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::connectNamed(array('random'));
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'random' => 'my-value'));
|
|
|
|
$expected = '/protected/others/edit/1/random:my-value';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that auto-generated prefix routes persist
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-09-27 05:22:46 +00:00
|
|
|
function testAutoPrefixRoutePersistence() {
|
|
|
|
Configure::write('Routing.prefixes', array('protected'));
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array('url' => 'protected/images/index')),
|
|
|
|
array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/protected/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => false));
|
|
|
|
$expected = '/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
2009-09-30 14:19:43 +00:00
|
|
|
/**
|
|
|
|
* test that setting a prefix override the current one
|
2009-11-05 04:05:25 +00:00
|
|
|
*
|
2009-09-30 14:19:43 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testPrefixOverride() {
|
|
|
|
Configure::write('Routing.prefixes', array('protected', 'admin'));
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array('url' => 'protected/images/index')),
|
|
|
|
array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'admin' => true));
|
|
|
|
$expected = '/admin/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-11-05 04:05:25 +00:00
|
|
|
|
2009-09-30 14:19:43 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/images/index')),
|
|
|
|
array('base' => '', 'here' => '/admin/images/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRemoveBase method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRemoveBase() {
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'plugin' => null),
|
|
|
|
array('base' => '/base', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action'));
|
2009-10-02 18:00:33 +00:00
|
|
|
$expected = '/base/my_controller/my_action';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => false));
|
2009-10-02 18:00:33 +00:00
|
|
|
$expected = '/my_controller/my_action';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => true));
|
|
|
|
$expected = '/base/my_controller/my_action/base:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPagesUrlParsing method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPagesUrlParsing() {
|
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
|
|
|
|
$result = Router::parse('/');
|
2009-11-27 04:46:42 +00:00
|
|
|
$expected = array('pass'=> array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/pages/home/');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
|
|
|
|
$result = Router::parse('/pages/display/home/parameter:value');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array('parameter' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
|
|
|
|
$result = Router::parse('/');
|
2009-11-28 14:40:15 +00:00
|
|
|
$expected = array('pass' => array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/pages/display/home/event:value');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array('event' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/pages/display/home/event:Val_u2');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array('event' => 'Val_u2'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/pages/display/home/event:val-ue');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array('event' => 'val-ue'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
$result = Router::parse('/pages/contact/');
|
|
|
|
|
|
|
|
$expected = array('pass'=>array('contact'), 'named' => array(), 'plugin'=> null, 'controller'=>'pages', 'action'=>'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testParsingWithPrefixes method
|
2008-06-14 21:12:56 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParsingWithPrefixes() {
|
|
|
|
$adminParams = array('prefix' => 'admin', 'admin' => true);
|
|
|
|
Router::connect('/admin/:controller', $adminParams);
|
|
|
|
Router::connect('/admin/:controller/:action', $adminParams);
|
|
|
|
Router::connect('/admin/:controller/:action/*', $adminParams);
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
|
|
|
|
array('base' => '/base', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::parse('/admin/posts/');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'admin' => true);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/admin/posts');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('admin' => true, 'controller' => 'posts'));
|
|
|
|
$expected = '/base/admin/posts';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::prefixes();
|
|
|
|
$expected = array('admin');
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
Router::reload();
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
$prefixParams = array('prefix' => 'members', 'members' => true);
|
|
|
|
Router::connect('/members/:controller', $prefixParams);
|
|
|
|
Router::connect('/members/:controller/:action', $prefixParams);
|
|
|
|
Router::connect('/members/:controller/:action/*', $prefixParams);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
|
|
|
|
array('base' => '/base', 'here' => '/', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
|
|
|
));
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
$result = Router::parse('/members/posts/index');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'members' => true);
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
$result = Router::url(array('members' => true, 'controller' => 'posts', 'action' =>'index', 'page' => 2));
|
|
|
|
$expected = '/base/members/posts/index/page:2';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
$result = Router::url(array('members' => true, 'controller' => 'users', 'action' => 'add'));
|
|
|
|
$expected = '/base/members/users/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
$result = Router::parse('/posts/index');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'index');
|
2008-08-13 18:07:52 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-09 14:28:32 +00:00
|
|
|
/**
|
|
|
|
* Tests URL generation with flags and prefixes in and out of context
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUrlWritingWithPrefixes() {
|
|
|
|
Router::connect('/company/:controller/:action/*', array('prefix' => 'company', 'company' => true));
|
|
|
|
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => true));
|
|
|
|
$expected = '/company/users/login';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('controller' => 'users', 'action' => 'login', 'company' => true, 'form' => array(), 'url' => array(), 'plugin' => null),
|
2010-04-12 03:13:18 +00:00
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/')
|
2008-07-09 14:28:32 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => false));
|
|
|
|
$expected = '/login';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-04-12 03:13:18 +00:00
|
|
|
/**
|
|
|
|
* test url generation with prefixes and custom routes
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUrlWritingWithPrefixesAndCustomRoutes() {
|
|
|
|
Router::connect(
|
|
|
|
'/admin/login',
|
|
|
|
array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true)
|
|
|
|
);
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('controller' => 'posts', 'action' => 'index', 'admin' => true, 'prefix' => 'admin',
|
|
|
|
'form' => array(), 'url' => array(), 'plugin' => null
|
|
|
|
),
|
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true));
|
|
|
|
$this->assertEqual($result, '/admin/login');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'login'));
|
|
|
|
$this->assertEqual($result, '/admin/login');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'admin_login'));
|
|
|
|
$this->assertEqual($result, '/admin/login');
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testPassedArgsOrder method
|
2008-06-14 21:12:56 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPassedArgsOrder() {
|
2009-11-29 14:49:19 +00:00
|
|
|
Router::connect('/test-passed/*', array('controller' => 'pages', 'action' => 'display', 'home'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
|
|
|
|
Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1));
|
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 1, 'whatever'));
|
|
|
|
$expected = '/test/whatever';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 2, 'whatever'));
|
|
|
|
$expected = '/test2/whatever';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-11-29 14:49:19 +00:00
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 'home', 'whatever'));
|
|
|
|
$expected = '/test-passed/whatever';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-10-02 18:00:33 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
2009-10-02 18:00:33 +00:00
|
|
|
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'named' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array ('url' => 'protected/images/index')),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/protected/images/index', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
Router::connect('/protected/:controller/:action/*', array(
|
2009-11-29 04:37:40 +00:00
|
|
|
'controller' => 'users',
|
|
|
|
'action' => 'index',
|
|
|
|
'prefix' => 'protected'
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
Router::parse('/');
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/protected/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::prefixes();
|
2009-09-27 02:37:19 +00:00
|
|
|
$expected = array('admin', 'protected');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRegexRouteMatching method
|
2008-06-14 21:12:56 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRegexRouteMatching() {
|
|
|
|
Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng'));
|
|
|
|
|
|
|
|
$result = Router::parse('/test/test_action');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'controller' => 'test', 'action' => 'test_action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/eng/test/test_action');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'locale' => 'eng', 'controller' => 'test', 'action' => 'test_action', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::parse('/badness/test/test_action');
|
|
|
|
$expected = array('pass' => array('test_action'), 'named' => array(), 'controller' => 'badness', 'action' => 'test', 'plugin' => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng'));
|
|
|
|
|
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array('plugin' => null, 'controller' => 'test', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array ('url' => 'test/test_action')),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/test/test_action', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'test_another_action'));
|
2009-10-02 18:00:33 +00:00
|
|
|
$expected = '/test/test_another_action';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'test_another_action', 'locale' => 'eng'));
|
|
|
|
$expected = '/eng/test/test_another_action';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'test_another_action', 'locale' => 'badness'));
|
|
|
|
$expected = '/test/test_another_action/locale:badness';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-22 13:02:31 +00:00
|
|
|
/**
|
|
|
|
* testStripPlugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testStripPlugin() {
|
2009-07-22 13:02:31 +00:00
|
|
|
$pluginName = 'forums';
|
|
|
|
$url = 'example.com/' . $pluginName . '/';
|
|
|
|
$expected = 'example.com';
|
|
|
|
|
|
|
|
$this->assertEqual(Router::stripPlugin($url, $pluginName), $expected);
|
|
|
|
$this->assertEqual(Router::stripPlugin($url), $url);
|
|
|
|
$this->assertEqual(Router::stripPlugin($url, null), $url);
|
|
|
|
}
|
2009-07-28 09:49:27 +00:00
|
|
|
/**
|
|
|
|
* testCurentRoute
|
|
|
|
*
|
|
|
|
* This test needs some improvement and actual requestAction() usage
|
2009-09-30 13:49:39 +00:00
|
|
|
*
|
2009-07-28 09:49:27 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testCurrentRoute() {
|
2009-07-28 09:49:27 +00:00
|
|
|
$url = array('controller' => 'pages', 'action' => 'display', 'government');
|
|
|
|
Router::connect('/government', $url);
|
|
|
|
Router::parse('/government');
|
2009-10-02 05:36:27 +00:00
|
|
|
$route =& Router::currentRoute();
|
2009-12-16 20:04:59 +00:00
|
|
|
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
2009-07-28 09:49:27 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testRequestRoute
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testRequestRoute() {
|
2009-07-28 09:49:27 +00:00
|
|
|
$url = array('controller' => 'products', 'action' => 'display', 5);
|
|
|
|
Router::connect('/government', $url);
|
|
|
|
Router::parse('/government');
|
2009-10-02 05:36:27 +00:00
|
|
|
$route =& Router::requestRoute();
|
2009-12-16 20:04:59 +00:00
|
|
|
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
2009-07-28 09:49:27 +00:00
|
|
|
|
|
|
|
// test that the first route is matched
|
|
|
|
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
|
|
|
|
Router::connect('/government', $url);
|
|
|
|
Router::parse('/government');
|
2009-10-02 05:36:27 +00:00
|
|
|
$route =& Router::requestRoute();
|
2009-12-16 20:04:59 +00:00
|
|
|
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
2009-07-28 09:49:27 +00:00
|
|
|
|
|
|
|
// test that an unmatched route does not change the current route
|
|
|
|
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
|
|
|
|
Router::connect('/actor', $url);
|
|
|
|
Router::parse('/government');
|
2009-10-02 05:36:27 +00:00
|
|
|
$route =& Router::requestRoute();
|
2009-12-16 20:04:59 +00:00
|
|
|
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
2009-07-28 09:49:27 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testGetParams
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetParams() {
|
2009-07-28 09:49:27 +00:00
|
|
|
$paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot');
|
|
|
|
$params = array('param1' => '1', 'param2' => '2');
|
|
|
|
Router::setRequestInfo(array($params, $paths));
|
|
|
|
$expected = array(
|
2009-12-16 20:04:59 +00:00
|
|
|
'plugin' => null, 'controller' => false, 'action' => false,
|
2009-07-28 09:49:27 +00:00
|
|
|
'param1' => '1', 'param2' => '2'
|
|
|
|
);
|
|
|
|
$this->assertEqual(Router::getparams(), $expected);
|
|
|
|
$this->assertEqual(Router::getparam('controller'), false);
|
|
|
|
$this->assertEqual(Router::getparam('param1'), '1');
|
|
|
|
$this->assertEqual(Router::getparam('param2'), '2');
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
$params = array('controller' => 'pages', 'action' => 'display');
|
|
|
|
Router::setRequestInfo(array($params, $paths));
|
2009-12-16 20:04:59 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2009-07-28 09:49:27 +00:00
|
|
|
$this->assertEqual(Router::getparams(), $expected);
|
|
|
|
$this->assertEqual(Router::getparams(true), $expected);
|
|
|
|
}
|
2009-11-26 04:39:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that connectDefaults() can disable default route connection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-12-04 01:50:13 +00:00
|
|
|
function testDefaultsMethod() {
|
2009-11-26 04:39:07 +00:00
|
|
|
Router::defaults(false);
|
|
|
|
Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 2));
|
|
|
|
$result = Router::parse('/posts/edit/5');
|
|
|
|
$this->assertFalse(isset($result['controller']));
|
|
|
|
$this->assertFalse(isset($result['action']));
|
|
|
|
}
|
2009-12-04 01:50:13 +00:00
|
|
|
|
2010-01-18 15:05:23 +00:00
|
|
|
/**
|
|
|
|
* test that the required default routes are connected.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testConnectDefaultRoutes() {
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(
|
|
|
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
|
|
|
|
)
|
|
|
|
), true);
|
|
|
|
App::objects('plugin', null, false);
|
2010-04-08 04:03:46 +00:00
|
|
|
Router::reload();
|
2010-01-18 15:05:23 +00:00
|
|
|
|
|
|
|
$plugins = App::objects('plugin');
|
|
|
|
$plugin = Inflector::underscore($plugins[0]);
|
|
|
|
$result = Router::url(array('plugin' => $plugin, 'controller' => 'js_file', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/plugin_js/js_file');
|
|
|
|
|
|
|
|
$result = Router::parse('/plugin_js/js_file');
|
|
|
|
$expected = array(
|
|
|
|
'plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index',
|
|
|
|
'named' => array(), 'pass' => array()
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
2010-04-08 04:03:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/test_plugin');
|
|
|
|
|
|
|
|
$result = Router::parse('/test_plugin');
|
|
|
|
$expected = array(
|
|
|
|
'plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index',
|
|
|
|
'named' => array(), 'pass' => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected, 'Plugin shortcut route broken. %s');
|
2010-01-18 15:05:23 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 01:50:13 +00:00
|
|
|
/**
|
|
|
|
* test using a custom route class for route connection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUsingCustomRouteClass() {
|
2009-12-04 02:20:08 +00:00
|
|
|
Mock::generate('CakeRoute', 'MockConnectedRoute');
|
2009-12-04 01:50:13 +00:00
|
|
|
$routes = Router::connect(
|
|
|
|
'/:slug',
|
|
|
|
array('controller' => 'posts', 'action' => 'view'),
|
|
|
|
array('routeClass' => 'MockConnectedRoute', 'slug' => '[a-z_-]+')
|
|
|
|
);
|
|
|
|
$this->assertTrue(is_a($routes[0], 'MockConnectedRoute'), 'Incorrect class used. %s');
|
|
|
|
$expected = array('controller' => 'posts', 'action' => 'view', 'slug' => 'test');
|
|
|
|
$routes[0]->setReturnValue('parse', $expected);
|
|
|
|
$result = Router::parse('/test');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-12-28 04:09:26 +00:00
|
|
|
|
2010-04-24 00:22:02 +00:00
|
|
|
/**
|
|
|
|
* test that route classes must extend CakeRoute
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCustomRouteException() {
|
2010-04-24 00:42:53 +00:00
|
|
|
$this->expectException();
|
|
|
|
Router::connect('/:controller', array(), array('routeClass' => 'Object'));
|
2010-04-24 00:22:02 +00:00
|
|
|
}
|
|
|
|
|
2009-12-28 04:09:26 +00:00
|
|
|
/**
|
|
|
|
* test reversing parameter arrays back into strings.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRouterReverse() {
|
|
|
|
$params = array(
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array()
|
|
|
|
);
|
|
|
|
$result = Router::reverse($params);
|
|
|
|
$this->assertEqual($result, '/posts/view/1');
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'index',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array('page' => 1, 'sort' => 'Article.title', 'direction' => 'desc'),
|
|
|
|
'url' => array()
|
|
|
|
);
|
|
|
|
$result = Router::reverse($params);
|
|
|
|
$this->assertEqual($result, '/posts/index/1/page:1/sort:Article.title/direction:desc');
|
|
|
|
|
|
|
|
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
|
|
|
|
$params = array(
|
|
|
|
'lang' => 'eng',
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' => 'eng/posts/view/1')
|
|
|
|
);
|
|
|
|
$result = Router::reverse($params);
|
|
|
|
$this->assertEqual($result, '/eng/posts/view/1');
|
2009-12-28 04:10:29 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'lang' => 'eng',
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array(),
|
2009-12-28 18:34:05 +00:00
|
|
|
'url' => array('url' => 'eng/posts/view/1', 'foo' => 'bar', 'baz' => 'quu'),
|
|
|
|
'paging' => array(),
|
|
|
|
'models' => array()
|
2009-12-28 04:10:29 +00:00
|
|
|
);
|
|
|
|
$result = Router::reverse($params);
|
|
|
|
$this->assertEqual($result, '/eng/posts/view/1?foo=bar&baz=quu');
|
2009-12-28 04:09:26 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-11-27 04:46:42 +00:00
|
|
|
|
2009-09-30 13:49:39 +00:00
|
|
|
/**
|
2009-12-04 02:20:08 +00:00
|
|
|
* Test case for CakeRoute
|
2009-09-30 13:49:39 +00:00
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs.
|
|
|
|
**/
|
2009-12-04 02:20:08 +00:00
|
|
|
class CakeRouteTestCase extends CakeTestCase {
|
2009-09-30 13:49:39 +00:00
|
|
|
/**
|
2009-10-09 02:20:40 +00:00
|
|
|
* startTest method
|
2009-09-30 13:49:39 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-10-09 02:20:40 +00:00
|
|
|
function startTest() {
|
2009-09-30 13:49:39 +00:00
|
|
|
$this->_routing = Configure::read('Routing');
|
|
|
|
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
|
|
|
|
Router::reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* end the test and reset the environment
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function endTest() {
|
|
|
|
Configure::write('Routing', $this->_routing);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 02:20:08 +00:00
|
|
|
* Test the construction of a CakeRoute
|
2009-09-30 13:49:39 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testConstruction() {
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/:controller/:action/:id', array(), array('id' => '[0-9]+'));
|
2009-09-30 13:49:39 +00:00
|
|
|
|
2009-10-02 05:09:38 +00:00
|
|
|
$this->assertEqual($route->template, '/:controller/:action/:id');
|
2009-11-29 21:09:45 +00:00
|
|
|
$this->assertEqual($route->defaults, array());
|
2009-12-02 05:20:51 +00:00
|
|
|
$this->assertEqual($route->options, array('id' => '[0-9]+'));
|
2009-09-30 13:49:39 +00:00
|
|
|
$this->assertFalse($route->compiled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test Route compiling.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
2009-10-08 18:04:14 +00:00
|
|
|
function testBasicRouteCompiling() {
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
2009-09-30 13:49:39 +00:00
|
|
|
$result = $route->compile();
|
2009-10-08 18:04:14 +00:00
|
|
|
$expected = '#^/*$#';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
$this->assertEqual($route->keys, array());
|
2009-11-05 04:05:25 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/:controller/:action', array('controller' => 'posts'));
|
2009-10-08 18:04:14 +00:00
|
|
|
$result = $route->compile();
|
2009-11-27 02:42:33 +00:00
|
|
|
|
|
|
|
$this->assertPattern($result, '/posts/edit');
|
|
|
|
$this->assertPattern($result, '/posts/super_delete');
|
|
|
|
$this->assertNoPattern($result, '/posts');
|
|
|
|
$this->assertNoPattern($result, '/posts/super_delete/1');
|
2009-09-30 13:49:39 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/posts/foo:id', array('controller' => 'posts', 'action' => 'view'));
|
2009-09-30 13:49:39 +00:00
|
|
|
$result = $route->compile();
|
|
|
|
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertPattern($result, '/posts/foo:1');
|
|
|
|
$this->assertPattern($result, '/posts/foo:param');
|
|
|
|
$this->assertNoPattern($result, '/posts');
|
|
|
|
$this->assertNoPattern($result, '/posts/');
|
|
|
|
|
|
|
|
$this->assertEqual($route->keys, array('id'));
|
2009-09-30 13:49:39 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/:plugin/:controller/:action/*', array('plugin' => 'test_plugin', 'action' => 'index'));
|
2009-09-30 13:49:39 +00:00
|
|
|
$result = $route->compile();
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertPattern($result, '/test_plugin/posts/index');
|
|
|
|
$this->assertPattern($result, '/test_plugin/posts/edit/5');
|
|
|
|
$this->assertPattern($result, '/test_plugin/posts/edit/5/name:value/nick:name');
|
2009-10-08 18:04:14 +00:00
|
|
|
}
|
2009-11-27 02:42:33 +00:00
|
|
|
|
2010-04-10 15:17:24 +00:00
|
|
|
/**
|
|
|
|
* test that route parameters that overlap don't cause errors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRouteParameterOverlap() {
|
|
|
|
$route =& new CakeRoute('/invoices/add/:idd/:id', array('controller' => 'invoices', 'action' => 'add'));
|
|
|
|
$result = $route->compile();
|
|
|
|
$this->assertPattern($result, '/invoices/add/1/3');
|
|
|
|
|
|
|
|
$route =& new CakeRoute('/invoices/add/:id/:idd', array('controller' => 'invoices', 'action' => 'add'));
|
|
|
|
$result = $route->compile();
|
|
|
|
$this->assertPattern($result, '/invoices/add/1/3');
|
|
|
|
}
|
|
|
|
|
2009-10-08 18:04:14 +00:00
|
|
|
/**
|
|
|
|
* test compiling routes with keys that have patterns
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testRouteCompilingWithParamPatterns() {
|
|
|
|
extract(Router::getNamedExpressions());
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route = new CakeRoute(
|
2009-11-27 14:58:51 +00:00
|
|
|
'/:controller/:action/:id',
|
2009-11-29 21:09:45 +00:00
|
|
|
array(),
|
2009-11-27 04:46:42 +00:00
|
|
|
array('id' => $ID)
|
|
|
|
);
|
2009-10-08 18:04:14 +00:00
|
|
|
$result = $route->compile();
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertPattern($result, '/posts/edit/1');
|
|
|
|
$this->assertPattern($result, '/posts/view/518098');
|
|
|
|
$this->assertNoPattern($result, '/posts/edit/name-of-post');
|
|
|
|
$this->assertNoPattern($result, '/posts/edit/4/other:param');
|
2009-10-02 05:09:38 +00:00
|
|
|
$this->assertEqual($route->keys, array('controller', 'action', 'id'));
|
2009-09-30 13:49:39 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute(
|
2009-11-05 04:05:25 +00:00
|
|
|
'/:lang/:controller/:action/:id',
|
|
|
|
array('controller' => 'testing4'),
|
2009-10-08 18:04:14 +00:00
|
|
|
array('id' => $ID, 'lang' => '[a-z]{3}')
|
|
|
|
);
|
2009-09-30 13:49:39 +00:00
|
|
|
$result = $route->compile();
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertPattern($result, '/eng/posts/edit/1');
|
|
|
|
$this->assertPattern($result, '/cze/articles/view/1');
|
|
|
|
$this->assertNoPattern($result, '/language/articles/view/2');
|
|
|
|
$this->assertNoPattern($result, '/eng/articles/view/name-of-article');
|
2009-10-08 18:04:14 +00:00
|
|
|
$this->assertEqual($route->keys, array('lang', 'controller', 'action', 'id'));
|
2009-10-02 05:09:38 +00:00
|
|
|
|
2009-09-30 13:49:39 +00:00
|
|
|
foreach (array(':', '@', ';', '$', '-') as $delim) {
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/posts/:id' . $delim . ':title');
|
2009-09-30 13:49:39 +00:00
|
|
|
$result = $route->compile();
|
2009-11-26 14:41:05 +00:00
|
|
|
|
|
|
|
$this->assertPattern($result, '/posts/1' . $delim . 'name-of-article');
|
|
|
|
$this->assertPattern($result, '/posts/13244' . $delim . 'name-of_Article[]');
|
2009-11-27 14:58:51 +00:00
|
|
|
$this->assertNoPattern($result, '/posts/11!nameofarticle');
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertNoPattern($result, '/posts/11');
|
2009-09-30 13:49:39 +00:00
|
|
|
|
2009-10-02 05:09:38 +00:00
|
|
|
$this->assertEqual($route->keys, array('id', 'title'));
|
2009-09-30 13:49:39 +00:00
|
|
|
}
|
2009-10-02 05:09:38 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute(
|
2009-10-08 18:04:14 +00:00
|
|
|
'/posts/:id::title/:year',
|
|
|
|
array('controller' => 'posts', 'action' => 'view'),
|
|
|
|
array('id' => $ID, 'year' => $Year, 'title' => '[a-z-_]+')
|
|
|
|
);
|
2009-09-30 13:49:39 +00:00
|
|
|
$result = $route->compile();
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertPattern($result, '/posts/1:name-of-article/2009/');
|
|
|
|
$this->assertPattern($result, '/posts/13244:name-of-article/1999');
|
|
|
|
$this->assertNoPattern($result, '/posts/hey_now:nameofarticle');
|
|
|
|
$this->assertNoPattern($result, '/posts/:nameofarticle/2009');
|
|
|
|
$this->assertNoPattern($result, '/posts/:nameofarticle/01');
|
2009-10-02 05:09:38 +00:00
|
|
|
$this->assertEqual($route->keys, array('id', 'title', 'year'));
|
2009-11-27 14:58:51 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute(
|
2009-11-26 04:51:27 +00:00
|
|
|
'/posts/:url_title-(uuid::id)',
|
2009-11-27 14:58:51 +00:00
|
|
|
array('controller' => 'posts', 'action' => 'view'),
|
2009-11-26 04:51:27 +00:00
|
|
|
array('pass' => array('id', 'url_title'), 'id' => $ID)
|
|
|
|
);
|
|
|
|
$result = $route->compile();
|
2009-11-26 14:41:05 +00:00
|
|
|
$this->assertPattern($result, '/posts/some_title_for_article-(uuid:12534)/');
|
|
|
|
$this->assertPattern($result, '/posts/some_title_for_article-(uuid:12534)');
|
|
|
|
$this->assertNoPattern($result, '/posts/');
|
|
|
|
$this->assertNoPattern($result, '/posts/nameofarticle');
|
|
|
|
$this->assertNoPattern($result, '/posts/nameofarticle-12347');
|
2009-11-26 04:51:27 +00:00
|
|
|
$this->assertEqual($route->keys, array('url_title', 'id'));
|
2009-09-30 13:49:39 +00:00
|
|
|
}
|
2009-10-02 05:09:38 +00:00
|
|
|
|
2009-11-27 04:46:42 +00:00
|
|
|
/**
|
|
|
|
* test more complex route compiling & parsing with mid route greedy stars
|
2009-11-28 14:40:15 +00:00
|
|
|
* and optional routing parameters
|
2009-11-27 04:46:42 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testComplexRouteCompilingAndParsing() {
|
|
|
|
extract(Router::getNamedExpressions());
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute(
|
2009-11-27 04:46:42 +00:00
|
|
|
'/posts/:month/:day/:year/*',
|
2009-11-29 21:09:45 +00:00
|
|
|
array('controller' => 'posts', 'action' => 'view'),
|
|
|
|
array('year' => $Year, 'month' => $Month, 'day' => $Day)
|
2009-11-27 04:46:42 +00:00
|
|
|
);
|
|
|
|
$result = $route->compile();
|
|
|
|
$this->assertPattern($result, '/posts/08/01/2007/title-of-post');
|
|
|
|
$result = $route->parse('/posts/08/01/2007/title-of-post');
|
2009-11-28 14:40:15 +00:00
|
|
|
|
2009-11-29 21:21:33 +00:00
|
|
|
$this->assertEqual(count($result), 8);
|
2009-11-28 14:40:15 +00:00
|
|
|
$this->assertEqual($result['controller'], 'posts');
|
|
|
|
$this->assertEqual($result['action'], 'view');
|
|
|
|
$this->assertEqual($result['year'], '2007');
|
|
|
|
$this->assertEqual($result['month'], '08');
|
|
|
|
$this->assertEqual($result['day'], '01');
|
2009-11-27 04:46:42 +00:00
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute(
|
2009-11-27 04:46:42 +00:00
|
|
|
"/:extra/page/:slug/*",
|
|
|
|
array('controller' => 'pages', 'action' => 'view', 'extra' => null),
|
|
|
|
array("extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+', "action" => 'view')
|
|
|
|
);
|
|
|
|
$result = $route->compile();
|
2009-11-27 14:58:51 +00:00
|
|
|
|
|
|
|
$this->assertPattern($result, '/some_extra/page/this_is_the_slug');
|
|
|
|
$this->assertPattern($result, '/page/this_is_the_slug');
|
2009-11-27 04:46:42 +00:00
|
|
|
$this->assertEqual($route->keys, array('extra', 'slug'));
|
2009-12-02 05:20:51 +00:00
|
|
|
$this->assertEqual($route->options, array('extra' => '[a-z1-9_]*', 'slug' => '[a-z1-9_]+', 'action' => 'view'));
|
2009-11-27 04:46:42 +00:00
|
|
|
$expected = array(
|
|
|
|
'controller' => 'pages',
|
|
|
|
'action' => 'view',
|
|
|
|
'extra' => null,
|
|
|
|
);
|
|
|
|
$this->assertEqual($route->defaults, $expected);
|
2009-12-16 20:04:59 +00:00
|
|
|
|
|
|
|
$route =& new CakeRoute(
|
|
|
|
'/:controller/:action/*',
|
|
|
|
array('project' => false),
|
|
|
|
array(
|
|
|
|
'controller' => 'source|wiki|commits|tickets|comments|view',
|
|
|
|
'action' => 'branches|history|branch|logs|view|start|add|edit|modify'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertFalse($route->parse('/chaw_test/wiki'));
|
|
|
|
|
|
|
|
$result = $route->compile();
|
|
|
|
$this->assertNoPattern($result, '/some_project/source');
|
|
|
|
$this->assertPattern($result, '/source/view');
|
|
|
|
$this->assertPattern($result, '/source/view/other/params');
|
|
|
|
$this->assertNoPattern($result, '/chaw_test/wiki');
|
|
|
|
$this->assertNoPattern($result, '/source/wierd_action');
|
2009-11-27 04:46:42 +00:00
|
|
|
}
|
|
|
|
|
2009-10-02 05:09:38 +00:00
|
|
|
/**
|
|
|
|
* test that routes match their pattern.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
2009-11-29 21:09:45 +00:00
|
|
|
function testMatchBasic() {
|
2009-12-04 02:20:08 +00:00
|
|
|
$route = new CakeRoute('/:controller/:action/:id', array('plugin' => null));
|
2009-11-30 03:57:10 +00:00
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 0));
|
2009-11-29 21:09:45 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2009-11-30 03:57:10 +00:00
|
|
|
$result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => 1));
|
|
|
|
$this->assertEqual($result, '/posts/view/1');
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$this->assertEqual($result, '/');
|
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 'about'));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$this->assertEqual($result, '/pages/home');
|
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 'about'));
|
|
|
|
$this->assertEqual($result, '/pages/about');
|
|
|
|
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/blog/:action', array('controller' => 'posts'));
|
2009-10-02 05:09:38 +00:00
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view'));
|
|
|
|
$this->assertEqual($result, '/blog/view');
|
2009-11-05 04:05:25 +00:00
|
|
|
|
2009-11-30 03:57:10 +00:00
|
|
|
$result = $route->match(array('controller' => 'nodes', 'action' => 'view'));
|
|
|
|
$this->assertFalse($result);
|
2009-11-30 05:23:41 +00:00
|
|
|
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 1));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'id' => 2));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/foo/:controller/:action', array('action' => 'index'));
|
2009-12-01 18:38:32 +00:00
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view'));
|
|
|
|
$this->assertEqual($result, '/foo/posts/view');
|
|
|
|
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view'));
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = $route->match(array('plugin' => 'test', 'controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
|
|
|
$this->assertEqual($result, '/test/1/');
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'fo', 'controller' => 'posts', 'action' => 'view', 'id' => '1', '0'));
|
|
|
|
$this->assertEqual($result, '/fo/1/0');
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'fo', 'controller' => 'nodes', 'action' => 'view', 'id' => 1));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'fo', 'controller' => 'posts', 'action' => 'edit', 'id' => 1));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/admin/subscriptions/:action/*', array(
|
2009-10-02 18:00:33 +00:00
|
|
|
'controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'
|
|
|
|
));
|
|
|
|
|
2009-11-29 21:21:33 +00:00
|
|
|
$url = array('controller' => 'subscribe', 'admin' => true, 'action' => 'edit', 1);
|
2009-10-02 18:00:33 +00:00
|
|
|
$result = $route->match($url);
|
2009-11-29 21:09:45 +00:00
|
|
|
$expected = '/admin/subscriptions/edit/1';
|
2009-10-02 18:00:33 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2009-10-02 05:09:38 +00:00
|
|
|
}
|
2009-11-27 04:01:54 +00:00
|
|
|
|
2009-11-30 03:57:10 +00:00
|
|
|
/**
|
|
|
|
* test match() with greedy routes, named parameters and passed args.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-11-30 05:23:41 +00:00
|
|
|
function testMatchWithNamedParametersAndPassedArgs() {
|
2009-11-30 03:57:10 +00:00
|
|
|
Router::connectNamed(true);
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route = new CakeRoute('/:controller/:action/*', array('plugin' => null));
|
2009-11-30 03:57:10 +00:00
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'page' => 1));
|
|
|
|
$this->assertEqual($result, '/posts/index/page:1');
|
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5));
|
|
|
|
$this->assertEqual($result, '/posts/view/5');
|
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, 'page' => 1, 'limit' => 20, 'order' => 'title'));
|
|
|
|
$this->assertEqual($result, '/posts/view/5/page:1/limit:20/order:title');
|
2009-11-30 05:23:41 +00:00
|
|
|
|
|
|
|
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
|
2009-11-30 05:23:41 +00:00
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 1));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 2, 'something'));
|
|
|
|
$this->assertEqual($result, '/test2/something');
|
2009-12-09 02:43:29 +00:00
|
|
|
|
|
|
|
$result = $route->match(array('controller' => 'pages', 'action' => 'display', 5, 'something'));
|
|
|
|
$this->assertFalse($result);
|
2009-11-30 03:57:10 +00:00
|
|
|
}
|
|
|
|
|
2009-11-29 21:09:45 +00:00
|
|
|
/**
|
|
|
|
* test that match with patterns works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMatchWithPatterns() {
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute('/:controller/:action/:id', array('plugin' => null), array('id' => '[0-9]+'));
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'id' => 'foo'));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2009-11-29 21:21:33 +00:00
|
|
|
$result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => '9'));
|
2009-11-29 21:09:45 +00:00
|
|
|
$this->assertEqual($result, '/posts/view/9');
|
|
|
|
|
2009-11-29 21:21:33 +00:00
|
|
|
$result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => '922'));
|
2009-11-29 21:09:45 +00:00
|
|
|
$this->assertEqual($result, '/posts/view/922');
|
2009-12-01 20:04:53 +00:00
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => 'a99'));
|
|
|
|
$this->assertFalse($result);
|
2009-11-29 21:09:45 +00:00
|
|
|
}
|
|
|
|
|
2009-11-29 15:59:38 +00:00
|
|
|
/**
|
|
|
|
* test persistParams ability to persist parameters from $params and remove params.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testPersistParams() {
|
2009-12-04 02:20:08 +00:00
|
|
|
$route =& new CakeRoute(
|
2009-11-29 15:59:38 +00:00
|
|
|
'/:lang/:color/blog/:action',
|
|
|
|
array('controller' => 'posts'),
|
|
|
|
array('persist' => array('lang', 'color'))
|
|
|
|
);
|
|
|
|
$url = array('controller' => 'posts', 'action' => 'index');
|
|
|
|
$params = array('lang' => 'en', 'color' => 'blue');
|
|
|
|
$result = $route->persistParams($url, $params);
|
2009-12-14 23:43:29 +00:00
|
|
|
$this->assertEqual($result['lang'], 'en');
|
|
|
|
$this->assertEqual($result['color'], 'blue');
|
|
|
|
|
|
|
|
$url = array('controller' => 'posts', 'action' => 'index', 'color' => 'red');
|
|
|
|
$params = array('lang' => 'en', 'color' => 'blue');
|
|
|
|
$result = $route->persistParams($url, $params);
|
|
|
|
$this->assertEqual($result['lang'], 'en');
|
|
|
|
$this->assertEqual($result['color'], 'red');
|
2009-11-29 15:59:38 +00:00
|
|
|
}
|
|
|
|
|
2009-11-27 04:01:54 +00:00
|
|
|
/**
|
2009-12-04 02:20:08 +00:00
|
|
|
* test the parse method of CakeRoute.
|
2009-11-27 04:01:54 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testParse() {
|
|
|
|
extract(Router::getNamedExpressions());
|
2010-01-25 17:49:12 +00:00
|
|
|
$route =& new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $ID));
|
2009-11-27 04:01:54 +00:00
|
|
|
$route->compile();
|
|
|
|
$result = $route->parse('/posts/view/1');
|
2009-11-28 14:40:15 +00:00
|
|
|
$this->assertEqual($result['controller'], 'posts');
|
|
|
|
$this->assertEqual($result['action'], 'view');
|
|
|
|
$this->assertEqual($result['id'], '1');
|
2010-01-25 17:49:12 +00:00
|
|
|
|
|
|
|
$route =& new Cakeroute(
|
|
|
|
'/admin/:controller',
|
|
|
|
array('prefix' => 'admin', 'admin' => 1, 'action' => 'index')
|
|
|
|
);
|
|
|
|
$route->compile();
|
|
|
|
$result = $route->parse('/admin/');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $route->parse('/admin/posts');
|
|
|
|
$this->assertEqual($result['controller'], 'posts');
|
|
|
|
$this->assertEqual($result['action'], 'index');
|
2009-11-27 04:01:54 +00:00
|
|
|
}
|
2009-09-30 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2010-04-07 03:05:04 +00:00
|
|
|
/**
|
|
|
|
* test case for PluginShortRoute
|
|
|
|
*
|
|
|
|
* @package cake.tests.libs
|
|
|
|
*/
|
|
|
|
class PluginShortRouteTestCase extends CakeTestCase {
|
|
|
|
/**
|
|
|
|
* startTest method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function startTest() {
|
|
|
|
$this->_routing = Configure::read('Routing');
|
|
|
|
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
|
|
|
|
Router::reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* end the test and reset the environment
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function endTest() {
|
|
|
|
Configure::write('Routing', $this->_routing);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the parsing of routes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testParsing() {
|
|
|
|
$route =& new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
|
|
|
|
|
|
|
|
$result = $route->parse('/foo');
|
|
|
|
$this->assertEqual($result['plugin'], 'foo');
|
|
|
|
$this->assertEqual($result['controller'], 'foo');
|
|
|
|
$this->assertEqual($result['action'], 'index');
|
|
|
|
|
|
|
|
$result = $route->parse('/wrong');
|
|
|
|
$this->assertFalse($result, 'Wrong plugin name matched %s');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the reverse routing of the plugin shortcut urls.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMatch() {
|
|
|
|
$route =& new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'foo', 'controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->assertFalse($result, 'plugin controller mismatch was converted. %s');
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'foo', 'controller' => 'foo', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/foo');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|