2007-02-03 22:20:13 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
|
*/
|
2007-07-08 01:17:57 +00:00
|
|
|
uses('router', 'debugger');
|
2007-02-26 02:11:30 +00:00
|
|
|
|
2007-02-03 22:20:13 +00:00
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
|
|
|
class RouterTest extends UnitTestCase {
|
|
|
|
|
2007-02-22 23:41:00 +00:00
|
|
|
function setUp() {
|
|
|
|
$this->router =& Router::getInstance();
|
|
|
|
}
|
|
|
|
|
2007-02-03 22:20:13 +00:00
|
|
|
function testReturnedInstanceReference() {
|
2007-02-22 23:41:00 +00:00
|
|
|
$this->router->testVar = 'test';
|
|
|
|
$this->assertIdentical($this->router, Router::getInstance());
|
|
|
|
unset($this->router->testVar);
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRouteWriting() {
|
2007-02-22 23:41:00 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$this->router->connect('/');
|
|
|
|
$this->assertEqual($this->router->routes[0][0], '/');
|
|
|
|
$this->assertEqual($this->router->routes[0][1], '/^[\/]*$/');
|
|
|
|
$this->assertEqual($this->router->routes[0][2], array());
|
|
|
|
|
2007-08-15 14:18:39 +00:00
|
|
|
$this->router->reload();
|
2007-02-22 23:41:00 +00:00
|
|
|
$this->router->connect('/', array('controller' => 'testing'));
|
|
|
|
$this->assertTrue(is_array($this->router->routes[0][3]) && !empty($this->router->routes[0][3]));
|
|
|
|
$this->assertEqual($this->router->routes[0][3]['controller'], 'testing');
|
|
|
|
$this->assertEqual($this->router->routes[0][3]['action'], 'index');
|
|
|
|
$this->assertEqual(count($this->router->routes[0][3]), 3);
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/:controller', array('controller' => 'testing2'));
|
|
|
|
$this->assertTrue(is_array($this->router->routes[0][3]) && !empty($this->router->routes[0][3]), '/');
|
|
|
|
$this->assertEqual($this->router->routes[0][3]['controller'], 'testing2');
|
|
|
|
$this->assertEqual($this->router->routes[0][3]['action'], 'index');
|
|
|
|
$this->assertEqual(count($this->router->routes[0][3]), 3);
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/:controller/:action', array('controller' => 'testing3'));
|
|
|
|
$this->assertEqual($this->router->routes[0][0], '/:controller/:action');
|
|
|
|
$this->assertEqual($this->router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?[\/]*$#');
|
|
|
|
$this->assertEqual($this->router->routes[0][2], array('controller', 'action'));
|
|
|
|
$this->assertEqual($this->router->routes[0][3], array('controller' => 'testing3', 'action' => 'index', 'plugin' => null));
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $this->router->__named['ID']));
|
|
|
|
$this->assertEqual($this->router->routes[0][0], '/:controller/:action/:id');
|
|
|
|
$this->assertEqual($this->router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?(?:\/([0-9]+))?[\/]*$#');
|
|
|
|
$this->assertEqual($this->router->routes[0][2], array('controller', 'action', 'id'));
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/:controller/:action/:id', array('controller' => 'testing4'), array('id' => $this->router->__named['ID']));
|
|
|
|
$this->assertEqual($this->router->routes[0][1], '#^(?:\/([^\/]+))?(?:\/([^\/]+))?(?:\/([0-9]+))[\/]*$#');
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRouterIdentity() {
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->reload();
|
2007-02-03 22:20:13 +00:00
|
|
|
$router2 = new Router();
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual(get_object_vars($this->router), get_object_vars($router2));
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 13:50:50 +00:00
|
|
|
function testResourceRoutes() {
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->mapResources('Posts');
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = $this->router->parse('/posts');
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($result, array('pass' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => 'GET'));
|
2007-07-24 13:50:50 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = $this->router->parse('/posts/13');
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($result, array('pass' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => '13', '[method]' => 'GET'));
|
2007-07-24 13:50:50 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$result = $this->router->parse('/posts');
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($result, array('pass' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST'));
|
2007-07-24 13:50:50 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$result = $this->router->parse('/posts/13');
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($result, array('pass' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '13', '[method]' => 'PUT'));
|
2007-07-24 13:50:50 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'DELETE';
|
|
|
|
$result = $this->router->parse('/posts/13');
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($result, array('pass' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'delete', 'id' => '13', '[method]' => 'DELETE'));
|
2007-07-24 13:50:50 +00:00
|
|
|
}
|
|
|
|
|
2007-02-03 22:20:13 +00:00
|
|
|
function testUrlGeneration() {
|
2007-08-15 14:18:39 +00:00
|
|
|
$this->router->reload();
|
2007-02-26 02:11:30 +00:00
|
|
|
extract($this->router->getNamedExpressions());
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-08-15 14:18:39 +00:00
|
|
|
$this->router->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$out = $this->router->url(array('controller' => 'pages', 'action' => 'display', 'home'));
|
2007-02-04 09:06:44 +00:00
|
|
|
$this->assertEqual($out, '/');
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
$result = $this->router->url(array('controller' => 'pages', 'action' => 'display', 'about'));
|
2007-02-03 22:20:13 +00:00
|
|
|
$expected = '/pages/about';
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->parse('/');
|
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->connect('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID));
|
|
|
|
$result = $this->router->url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
2007-08-20 13:09:11 +00:00
|
|
|
$expected = '/cake_plugin/1';
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$result = $this->router->url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1', '0'));
|
|
|
|
$expected = '/cake_plugin/1/0';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->parse('/');
|
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->connect('/:controller/:action/:id', array(), array('id' => $ID));
|
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
2007-02-03 22:20:13 +00:00
|
|
|
$expected = '/posts/view/1';
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->parse('/');
|
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->router->connect('/:controller/:id', array('action' => 'view', 'id' => '1'));
|
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'view', 'id' => '1'));
|
2007-02-03 22:20:13 +00:00
|
|
|
$expected = '/posts/1';
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index', '0'));
|
2007-02-03 22:20:13 +00:00
|
|
|
$expected = '/posts/index/0';
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->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 = $this->router->url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-04-12 07:17:39 +00:00
|
|
|
|
2007-04-17 07:51:01 +00:00
|
|
|
$result = $this->router->url(array('controller' => 'posts', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->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);
|
2007-05-02 18:37:28 +00:00
|
|
|
|
|
|
|
$this->router->connect('/view/*', array('controller' => 'posts', 'action' => 'view'));
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->promote();
|
2007-05-02 18:37:28 +00:00
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'view', '1'));
|
|
|
|
$expected = '/view/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-07-30 13:15:59 +00:00
|
|
|
|
2007-08-16 16:31:50 +00:00
|
|
|
Configure::write('Routing.admin', 'admin');
|
2007-07-30 13:15:59 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->setRequestInfo(array(
|
2007-07-30 13:15:59 +00:00
|
|
|
array(
|
2007-08-28 21:16:24 +00:00
|
|
|
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscriptions',
|
2007-08-16 16:31:50 +00:00
|
|
|
'admin' => true, 'url' => array('url' => 'admin/subscriptions/index/page:2'), 'bare' => 0, 'webservices' => ''
|
2007-07-30 13:15:59 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/index/page:2',
|
2007-08-16 16:31:50 +00:00
|
|
|
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
2007-07-30 13:15:59 +00:00
|
|
|
'webservices' => null
|
|
|
|
)
|
|
|
|
));
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->router->parse('/');
|
2007-08-12 22:52:15 +00:00
|
|
|
|
2007-07-30 13:15:59 +00:00
|
|
|
$result = $this->router->url(array('page' => 3));
|
|
|
|
$expected = '/magazine/admin/subscriptions/index/page:3';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-12 22:52:15 +00:00
|
|
|
|
2007-08-28 21:16:24 +00:00
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
$this->router->reload();
|
2007-09-21 02:29:36 +00:00
|
|
|
$this->router->connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
|
2007-08-28 21:16:24 +00:00
|
|
|
'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1'), 'bare' => 0, 'webservices' => ''
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/edit/1',
|
|
|
|
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
|
|
|
'webservices' => null
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
2007-09-16 18:32:02 +00:00
|
|
|
$result = $this->router->url(array('action' => 'edit', 1));
|
2007-08-28 21:16:24 +00:00
|
|
|
$expected = '/magazine/admin/subscriptions/edit/1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-12 22:52:15 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->setRequestInfo(array(
|
2007-08-12 22:52:15 +00:00
|
|
|
array(
|
|
|
|
'pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'real_controller_name',
|
|
|
|
'url' => array('url' => ''), 'bare' => 0, 'webservices' => ''
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/', 'here' => '/',
|
2007-08-16 16:31:50 +00:00
|
|
|
'webroot' => '/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
2007-08-12 22:52:15 +00:00
|
|
|
'webservices' => null
|
|
|
|
)
|
|
|
|
));
|
2007-08-15 14:38:28 +00:00
|
|
|
$this->router->connect('short_controller_name/:action/*', array('controller' => 'real_controller_name'));
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->router->parse('/');
|
2007-08-12 22:52:15 +00:00
|
|
|
|
|
|
|
$result = $this->router->url(array('controller' => 'real_controller_name', 'page' => '1'));
|
|
|
|
$expected = '/short_controller_name/index/page:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-14 18:51:34 +00:00
|
|
|
|
2007-08-15 14:38:28 +00:00
|
|
|
$result = $this->router->url(array('action' => 'add'));
|
2007-08-20 13:09:11 +00:00
|
|
|
$expected = '/short_controller_name/add';
|
2007-08-15 14:38:28 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-14 18:51:34 +00:00
|
|
|
$this->router->reload();
|
|
|
|
|
|
|
|
$this->router->connect(
|
|
|
|
':language/galleries',
|
|
|
|
array('controller' => 'galleries', 'action' => 'index'),
|
|
|
|
array('language' => '[a-z]{3}')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->router->connect(
|
2007-08-15 14:18:39 +00:00
|
|
|
'/:language/:admin/:controller/:action/*',
|
|
|
|
array('admin' => 'admin'),
|
|
|
|
array('language' => '[a-z]{3}', 'admin' => 'admin')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->router->connect('/:language/:controller/:action/*',
|
|
|
|
array(),
|
|
|
|
array('language' => '[a-z]{3}')
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('admin' => false, 'language' => 'dan', 'action' => 'index', 'controller' => 'galleries'));
|
|
|
|
$expected = '/dan/galleries';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('admin' => false, 'language' => 'eng', 'action' => 'index', 'controller' => 'galleries'));
|
|
|
|
$expected = '/eng/galleries';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->connect('/:language/pages',
|
|
|
|
array(
|
|
|
|
'controller' => 'pages',
|
|
|
|
'action' => 'index'
|
|
|
|
),
|
|
|
|
array('language' => '[a-z]{3}')
|
2007-08-14 18:51:34 +00:00
|
|
|
);
|
|
|
|
|
2007-08-15 16:26:04 +00:00
|
|
|
$this->router->connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}'));
|
2007-08-14 18:51:34 +00:00
|
|
|
|
2007-08-15 14:18:39 +00:00
|
|
|
$result = $this->router->url(array('language' => 'eng', 'action' => 'index', 'controller' => 'pages'));
|
2007-08-15 16:26:04 +00:00
|
|
|
$expected = '/eng/pages';
|
2007-08-15 14:18:39 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('language' => 'eng', 'controller' => 'pages'));
|
2007-08-14 18:51:34 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-15 14:18:39 +00:00
|
|
|
$result = $this->router->url(array('language' => 'eng', 'controller' => 'pages', 'action' => 'add'));
|
2007-08-20 13:09:11 +00:00
|
|
|
$expected = '/eng/pages/add';
|
2007-08-14 18:51:34 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-15 16:26:04 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->parse('/');
|
|
|
|
$this->router->setRequestInfo(array(
|
2007-08-15 16:26:04 +00:00
|
|
|
array(
|
|
|
|
'pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'users',
|
|
|
|
'url' => array('url' => 'users'), 'bare' => 0, 'webservices' => ''
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/', 'here' => '/',
|
|
|
|
'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(),
|
|
|
|
'webservices' => null
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->router->url(array('action' => 'login'));
|
2007-08-20 13:09:11 +00:00
|
|
|
$expected = '/users/login';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
$this->router->connect('/page/*', array('plugin' => null, 'controller' => 'pages', 'action' => 'view'));
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'view', 'my-page'));
|
|
|
|
$expected = '/my_plugin/pages/view/my-page';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
$this->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 = $this->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);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$this->router->connect('/contact/:action', array('plugin' => 'contact', 'controller' => 'contact'));
|
|
|
|
$result = $this->router->url(array('plugin' => 'contact', 'controller' => 'contact', 'action' => 'me'));
|
|
|
|
|
|
|
|
$expected = '/contact/me';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->router->url(array('admin' => true, 'controller' => 'users', 'action' => 'login'));
|
|
|
|
$expected = '/admin/users/login';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-20 16:02:11 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$this->router->connect('/kalender/:month/:year/*',
|
|
|
|
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
|
|
|
|
array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->router->connect('/kalender/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'));
|
2007-08-28 21:16:24 +00:00
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling'));
|
2007-08-20 16:02:11 +00:00
|
|
|
$expected = '/kalender/min-forestilling';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-28 21:16:24 +00:00
|
|
|
$result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling'));
|
2007-08-20 16:02:11 +00:00
|
|
|
$expected = '/kalender/10/2007/min-forestilling';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-28 21:16:24 +00:00
|
|
|
|
2007-08-21 17:02:07 +00:00
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
$this->router->reload();
|
|
|
|
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'pass' => array(), 'admin' => true, 'action' => 'index', 'plugin' => null, 'controller' => 'users',
|
|
|
|
'url' => array('url' => 'users'), 'bare' => 0, 'webservices' => ''
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/', 'here' => '/',
|
|
|
|
'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(),
|
|
|
|
'webservices' => null
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->connect('/page/*', array('controller' => 'pages', 'action' => 'view', 'admin' => true, 'prefix' => 'admin'));
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->router->url(array('admin' => true, 'controller' => 'pages', 'action' => 'view', 'my-page'));
|
|
|
|
$expected = '/page/my-page';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-24 13:11:31 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
2007-08-28 21:16:24 +00:00
|
|
|
//Configure::write('Routing.admin', false);
|
2007-08-24 13:11:31 +00:00
|
|
|
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'pass' => array(), 'action' => 'index', 'plugin' => 'myplugin', 'controller' => 'mycontroller',
|
|
|
|
'admin' => false, 'url' => array('url' => array()), 'bare' => 0, 'webservices' => ''
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'base' => '/', 'here' => '/',
|
|
|
|
'webroot' => '/', 'passedArgs' => array(), 'namedArgs' => array(),
|
|
|
|
'webservices' => null
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'myothercontroller'));
|
|
|
|
$expected = '/myothercontroller/';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-09-16 18:32:02 +00:00
|
|
|
|
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
|
|
|
|
$this->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'), 'bare' => 0, 'webservices' => null),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
$this->router->parse('/');
|
2007-09-21 02:29:36 +00:00
|
|
|
|
2007-09-16 18:32:02 +00:00
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
|
|
|
|
$this->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'), 'bare' => 0, 'webservices' => null),
|
|
|
|
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+'));
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
|
|
|
|
$expected = '/admin/pages/edit/284';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-09-21 02:29:36 +00:00
|
|
|
|
2007-09-16 18:32:02 +00:00
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
$this->router->reload();
|
|
|
|
$this->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'), 'bare' => 0, 'webservices' => null),
|
|
|
|
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->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'), 'bare' => 0, 'webservices' => null),
|
|
|
|
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
|
|
|
|
$expected = '/admin/pages/edit/284';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-09-21 02:29:36 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array ('plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'admin_edit', 'pass' =>
|
|
|
|
array (0 => '6'), 'prefix' => 'admin', 'admin' => true, 'form' => array (), 'url' =>
|
|
|
|
array ('url' => 'admin/shows/show_tickets/edit/6'), 'bare' => 0, 'webservices' => NULL),
|
|
|
|
array ('plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/')));
|
|
|
|
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->router->url(array ( 'plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'edit', 'id' => '6', 'admin' => true, 'prefix' => 'admin', ));
|
|
|
|
$expected = '/admin/shows/show_tickets/edit/6';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-04-17 07:51:01 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 13:45:20 +00:00
|
|
|
function testUrlGenerationWithExtensions() {
|
2007-07-30 13:15:59 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->parse('/');
|
2007-07-17 13:45:20 +00:00
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'id' => null, 'ext' => 'json'));
|
|
|
|
$expected = '/articles/add.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-07-22 04:07:06 +00:00
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'ext' => 'json'));
|
|
|
|
$expected = '/articles/add.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'id' => null, 'ext' => 'json'));
|
|
|
|
$expected = '/articles.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'ext' => 'json'));
|
|
|
|
$expected = '/articles.json';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-07-17 13:45:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 01:40:34 +00:00
|
|
|
function testPluginUrlGeneration() {
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'controller' => 'controller', 'action' => 'index', 'form' => array(),
|
2007-08-20 13:09:11 +00:00
|
|
|
'url' => array(), 'bare' => 0, 'webservices' => null, 'plugin' => 'test'
|
2007-05-20 01:40:34 +00:00
|
|
|
),
|
2007-08-24 12:50:21 +00:00
|
|
|
array(
|
2007-05-20 01:40:34 +00:00
|
|
|
'base' => '/base', 'here' => '/clients/sage/portal/donations', 'webroot' => '/base/',
|
2007-08-24 12:50:21 +00:00
|
|
|
'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null
|
2007-05-20 01:40:34 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEqual($this->router->url('read/1'), '/base/test/controller/read/1');
|
|
|
|
$this->router->reload();
|
|
|
|
}
|
|
|
|
|
2007-04-17 07:51:01 +00:00
|
|
|
function testUrlParsing() {
|
|
|
|
extract($this->router->getNamedExpressions());
|
|
|
|
|
2007-04-12 07:17:39 +00:00
|
|
|
$this->router->connect('/posts/:value/:somevalue/:othervalue/*', array('controller' => 'posts', 'action' => 'view'), array('value','somevalue', 'othervalue'));
|
|
|
|
$result = $this->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'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
|
|
|
|
$result = $this->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'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/posts/:day/:year/:month/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
|
|
|
|
$result = $this->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'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/posts/:month/:day/:year//*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
|
|
|
|
$result = $this->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'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->routes = array();
|
|
|
|
$this->router->connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'));
|
|
|
|
$result = $this->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'));
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-07-27 13:32:26 +00:00
|
|
|
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->router->reload();
|
2007-07-27 13:32:26 +00:00
|
|
|
$result = $this->router->parse('/pages/display/home');
|
2007-08-15 14:18:39 +00:00
|
|
|
$expected = array('plugin' => null, 'pass' => array('home'), 'controller' => 'pages', 'action' => 'display');
|
2007-07-27 13:32:26 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2007-07-27 17:51:33 +00:00
|
|
|
|
2007-07-27 13:32:26 +00:00
|
|
|
$result = $this->router->parse('pages/display/home/');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->parse('pages/display/home');
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-15 14:28:53 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->connect('/page/*', array('controller' => 'test'));
|
|
|
|
$result = $this->router->parse('/page/my-page');
|
|
|
|
$expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index');
|
2007-08-16 18:50:25 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
2007-08-28 21:16:24 +00:00
|
|
|
$this->router->connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}'));
|
2007-08-16 18:50:25 +00:00
|
|
|
$result = $this->router->parse('/eng/contact');
|
|
|
|
$expected = array('pass' => array(), 'language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index');
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-28 21:16:24 +00:00
|
|
|
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$this->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 = $this->router->parse('/forestillinger/10/2007/min-forestilling');
|
|
|
|
$expected = array('pass' => array('min-forestilling'), 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10);
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-08-28 21:16:24 +00:00
|
|
|
|
2007-02-26 02:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAdminRouting() {
|
2007-08-16 05:44:06 +00:00
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
2007-08-16 16:31:50 +00:00
|
|
|
$result = $this->router->url(array('admin' => true, 'controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
2007-08-16 05:44:06 +00:00
|
|
|
$expected = '/admin/posts/index/0?var=test&var2=test2';
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-24 12:50:21 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parse('/');
|
|
|
|
$result = $this->router->url(array('admin' => false, 'controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'webservices' => null, 'plugin' => null),
|
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->parse('/');
|
|
|
|
$result = $this->router->url(array('admin' => false, 'controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
|
|
|
$expected = '/admin/posts/index/0?var=test&var2=test2';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-16 16:31:50 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$result = $this->router->parse('admin/users/view/');
|
|
|
|
$expected = array('pass' => array(), 'controller' => 'users', 'action' => 'view', 'plugin' => null, 'prefix' => 'admin', 'admin' => true);
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testExtensionParsingSetting() {
|
2007-02-26 02:11:30 +00:00
|
|
|
$router = Router::getInstance();
|
|
|
|
$this->router->reload();
|
|
|
|
$this->assertFalse($this->router->__parseExtensions);
|
|
|
|
|
|
|
|
$router->parseExtensions();
|
|
|
|
$this->assertTrue($this->router->__parseExtensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testExtensionParsing() {
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parseExtensions();
|
|
|
|
|
|
|
|
$result = $this->router->parse('/posts.rss');
|
2007-08-14 18:51:34 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'rss'), 'pass'=> array());
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->parse('/posts/view/1.rss');
|
2007-08-15 14:18:39 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'pass' => array('1'), 'url' => array('ext' => 'rss'));
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->parse('/posts/view/1.rss?query=test');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->parse('/posts/view/1.atom');
|
|
|
|
$expected['url'] = array('ext' => 'atom');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parseExtensions('rss', 'xml');
|
|
|
|
|
|
|
|
$result = $this->router->parse('/posts.xml');
|
2007-08-24 12:50:21 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'xml'), 'pass'=> array());
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->parse('/posts.atom?hello=goodbye');
|
2007-08-14 18:51:34 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts.atom', 'action' => 'index', 'pass' => array());
|
2007-02-26 02:11:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->parseExtensions();
|
|
|
|
$result = $this->router->__parseExtension('/posts.atom');
|
|
|
|
$expected = array('ext' => 'atom', 'url' => '/posts');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testQuerystringGeneration() {
|
|
|
|
$result = $this->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 = $this->router->url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected .= '&more=test+data';
|
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data')));
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
2007-04-29 11:10:11 +00:00
|
|
|
|
|
|
|
function testNamedArgsUrlGeneration() {
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->setRequestInfo(array(null, array('base' => '/', 'argSeparator' => ':')));
|
|
|
|
$this->router->connectNamed(array(
|
|
|
|
'published' => array('regex' => '[01]'),
|
|
|
|
'deleted' => array('regex' => '[01]')
|
|
|
|
));
|
|
|
|
$this->router->parse('/');
|
2007-04-29 11:10:11 +00:00
|
|
|
|
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1));
|
|
|
|
$expected = '/posts/index/published:1/deleted:1';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index', 'published' => 0, 'deleted' => 0));
|
|
|
|
$expected = '/posts/index/published:0/deleted:0';
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-09-16 18:32:02 +00:00
|
|
|
|
2007-10-04 23:29:57 +00:00
|
|
|
$this->router->reload();
|
|
|
|
extract($this->router->getNamedExpressions());
|
|
|
|
$this->router->setRequestInfo(array(null, array('base' => '/', 'argSeparator' => ':')));
|
|
|
|
$this->router->connectNamed(array('file'=> '[\w\.\-]+\.(html|png)'));
|
|
|
|
$this->router->connect('/', array('controller' => 'graphs', 'action' => 'index'));
|
|
|
|
$this->router->connect('/:id/*', array('controller' => 'graphs', 'action' => 'view'), array('id' => $ID));
|
|
|
|
|
|
|
|
$result = $this->router->url(array('controller' => 'graphs', 'action' => 'view', 'id' => 12, 'file' => 'asdf.png'));
|
|
|
|
$expected = '/12/file:asdf.png';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-09-26 09:49:01 +00:00
|
|
|
Configure::write('Routing.admin', 'admin');
|
|
|
|
|
2007-09-16 18:32:02 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'webservices' => null, 'plugin' => null),
|
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null)
|
|
|
|
));
|
|
|
|
$this->router->parse('/');
|
|
|
|
|
|
|
|
$result = $this->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);
|
2007-09-26 09:49:01 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'webservices' => null, 'plugin' => null),
|
|
|
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array('type'=> 'whatever'), 'argSeparator' => ':', 'namedArgs' => array('type'=> 'whatever'), 'webservices' => null)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->connectNamed(array('type'));
|
|
|
|
|
|
|
|
$this->router->parse('/admin/controller/index/type:whatever');
|
|
|
|
|
|
|
|
$result = $this->router->url(array('type'=> 'new'));
|
|
|
|
$expected = "/admin/controller/index/type:new";
|
|
|
|
$this->assertEqual($result, $expected);
|
2007-04-29 11:10:11 +00:00
|
|
|
}
|
2007-07-24 14:40:34 +00:00
|
|
|
|
2007-07-24 13:50:50 +00:00
|
|
|
function testParamsUrlParsing() {
|
2007-09-16 18:32:02 +00:00
|
|
|
$this->router->reload();
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->connect('/', array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->router->connect('/view/:user/*', array('controller' => 'posts', 'action' => 'view'), array('user'));
|
2007-07-24 13:50:50 +00:00
|
|
|
$result = $this->router->parse('/view/gwoo/');
|
|
|
|
$expected = array('user' => 'gwoo', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2007-07-27 02:46:30 +00:00
|
|
|
|
|
|
|
function testPagesUrlParsing() {
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$this->router->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$this->router->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
2007-07-27 17:51:33 +00:00
|
|
|
|
|
|
|
$result = $this->router->parse('/');
|
2007-08-16 05:44:06 +00:00
|
|
|
$expected = array('pass'=>array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2007-07-27 17:51:33 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-07-27 02:46:30 +00:00
|
|
|
$result = $this->router->parse('/pages/home/');
|
2007-08-16 05:44:06 +00:00
|
|
|
$expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2007-07-27 02:46:30 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2007-08-20 13:09:11 +00:00
|
|
|
$this->router->reload();
|
|
|
|
$this->router->connect('/', array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->router->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
2007-07-27 02:46:30 +00:00
|
|
|
$result = $this->router->parse('/pages/contact/');
|
|
|
|
|
|
|
|
$expected = array('pass'=>array('contact'), 'plugin'=> null, 'controller'=>'pages', 'action'=>'display');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2007-08-16 05:44:06 +00:00
|
|
|
|
|
|
|
function testParsingWithPrefixes() {
|
|
|
|
$this->router->reload();
|
|
|
|
$adminParams = array('prefix' => 'admin', 'admin' => true);
|
|
|
|
$this->router->connect('/admin/:controller', $adminParams);
|
|
|
|
$this->router->connect('/admin/:controller/:action', $adminParams);
|
|
|
|
$this->router->connect('/admin/:controller/:action/*', $adminParams);
|
|
|
|
|
|
|
|
$this->router->setRequestInfo(array(
|
2007-08-24 12:50:21 +00:00
|
|
|
array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'webservices' => null, 'plugin' => null),
|
|
|
|
array('base' => '/base', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null)
|
2007-08-16 05:44:06 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->router->parse('/admin/posts/');
|
|
|
|
$expected = array('pass' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'admin' => true);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->parse('/admin/posts');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->url(array('admin' => true, 'controller' => 'posts'));
|
|
|
|
$expected = '/base/admin/posts';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->router->prefixes();
|
|
|
|
$expected = array('admin');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2007-08-28 21:16:24 +00:00
|
|
|
|
2007-09-16 18:32:02 +00:00
|
|
|
function testPassedArgsOrder() {
|
2007-08-28 21:16:24 +00:00
|
|
|
$this->router->reload();
|
|
|
|
|
2007-09-16 18:32:02 +00:00
|
|
|
$this->router->connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
|
|
|
|
$this->router->connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1));
|
2007-08-28 21:16:24 +00:00
|
|
|
$this->router->parse('/');
|
2007-09-26 09:49:01 +00:00
|
|
|
|
|
|
|
$this->router->reload();
|
|
|
|
|
|
|
|
$this->router->setRequestInfo(array(
|
|
|
|
array ( 'plugin' => NULL, 'controller' => 'images', 'action' => 'index', 'pass' => array ( ), 'prefix' => 'protected', 'admin' => false, 'form' => array ( ), 'url' => array ( 'url' => 'protected/images/index', ), 'bare' => 0, 'webservices' => NULL, ),
|
|
|
|
array ( 'plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'here' => '/protected/images/index', 'webroot' => '/', )
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->router->connect('/protected/:controller/:action/*', array(
|
|
|
|
'controller' => 'users',
|
|
|
|
'action' => 'index',
|
|
|
|
'prefix' => 'protected'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->router->parse('/');
|
|
|
|
$result = $this->router->url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/protected/images/add';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
//debug($this->router->prefixes());
|
2007-08-28 21:16:24 +00:00
|
|
|
}
|
2007-09-26 09:49:01 +00:00
|
|
|
|
2007-02-03 22:20:13 +00:00
|
|
|
}
|
2007-02-26 02:11:30 +00:00
|
|
|
|
2007-02-04 09:06:44 +00:00
|
|
|
?>
|