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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, 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.
|
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:13:11 +00:00
|
|
|
|
|
|
|
App::uses('Router', 'Routing');
|
|
|
|
App::uses('CakeResponse', 'Network');
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2009-09-27 05:22:46 +00:00
|
|
|
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
|
|
|
|
}
|
|
|
|
|
2011-05-09 04:31:00 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
CakePlugin::unload();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFullBaseURL() {
|
2010-09-20 01:40:35 +00:00
|
|
|
$skip = PHP_SAPI == 'cli';
|
|
|
|
if ($skip) {
|
|
|
|
$this->markTestSkipped('Cannot validate base urls in CLI');
|
|
|
|
}
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/^http(s)?:\/\//', Router::url('/', true));
|
|
|
|
$this->assertRegExp('/^http(s)?:\/\//', Router::url(null, true));
|
|
|
|
$this->assertRegExp('/^http(s)?:\/\//', Router::url(array('full_base' => true)));
|
|
|
|
$this->assertSame(FULL_BASE_URL . '/', Router::url(array('full_base' => true)));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRouteDefaultParams() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/:controller', array('controller' => 'posts'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(Router::url(array('action' => 'index')), '/');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2011-09-01 17:44:15 +00:00
|
|
|
* testMapResources method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-09-01 17:44:15 +00:00
|
|
|
public function testMapResources() {
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => 'GET'), $result);
|
|
|
|
$this->assertEquals(array('posts'), $resources);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts/13');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => '13', '[method]' => 'GET'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$result = Router::parse('/posts');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$result = Router::parse('/posts/13');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '13', '[method]' => 'PUT'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts/475acc39-a328-44d3-95fb-015000000000');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array('475acc39-a328-44d3-95fb-015000000000'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '475acc39-a328-44d3-95fb-015000000000', '[method]' => 'PUT'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'DELETE';
|
|
|
|
$result = Router::parse('/posts/13');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'delete', 'id' => '13', '[method]' => 'DELETE'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts/add');
|
2012-10-26 22:18:05 +00:00
|
|
|
$this->assertSame(array(), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-04-20 03:44:45 +00:00
|
|
|
$resources = Router::mapResources('Posts', array('id' => '[a-z0-9_]+'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('posts'), $resources);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts/add');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array('add'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => 'add', '[method]' => 'GET'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$result = Router::parse('/posts/name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array('name'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => 'name', '[method]' => 'PUT'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-09-01 17:44:15 +00:00
|
|
|
/**
|
|
|
|
* testMapResources with plugin controllers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPluginMapResources() {
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(
|
2011-09-01 17:44:15 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$resources = Router::mapResources('TestPlugin.TestPlugin');
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/test_plugin/test_plugin');
|
|
|
|
$expected = array(
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'plugin' => 'test_plugin',
|
|
|
|
'controller' => 'test_plugin',
|
2011-10-28 05:01:17 +00:00
|
|
|
'action' => 'index',
|
2011-09-01 17:44:15 +00:00
|
|
|
'[method]' => 'GET'
|
|
|
|
);
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('test_plugin'), $resources);
|
2011-09-01 17:44:15 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/test_plugin/test_plugin/13');
|
|
|
|
$expected = array(
|
|
|
|
'pass' => array('13'),
|
|
|
|
'named' => array(),
|
|
|
|
'plugin' => 'test_plugin',
|
|
|
|
'controller' => 'test_plugin',
|
|
|
|
'action' => 'view',
|
|
|
|
'id' => '13',
|
|
|
|
'[method]' => 'GET'
|
|
|
|
);
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-09-01 17:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test mapResources with a plugin and prefix.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPluginMapResourcesWithPrefix() {
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(
|
2011-09-01 17:44:15 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$resources = Router::mapResources('TestPlugin.TestPlugin', array('prefix' => '/api/'));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/api/test_plugin');
|
|
|
|
$expected = array(
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'plugin' => 'test_plugin',
|
|
|
|
'controller' => 'test_plugin',
|
2011-10-28 05:01:17 +00:00
|
|
|
'action' => 'index',
|
2011-09-01 17:44:15 +00:00
|
|
|
'[method]' => 'GET'
|
|
|
|
);
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('test_plugin'), $resources);
|
2011-09-01 17:44:15 +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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleResourceRoute() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/:controller', array('action' => 'index', '[method]' => array('GET', 'POST')));
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$result = Router::parse('/posts');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST')), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$result = Router::parse('/posts');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST')), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-01-15 01:17:09 +00:00
|
|
|
/**
|
|
|
|
* testGenerateUrlResourceRoute method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGenerateUrlResourceRoute() {
|
2009-01-15 01:17:09 +00:00
|
|
|
Router::mapResources('Posts');
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '[method]' => 'GET'));
|
|
|
|
$expected = '/posts';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'add', '[method]' => 'POST'));
|
|
|
|
$expected = '/posts';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'delete', '[method]' => 'DELETE', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', '[method]' => 'POST', 'id' => 10));
|
|
|
|
$expected = '/posts/10';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-01-15 01:17:09 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlNormalization() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/users/logout';
|
|
|
|
|
|
|
|
$result = Router::normalize('/users/logout/');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('//users//logout//');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('users/logout');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::normalize(array('controller' => 'users', 'action' => 'logout'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('/');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $result);
|
2008-07-25 11:45:00 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('http://google.com/');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('http://google.com/', $result);
|
2008-07-25 11:45:00 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('http://google.com//');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('http://google.com//', $result);
|
2008-07-25 11:45:00 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('/users/login/scope://foo');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/users/login/scope:/foo', $result);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('/recipe/recipes/add');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/recipe/recipes/add', $result);
|
2009-01-14 17:55:48 +00:00
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->base = '/us';
|
|
|
|
Router::setRequestInfo($request);
|
2009-01-14 17:55:48 +00:00
|
|
|
$result = Router::normalize('/us/users/logout/');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/users/logout', $result);
|
2009-01-14 17:55:48 +00:00
|
|
|
|
2009-01-14 18:27:14 +00:00
|
|
|
Router::reload();
|
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->base = '/cake_12';
|
|
|
|
Router::setRequestInfo($request);
|
2009-01-14 18:27:14 +00:00
|
|
|
$result = Router::normalize('/cake_12/users/logout/');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/users/logout', $result);
|
2009-01-14 18:27:14 +00:00
|
|
|
|
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
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->base = '/';
|
|
|
|
Router::setRequestInfo($request);
|
2009-07-20 13:18:38 +00:00
|
|
|
$result = Router::normalize('users/login');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/users/login', $result);
|
2009-07-20 13:18:38 +00:00
|
|
|
Configure::write('App.baseUrl', $_back);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-20 13:18:38 +00:00
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->base = 'beer';
|
|
|
|
Router::setRequestInfo($request);
|
2009-07-20 13:18:38 +00:00
|
|
|
$result = Router::normalize('beer/admin/beers_tags/add');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/beers_tags/add', $result);
|
2009-07-20 13:18:38 +00:00
|
|
|
|
|
|
|
$result = Router::normalize('/admin/beers_tags/add');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/beers_tags/add', $result);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlGenerationBasic() {
|
2008-05-30 11:40:08 +00:00
|
|
|
extract(Router::getNamedExpressions());
|
2008-06-14 21:26:01 +00:00
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'action' => 'index', 'plugin' => null, 'controller' => 'subscribe', 'admin' => true
|
2008-06-14 21:12:56 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/magazine';
|
|
|
|
$request->here = '/magazine';
|
|
|
|
$request->webroot = '/magazine/';
|
|
|
|
Router::setRequestInfo($request);
|
|
|
|
|
2008-06-14 21:12:56 +00:00
|
|
|
$result = Router::url();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('/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'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', $out);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 'about'));
|
|
|
|
$expected = '/pages/about';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1', '0'));
|
|
|
|
$expected = '/cake_plugin/1/0';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0'));
|
|
|
|
$expected = '/posts/index/0';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'action' => 'index', 'plugin' => null, 'controller' => 'real_controller_name'
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/';
|
|
|
|
$request->here = '/';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'add'));
|
|
|
|
$expected = '/short_controller_name/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2009-10-02 18:28:01 +00:00
|
|
|
Router::parse('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/';
|
|
|
|
$request->here = '/';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'login'));
|
|
|
|
$expected = '/users/login';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'action' => 'index', 'plugin' => 'myplugin', 'controller' => 'mycontroller', 'admin' => false
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/';
|
|
|
|
$request->here = '/';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-10 00:56:40 +00:00
|
|
|
/**
|
|
|
|
* Test that catch all routes work with a variety of falsey inputs.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testUrlCatchAllRoute() {
|
|
|
|
Router::connect('/*', array('controller' => 'categories', 'action' => 'index'));
|
|
|
|
$result = Router::url(array('controller' => 'categories', 'action' => 'index', '0'));
|
|
|
|
$this->assertEquals('/0', $result);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'controller' => 'categories',
|
|
|
|
'action' => 'index',
|
|
|
|
'pass' => array('0'),
|
|
|
|
'named' => array()
|
|
|
|
);
|
|
|
|
$result = Router::parse('/0');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Router::parse('0');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2010-12-15 02:21:39 +00:00
|
|
|
/**
|
|
|
|
* Tests using arrays in named parameters
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testArrayNamedParameters() {
|
2010-12-15 02:21:39 +00:00
|
|
|
$result = Router::url(array('controller' => 'tests', 'pages' => array(
|
|
|
|
1, 2, 3
|
|
|
|
)));
|
|
|
|
$expected = '/tests/index/pages[0]:1/pages[1]:2/pages[2]:3';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'tests',
|
|
|
|
'pages' => array(
|
|
|
|
'param1' => array(
|
|
|
|
'one',
|
|
|
|
'two'
|
|
|
|
),
|
|
|
|
'three'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = '/tests/index/pages[param1][0]:one/pages[param1][1]:two/pages[0]:three';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'tests',
|
|
|
|
'pages' => array(
|
|
|
|
'param1' => array(
|
|
|
|
'one' => 1,
|
|
|
|
'two' => 2
|
|
|
|
),
|
|
|
|
'three'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = '/tests/index/pages[param1][one]:1/pages[param1][two]:2/pages[0]:three';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'tests',
|
|
|
|
'super' => array(
|
|
|
|
'nested' => array(
|
|
|
|
'array' => 'awesome',
|
|
|
|
'something' => 'else'
|
|
|
|
),
|
|
|
|
'cool'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = '/tests/index/super[nested][array]:awesome/super[nested][something]:else/super[0]:cool';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-15 02:21:39 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'tests', 'namedParam' => array(
|
|
|
|
'keyed' => 'is an array',
|
|
|
|
'test'
|
|
|
|
)));
|
2012-02-14 02:16:57 +00:00
|
|
|
$expected = '/tests/index/namedParam[keyed]:is%20an%20array/namedParam[0]:test';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-15 02:21:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-02 18:28:01 +00:00
|
|
|
/**
|
|
|
|
* Test generation of routes with query string parameters.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlGenerationWithQueryStrings() {
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
2009-10-02 18:28:01 +00:00
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', '0', '?' => array('var' => null)));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/posts/index/0', $result);
|
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 %'));
|
2012-04-07 01:32:37 +00:00
|
|
|
$expected = '/posts/index/0?var=test&var2=test2#unencoded string %';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that regex validation of keyed route params is working.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('admin' => false, 'language' => 'eng', 'action' => 'index', 'controller' => 'galleries'));
|
|
|
|
$expected = '/eng/galleries';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('language' => 'eng', 'controller' => 'pages'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('language' => 'eng', 'controller' => 'pages', 'action' => 'add'));
|
|
|
|
$expected = '/eng/pages/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling'));
|
|
|
|
$expected = '/kalender/10/2007/min-forestilling';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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'
|
|
|
|
));
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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');
|
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'controller' => 'registrations', 'action' => 'admin_index',
|
|
|
|
'plugin' => null, 'prefix' => 'admin', 'admin' => true,
|
2011-08-23 01:19:35 +00:00
|
|
|
'ext' => 'html'
|
2009-10-02 18:28:01 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '';
|
|
|
|
$request->here = '/admin/registrations/index';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('page' => 2));
|
|
|
|
$expected = '/admin/registrations/index/page:2';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'controller' => 'subscriptions', 'action' => 'admin_index',
|
|
|
|
'plugin' => null, 'admin' => true,
|
2010-05-02 05:43:37 +00:00
|
|
|
'url' => array('url' => 'admin/subscriptions/index/page:2')
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/magazine';
|
|
|
|
$request->here = '/magazine/admin/subscriptions/index/page:2';
|
|
|
|
$request->webroot = '/magazine/';
|
|
|
|
Router::setRequestInfo($request);
|
|
|
|
|
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';
|
2010-12-18 19:16:00 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
|
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
|
|
|
|
'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1')
|
2009-10-02 18:28:01 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/magazine';
|
|
|
|
$request->here = '/magazine/admin/subscriptions/edit/1';
|
|
|
|
$request->webroot = '/magazine/';
|
|
|
|
Router::setRequestInfo($request);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1));
|
|
|
|
$expected = '/magazine/admin/subscriptions/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'admin' => true, 'action' => 'index', 'plugin' => null, 'controller' => 'users',
|
2010-05-02 05:43:37 +00:00
|
|
|
'url' => array('url' => 'users')
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/';
|
|
|
|
$request->here = '/';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'prefix' => 'admin', 'admin' => true,
|
|
|
|
'url' => array('url' => 'admin/pages/add')
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '';
|
|
|
|
$request->here = '/admin/pages/add';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parse('/');
|
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'prefix' => 'admin', 'admin' => true,
|
|
|
|
'url' => array('url' => 'admin/pages/add')
|
2009-10-02 18:28:01 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '';
|
|
|
|
$request->here = '/admin/pages/add';
|
|
|
|
$request->webroot = '/';
|
|
|
|
Router::setRequestInfo($request);
|
2009-10-02 18:28:01 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'),
|
2010-05-02 05:43:37 +00:00
|
|
|
'prefix' => 'admin', 'admin' => true,
|
|
|
|
'url' => array('url' => 'admin/pages/edit/284')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/'
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
|
|
|
|
$expected = '/admin/pages/edit/284';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
|
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'prefix' => 'admin',
|
2010-05-02 05:43:37 +00:00
|
|
|
'admin' => true, 'url' => array('url' => 'admin/pages/add')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/'
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
|
|
|
$expected = '/admin/pages/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::parse('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
|
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'prefix' => 'admin',
|
2010-05-02 05:43:37 +00:00
|
|
|
'admin' => true, 'pass' => array('284'), 'url' => array('url' => 'admin/pages/edit/284')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/'
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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('/');
|
2010-05-02 05:43:37 +00:00
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugin' => null, 'controller' => 'posts', 'action' => 'admin_index', 'prefix' => 'admin',
|
2010-05-02 05:43:37 +00:00
|
|
|
'admin' => true, 'pass' => array('284'), 'url' => array('url' => 'admin/posts')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '', 'here' => '/admin/posts', 'webroot' => '/'
|
|
|
|
))
|
|
|
|
);
|
2009-08-20 03:33:52 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('all'));
|
|
|
|
$expected = '/admin/posts/all';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlGenerationWithExtensions() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parse('/');
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'id' => null, 'ext' => 'json'));
|
|
|
|
$expected = '/articles/add.json';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'ext' => 'json'));
|
|
|
|
$expected = '/articles/add.json';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'id' => null, 'ext' => 'json'));
|
|
|
|
$expected = '/articles.json';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'ext' => 'json'));
|
|
|
|
$expected = '/articles.json';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlGenerationPlugins() {
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => 'test', 'controller' => 'controller', 'action' => 'index'
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/base', 'here' => '/clients/sage/portal/donations', 'webroot' => '/base/'
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(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
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2009-12-09 02:36:25 +00:00
|
|
|
'lang' => 'en',
|
2010-05-02 05:43:37 +00:00
|
|
|
'plugin' => 'shows', 'controller' => 'shows', 'action' => 'index',
|
|
|
|
'url' => array('url' => 'en/shows/'),
|
|
|
|
))->addPaths(array(
|
|
|
|
'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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCanLeavePlugin() {
|
2009-12-09 02:36:25 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect(
|
|
|
|
'/admin/other/:controller/:action/*',
|
|
|
|
array(
|
|
|
|
'admin' => 1,
|
|
|
|
'plugin' => 'aliased',
|
|
|
|
'prefix' => 'admin'
|
|
|
|
)
|
|
|
|
);
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2009-12-09 02:36:25 +00:00
|
|
|
'pass' => array(),
|
|
|
|
'admin' => true,
|
|
|
|
'prefix' => 'admin',
|
|
|
|
'plugin' => 'this',
|
|
|
|
'action' => 'admin_index',
|
|
|
|
'controller' => 'interesting',
|
|
|
|
'url' => array('url' => 'admin/this/interesting/index'),
|
2010-05-02 05:43:37 +00:00
|
|
|
))->addPaths(array(
|
2009-12-09 02:36:25 +00:00
|
|
|
'base' => '',
|
|
|
|
'here' => '/admin/this/interesting/index',
|
|
|
|
'webroot' => '/',
|
2010-05-02 05:43:37 +00:00
|
|
|
))
|
|
|
|
);
|
2009-12-09 02:36:25 +00:00
|
|
|
$result = Router::url(array('plugin' => null, 'controller' => 'posts', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/posts', $result);
|
2009-12-09 02:36:25 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/this/posts', $result);
|
2009-12-09 02:36:25 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'aliased', 'controller' => 'posts', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/other/posts/index', $result);
|
2009-12-09 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlParsing() {
|
2008-05-30 11:40:08 +00:00
|
|
|
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');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('value' => '2007', 'somevalue' => '08', 'othervalue' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' => '', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' => '', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('day' => '01', 'year' => '2007', 'month' => '08', 'controller' => 'posts', 'action' => 'view', 'plugin' => '', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('month' => '08', 'day' => '01', 'year' => '2007', 'controller' => 'posts', 'action' => 'view', 'plugin' => '', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' => '', 'pass' => array('0' => 'title-of-post-here'), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::parse('/pages/display/home');
|
|
|
|
$expected = array('plugin' => null, 'pass' => array('home'), 'controller' => 'pages', 'action' => 'display', 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('pages/display/home/');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('pages/display/home');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/page/*', array('controller' => 'test'));
|
|
|
|
$result = Router::parse('/page/my-page');
|
2012-02-16 18:28:21 +00:00
|
|
|
$expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index', 'named' => array());
|
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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/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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-03-03 12:32:06 +00:00
|
|
|
Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => array('foo', 'answer'), 'greedyNamed' => true));
|
2008-05-30 11:40:08 +00:00
|
|
|
$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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'lang' => 'en',
|
|
|
|
'color' => 'red',
|
|
|
|
'prefix' => 'admin',
|
|
|
|
'plugin' => null,
|
|
|
|
'action' => 'view',
|
|
|
|
'controller' => 'posts',
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/',
|
|
|
|
'here' => '/en/red/posts/view/5',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/en/red/posts/view/6';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 6));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = '/en/blue/posts/index';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'color' => 'blue'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-11-26 04:11:50 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/posts';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = '/posts/edit/7';
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'edit', 7));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = '/about';
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'view', 'about'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUuidRoutes() {
|
2008-05-30 11:40:08 +00:00
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRouteSymmetry() {
|
2008-05-30 11:40:08 +00:00
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRoutingPrefixesSetting() {
|
2009-09-27 02:48:57 +00:00
|
|
|
$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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 02:48:57 +00:00
|
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 02:48:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPrefixRoutingAndPlugins() {
|
2009-09-27 05:22:46 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2009-09-20 22:38:26 +00:00
|
|
|
$paths = App::path('plugins');
|
|
|
|
App::build(array(
|
2012-03-13 01:36:27 +00:00
|
|
|
'plugins' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
2009-09-20 22:38:26 +00:00
|
|
|
)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2009-07-17 21:35:23 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'admin' => true, 'controller' => 'controller', 'action' => 'action',
|
|
|
|
'plugin' => null, 'prefix' => 'admin'
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/',
|
|
|
|
'here' => '/',
|
|
|
|
'webroot' => '/base/',
|
|
|
|
))
|
|
|
|
);
|
2009-07-17 21:35:23 +00:00
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-12-09 02:36:25 +00:00
|
|
|
|
2009-12-01 19:39:23 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2009-12-01 19:39:23 +00:00
|
|
|
'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')
|
2010-05-02 05:43:37 +00:00
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/',
|
|
|
|
'here' => '/admin/shows/show_tickets/edit/6',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2009-12-01 19:39:23 +00:00
|
|
|
|
|
|
|
$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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-04-11 01:15:56 +00:00
|
|
|
|
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
|
|
|
/**
|
2012-05-30 19:27:54 +00:00
|
|
|
* testParseExtensions method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-05-30 19:27:54 +00:00
|
|
|
public function testParseExtensions() {
|
2010-05-21 02:55:25 +00:00
|
|
|
$this->assertEquals(array(), Router::extensions());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-20 03:54:09 +00:00
|
|
|
Router::parseExtensions('rss');
|
2012-05-30 19:27:54 +00:00
|
|
|
$this->assertEquals(array('rss'), Router::extensions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSetExtensions method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetExtensions() {
|
|
|
|
Router::setExtensions(array('rss'));
|
|
|
|
$this->assertEquals(array('rss'), Router::extensions());
|
|
|
|
|
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
|
|
|
$result = Router::parse('/posts.rss');
|
|
|
|
$this->assertFalse(isset($result['ext']));
|
|
|
|
|
|
|
|
Router::parseExtensions();
|
|
|
|
$result = Router::parse('/posts.rss');
|
|
|
|
$this->assertEquals('rss', $result['ext']);
|
|
|
|
|
|
|
|
$result = Router::parse('/posts.xml');
|
|
|
|
$this->assertFalse(isset($result['ext']));
|
|
|
|
|
|
|
|
Router::setExtensions(array('xml'));
|
|
|
|
$result = Router::extensions();
|
|
|
|
$this->assertEquals(array('rss', 'xml'), $result);
|
|
|
|
|
|
|
|
$result = Router::parse('/posts.xml');
|
|
|
|
$this->assertEquals('xml', $result['ext']);
|
|
|
|
|
|
|
|
$result = Router::setExtensions(array('pdf'), false);
|
|
|
|
$this->assertEquals(array('pdf'), $result);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExtensionParsing() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parseExtensions();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts.rss');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'ext' => 'rss', 'pass' => array(), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/1.rss');
|
2011-08-23 01:19:35 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'pass' => array('1'), 'named' => array(), 'ext' => 'rss', 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/1.rss?query=test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/1.atom');
|
2011-08-23 01:19:35 +00:00
|
|
|
$expected['ext'] = 'atom';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::parseExtensions('rss', 'xml');
|
|
|
|
|
|
|
|
$result = Router::parse('/posts.xml');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'ext' => 'xml', 'pass' => array(), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts.atom?hello=goodbye');
|
2011-05-05 03:08:10 +00:00
|
|
|
$expected = array('plugin' => null, 'controller' => 'posts.atom', 'action' => 'index', 'pass' => array(), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-06-29 20:24:06 +00:00
|
|
|
Router::reload();
|
2011-08-23 01:19:35 +00:00
|
|
|
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'ext' => 'rss'));
|
2008-06-29 20:24:06 +00:00
|
|
|
$result = Router::parse('/controller/action');
|
2011-08-23 01:19:35 +00:00
|
|
|
$expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'ext' => 'rss', 'named' => array(), 'pass' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-03-20 20:57:01 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::parseExtensions('rss');
|
2011-08-23 01:19:35 +00:00
|
|
|
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'ext' => 'rss'));
|
2010-03-20 20:57:01 +00:00
|
|
|
$result = Router::parse('/controller/action');
|
2011-08-23 01:19:35 +00:00
|
|
|
$expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'ext' => 'rss', 'named' => array(), 'pass' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testQuerystringGeneration() {
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected .= '&more=test+data';
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-13 01:36:27 +00:00
|
|
|
// Test bug #4614
|
2008-05-30 11:40:08 +00:00
|
|
|
$restore = ini_get('arg_separator.output');
|
|
|
|
ini_set('arg_separator.output', '&');
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
ini_set('arg_separator.output', $restore);
|
2009-01-15 01:17:09 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')), array('escape' => true));
|
2009-01-14 21:38:11 +00:00
|
|
|
$expected = '/posts/index/0?var=test&var2=test2';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConnectNamed() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$named = Router::connectNamed(false, array('default' => true));
|
2011-03-03 12:32:06 +00:00
|
|
|
$this->assertFalse($named['greedyNamed']);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_keys($named['rules']), $named['default']);
|
2008-06-17 15:46:49 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar'));
|
2010-12-20 02:49:17 +00:00
|
|
|
Router::connectNamed(array(), array('separator' => '='));
|
2008-06-17 15:46:49 +00:00
|
|
|
$result = Router::parse('/foo/param1=value1/param2=value2');
|
|
|
|
$expected = array('pass' => array(), 'named' => array('param1' => 'value1', 'param2' => 'value2'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-17 15:46:49 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/controller/action/*', array('controller' => 'controller', 'action' => 'action'), array('named' => array('param1' => 'value[\d]')));
|
2010-12-20 02:49:17 +00:00
|
|
|
Router::connectNamed(array(), array('greedy' => false, 'separator' => '='));
|
2008-06-17 15:46:49 +00:00
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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));
|
2010-12-18 22:01:26 +00:00
|
|
|
$result = Router::parse('/categories/index/limit=5');
|
2008-10-04 18:01:48 +00:00
|
|
|
$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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNamedArgsUrlGeneration() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1));
|
|
|
|
$expected = '/posts/index/published:1/deleted:1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 0, 'deleted' => 0));
|
|
|
|
$expected = '/posts/index/published:0/deleted:0';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
extract(Router::getNamedExpressions());
|
2011-12-01 07:21:31 +00:00
|
|
|
Router::connectNamed(array('file' => '[\w\.\-]+\.(html|png)'));
|
2008-05-30 11:40:08 +00:00
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-21 03:40:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'admin' => true, 'controller' => 'controller', 'action' => 'index', 'plugin' => null
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/',
|
|
|
|
'here' => '/',
|
|
|
|
'webroot' => '/base/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
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";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest('admin/controller/index');
|
|
|
|
$request->addParams(array(
|
|
|
|
'admin' => true, 'controller' => 'controller', 'action' => 'index', 'plugin' => null
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-02 05:43:37 +00:00
|
|
|
$request->base = '/';
|
|
|
|
Router::setRequestInfo($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/admin/controller/index/type:whatever');
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('type' => 'new'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = "/admin/controller/index/type:new";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNamedArgsUrlParsing() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::connectNamed(false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), array_keys($result['rules']));
|
2011-03-03 12:32:06 +00:00
|
|
|
$this->assertFalse($result['greedyNamed']);
|
2008-05-30 11:40:08 +00:00
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::connectNamed(true);
|
2011-03-02 11:20:45 +00:00
|
|
|
$named = Router::namedConfig();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($named['default'], array_keys($result['rules']));
|
2011-03-03 12:32:06 +00:00
|
|
|
$this->assertTrue($result['greedyNamed']);
|
2011-07-17 03:36:30 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/foo/view/param1:value1:1/param2:value2:3/param:value');
|
2011-07-17 03:36:30 +00:00
|
|
|
$expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'foo', 'action' => 'view', 'plugin' => null);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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-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
|
|
|
* @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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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('/');
|
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index',
|
2010-05-02 05:43:37 +00:00
|
|
|
'prefix' => null, 'admin' => false,'url' => array('url' => 'images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/images/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-11-29 21:09:45 +00:00
|
|
|
$result = Router::url(array('protected' => true));
|
|
|
|
$expected = '/protected/images/index';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-11-29 21:09:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/images/add';
|
2010-12-18 19:26:45 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1));
|
|
|
|
$expected = '/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1));
|
|
|
|
$expected = '/others/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-05 14:48:09 +00:00
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlGenerationWithAutoPrefixes() {
|
2009-09-27 05:22:46 +00:00
|
|
|
Configure::write('Routing.prefixes', array('protected'));
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
2010-05-02 05:43:37 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index',
|
2010-05-02 05:43:37 +00:00
|
|
|
'prefix' => null, 'protected' => false, 'url' => array('url' => 'images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/images/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-04-25 00:48:23 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add_protected_test', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add_protected_test';
|
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1));
|
|
|
|
$expected = '/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2011-02-24 21:43:13 +00:00
|
|
|
$result = Router::url(array('action' => 'protectededit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/protectededit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/images/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1));
|
|
|
|
$expected = '/others/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true));
|
|
|
|
$expected = '/protected/others/edit/1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1));
|
|
|
|
$expected = '/protected/others/edit/1/page:1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that auto-generated prefix routes persist
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoPrefixRoutePersistence() {
|
2009-09-27 05:22:46 +00:00
|
|
|
Configure::write('Routing.prefixes', array('protected'));
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index', 'prefix' => 'protected',
|
|
|
|
'protected' => true, 'url' => array('url' => 'protected/images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/protected/images/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
|
|
|
|
$expected = '/protected/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => false));
|
|
|
|
$expected = '/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-27 05:22:46 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPrefixOverride() {
|
2009-09-30 14:19:43 +00:00
|
|
|
Configure::write('Routing.prefixes', array('protected', 'admin'));
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index', 'prefix' => 'protected',
|
|
|
|
'protected' => true, 'url' => array('url' => 'protected/images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/protected/images/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2009-09-30 14:19:43 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'admin' => true));
|
|
|
|
$expected = '/admin/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-11-05 04:05:25 +00:00
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index', 'prefix' => 'admin',
|
|
|
|
'admin' => true, 'url' => array('url' => 'admin/images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/admin/images/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2009-09-30 14:19:43 +00:00
|
|
|
$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
|
|
|
|
$expected = '/protected/images/add';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-09-30 14:19:43 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 02:30:26 +00:00
|
|
|
/**
|
|
|
|
* Test that setting a prefix to false is ignored, as its generally user error.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPrefixFalseIgnored() {
|
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2012-02-14 02:16:57 +00:00
|
|
|
Router::reload();
|
|
|
|
|
2012-01-17 02:30:26 +00:00
|
|
|
Router::connect('/cache_css/*', array('admin' => false, 'controller' => 'asset_compress', 'action' => 'get'));
|
|
|
|
|
|
|
|
$url = Router::url(array('controller' => 'asset_compress', 'action' => 'get', 'test'));
|
|
|
|
$expected = '/cache_css/test';
|
|
|
|
$this->assertEquals($expected, $url);
|
|
|
|
|
|
|
|
$url = Router::url(array('admin' => false, 'controller' => 'asset_compress', 'action' => 'get', 'test'));
|
|
|
|
$expected = '/cache_css/test';
|
|
|
|
$this->assertEquals($expected, $url);
|
|
|
|
|
|
|
|
$url = Router::url(array('admin' => true, 'controller' => 'asset_compress', 'action' => 'get', 'test'));
|
|
|
|
$this->assertEquals('/admin/asset_compress/get/test', $url);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRemoveBase() {
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'controller', 'action' => 'index',
|
|
|
|
'bare' => 0, 'url' => array('url' => 'protected/images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/base',
|
|
|
|
'here' => '/',
|
|
|
|
'webroot' => '/base/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action'));
|
2009-10-02 18:00:33 +00:00
|
|
|
$expected = '/base/my_controller/my_action';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => true));
|
|
|
|
$expected = '/base/my_controller/my_action/base:1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPagesUrlParsing() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
|
|
|
|
$result = Router::parse('/');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('pass' => array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/pages/home/');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/pages/display/home/event:value');
|
|
|
|
$expected = array('pass' => array('home'), 'named' => array('event' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
|
|
$result = Router::parse('/pages/contact/');
|
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('pass' => array('contact'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-04-24 17:40:15 +00:00
|
|
|
/**
|
|
|
|
* test that requests with a trailing dot don't loose the do.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testParsingWithTrailingPeriod() {
|
2010-04-24 17:40:15 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2010-04-24 17:40:15 +00:00
|
|
|
$result = Router::parse('/posts/view/something.');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('something.', $result['pass'][0], 'Period was chopped off %s');
|
2010-04-24 17:40:15 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/something. . .');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('something. . .', $result['pass'][0], 'Period was chopped off %s');
|
2010-04-24 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 00:30:00 +00:00
|
|
|
/**
|
|
|
|
* test that requests with a trailing dot don't loose the do.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testParsingWithTrailingPeriodAndParseExtensions() {
|
2010-04-25 00:30:00 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2010-04-25 00:30:00 +00:00
|
|
|
Router::parseExtensions('json');
|
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/something.');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('something.', $result['pass'][0], 'Period was chopped off %s');
|
2010-04-25 00:30:00 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/posts/view/something. . .');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('something. . .', $result['pass'][0], 'Period was chopped off %s');
|
2010-04-25 00:30:00 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:54:44 +00:00
|
|
|
/**
|
|
|
|
* test that patterns work for :action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testParsingWithPatternOnAction() {
|
2010-10-15 01:54:44 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect(
|
2010-11-04 12:29:23 +00:00
|
|
|
'/blog/:action/*',
|
|
|
|
array('controller' => 'blog_posts'),
|
2010-10-15 01:54:44 +00:00
|
|
|
array('action' => 'other|actions')
|
|
|
|
);
|
|
|
|
$result = Router::parse('/blog/other');
|
|
|
|
$expected = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'controller' => 'blog_posts',
|
|
|
|
'action' => 'other',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-10-15 01:54:44 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/blog/foobar');
|
2012-10-26 22:18:05 +00:00
|
|
|
$this->assertSame(array(), $result);
|
2010-11-04 12:29:23 +00:00
|
|
|
|
2010-10-15 01:54:44 +00:00
|
|
|
$result = Router::url(array('controller' => 'blog_posts', 'action' => 'foo'));
|
2011-07-17 03:36:30 +00:00
|
|
|
$this->assertEquals('/blog_posts/foo', $result);
|
2010-10-15 01:54:44 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'blog_posts', 'action' => 'actions'));
|
2011-07-17 03:36:30 +00:00
|
|
|
$this->assertEquals('/blog/actions', $result);
|
2010-10-15 01:54:44 +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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testParsingWithPrefixes() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$adminParams = array('prefix' => 'admin', 'admin' => true);
|
|
|
|
Router::connect('/admin/:controller', $adminParams);
|
|
|
|
Router::connect('/admin/:controller/:action', $adminParams);
|
|
|
|
Router::connect('/admin/:controller/:action/*', $adminParams);
|
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'controller', 'action' => 'index'
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/base',
|
|
|
|
'here' => '/',
|
|
|
|
'webroot' => '/base/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/admin/posts/');
|
2011-03-11 03:04:46 +00:00
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'admin_index', 'admin' => true);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/admin/posts');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('admin' => true, 'controller' => 'posts'));
|
|
|
|
$expected = '/base/admin/posts';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::prefixes();
|
|
|
|
$expected = array('admin');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'controller', 'action' => 'index',
|
|
|
|
'bare' => 0
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/base',
|
|
|
|
'here' => '/',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2008-07-19 17:20:42 +00:00
|
|
|
$result = Router::parse('/members/posts/index');
|
2011-03-11 03:04:46 +00:00
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'members_index', 'members' => true);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-08-13 18:07:52 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Router::url(array('members' => true, 'controller' => 'posts', 'action' => 'index', 'page' => 2));
|
2008-07-19 17:20:42 +00:00
|
|
|
$expected = '/base/members/posts/index/page:2';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlWritingWithPrefixes() {
|
2008-07-09 14:28:32 +00:00
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-09 14:28:32 +00:00
|
|
|
|
2011-03-11 03:04:46 +00:00
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'company_login', 'company' => true));
|
|
|
|
$expected = '/company/users/login';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-03-11 03:04:46 +00:00
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'users', 'action' => 'login',
|
|
|
|
'company' => true
|
|
|
|
))->addPaths(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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-07-09 14:28:32 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlWritingWithPrefixesAndCustomRoutes() {
|
2010-04-12 03:13:18 +00:00
|
|
|
Router::connect(
|
2010-07-31 15:23:02 +00:00
|
|
|
'/admin/login',
|
2010-04-12 03:13:18 +00:00
|
|
|
array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true)
|
|
|
|
);
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'posts', 'action' => 'index',
|
|
|
|
'admin' => true, 'prefix' => 'admin'
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '/',
|
|
|
|
'here' => '/',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2010-04-12 03:13:18 +00:00
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/login', $result);
|
2010-04-12 03:13:18 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'login'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/login', $result);
|
2010-04-12 03:13:18 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'users', 'action' => 'admin_login'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/admin/login', $result);
|
2010-04-12 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 2, 'whatever'));
|
|
|
|
$expected = '/test2/whatever';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-11-29 14:49:19 +00:00
|
|
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 'home', 'whatever'));
|
|
|
|
$expected = '/test-passed/whatever';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-11-29 14:49:19 +00:00
|
|
|
|
2009-10-02 18:00:33 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index',
|
|
|
|
'url' => array('url' => 'protected/images/index')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/protected/images/index',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::prefixes();
|
2009-09-27 02:37:19 +00:00
|
|
|
$expected = array('admin', 'protected');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRegexRouteMatching() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng'));
|
|
|
|
|
|
|
|
$result = Router::parse('/eng/test/test_action');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'locale' => 'eng', 'controller' => 'test', 'action' => 'test_action', 'plugin' => null);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/badness/test/test_action');
|
2012-10-26 22:18:05 +00:00
|
|
|
$this->assertSame(array(), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng'));
|
|
|
|
|
2010-05-02 06:16:16 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
Router::setRequestInfo(
|
|
|
|
$request->addParams(array(
|
|
|
|
'plugin' => null, 'controller' => 'test', 'action' => 'index',
|
|
|
|
'url' => array('url' => 'test/test_action')
|
|
|
|
))->addPaths(array(
|
|
|
|
'base' => '',
|
|
|
|
'here' => '/test/test_action',
|
|
|
|
'webroot' => '/',
|
|
|
|
))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'test_another_action'));
|
2009-10-02 18:00:33 +00:00
|
|
|
$expected = '/test/test_another_action';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'test_another_action', 'locale' => 'eng'));
|
|
|
|
$expected = '/eng/test/test_another_action';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('action' => 'test_another_action', 'locale' => 'badness'));
|
|
|
|
$expected = '/test/test_another_action/locale:badness';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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';
|
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, Router::stripPlugin($url, $pluginName));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(Router::stripPlugin($url), $url);
|
|
|
|
$this->assertEquals(Router::stripPlugin($url, null), $url);
|
2009-07-22 13:02:31 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2009-07-28 09:49:27 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* testCurrentRoute
|
2009-07-28 09:49:27 +00:00
|
|
|
*
|
|
|
|
* 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');
|
2010-05-02 06:16:16 +00:00
|
|
|
$route = Router::currentRoute();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_merge($url, array('plugin' => null)), $route->defaults);
|
2009-07-28 09:49:27 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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');
|
2010-05-02 06:16:16 +00:00
|
|
|
$route = Router::requestRoute();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(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');
|
2010-05-02 06:16:16 +00:00
|
|
|
$route = Router::requestRoute();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(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');
|
2010-05-02 06:16:16 +00:00
|
|
|
$route = Router::requestRoute();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_merge($url, array('plugin' => null)), $route->defaults);
|
2009-07-28 09:49:27 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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));
|
2010-05-02 05:59:56 +00:00
|
|
|
|
2009-07-28 09:49:27 +00:00
|
|
|
$expected = array(
|
2009-12-16 20:04:59 +00:00
|
|
|
'plugin' => null, 'controller' => false, 'action' => false,
|
2012-04-13 13:58:45 +00:00
|
|
|
'named' => array(), 'pass' => array(),
|
|
|
|
'param1' => '1', 'param2' => '2',
|
2009-07-28 09:49:27 +00:00
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(Router::getParams(), $expected);
|
|
|
|
$this->assertEquals(Router::getParam('controller'), false);
|
|
|
|
$this->assertEquals(Router::getParam('param1'), '1');
|
|
|
|
$this->assertEquals(Router::getParam('param2'), '2');
|
2009-07-28 09:49:27 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
$params = array('controller' => 'pages', 'action' => 'display');
|
|
|
|
Router::setRequestInfo(array($params, $paths));
|
2012-04-13 13:58:45 +00:00
|
|
|
$expected = array(
|
|
|
|
'plugin' => null, 'controller' => 'pages', 'action' => 'display',
|
|
|
|
'named' => array(), 'pass' => array(),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(Router::getParams(), $expected);
|
|
|
|
$this->assertEquals(Router::getParams(true), $expected);
|
2009-07-28 09:49:27 +00:00
|
|
|
}
|
2009-11-26 04:39:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that connectDefaults() can disable default route connection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDefaultsMethod() {
|
2009-11-26 04:39:07 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConnectDefaultRoutes() {
|
2010-01-18 15:05:23 +00:00
|
|
|
App::build(array(
|
2012-03-13 01:36:27 +00:00
|
|
|
'plugins' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
2010-01-18 15:05:23 +00:00
|
|
|
)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin', 'PluginJs'));
|
2010-04-08 04:03:46 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:36:30 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2010-01-18 15:05:23 +00:00
|
|
|
|
2010-07-31 15:38:10 +00:00
|
|
|
$result = Router::url(array('plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/plugin_js/js_file', $result);
|
2010-01-18 15:05:23 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/plugin_js/js_file');
|
|
|
|
$expected = array(
|
|
|
|
'plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index',
|
|
|
|
'named' => array(), 'pass' => array()
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-04-08 04:03:46 +00:00
|
|
|
|
|
|
|
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/test_plugin', $result);
|
2010-04-08 04:03:46 +00:00
|
|
|
|
|
|
|
$result = Router::parse('/test_plugin');
|
|
|
|
$expected = array(
|
|
|
|
'plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index',
|
|
|
|
'named' => array(), 'pass' => array()
|
|
|
|
);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result, '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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUsingCustomRouteClass() {
|
2010-05-21 02:55:25 +00:00
|
|
|
$mock = $this->getMock('CakeRoute', array(), array(), 'MockConnectedRoute', false);
|
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');
|
2010-05-21 02:55:25 +00:00
|
|
|
$routes[0]->expects($this->any())
|
|
|
|
->method('parse')
|
|
|
|
->will($this->returnValue($expected));
|
2009-12-04 01:50:13 +00:00
|
|
|
$result = Router::parse('/test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-12-04 01:50:13 +00:00
|
|
|
}
|
2009-12-28 04:09:26 +00:00
|
|
|
|
2010-04-24 00:22:02 +00:00
|
|
|
/**
|
|
|
|
* test that route classes must extend CakeRoute
|
|
|
|
*
|
2011-11-04 01:16:29 +00:00
|
|
|
* @expectedException RouterException
|
2010-04-24 00:22:02 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCustomRouteException() {
|
2010-04-24 00:42:53 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRouterReverse() {
|
2009-12-28 04:09:26 +00:00
|
|
|
$params = array(
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array(),
|
2010-08-05 03:35:49 +00:00
|
|
|
'url' => array(),
|
|
|
|
'autoRender' => 1,
|
|
|
|
'bare' => 1,
|
|
|
|
'return' => 1,
|
2011-05-17 00:35:27 +00:00
|
|
|
'requested' => 1,
|
|
|
|
'_Token' => array('key' => 'sekret')
|
2009-12-28 04:09:26 +00:00
|
|
|
);
|
|
|
|
$result = Router::reverse($params);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/posts/view/1', $result);
|
2009-12-28 04:09:26 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'index',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array('page' => 1, 'sort' => 'Article.title', 'direction' => 'desc'),
|
|
|
|
'url' => array()
|
|
|
|
);
|
|
|
|
$result = Router::reverse($params);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/posts/index/1/page:1/sort:Article.title/direction:desc', $result);
|
2009-12-28 04:09:26 +00:00
|
|
|
|
|
|
|
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);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/eng/posts/view/1', $result);
|
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);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/eng/posts/view/1?foo=bar&baz=quu', $result);
|
2009-09-30 13:49:39 +00:00
|
|
|
|
2010-05-02 06:19:32 +00:00
|
|
|
$request = new CakeRequest('/eng/posts/view/1');
|
|
|
|
$request->addParams(array(
|
|
|
|
'lang' => 'eng',
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
2010-07-31 17:03:45 +00:00
|
|
|
'named' => array(),
|
2010-05-02 06:19:32 +00:00
|
|
|
));
|
2011-01-21 02:20:23 +00:00
|
|
|
$request->query = array('url' => 'eng/posts/view/1', 'test' => 'value');
|
2010-05-02 06:19:32 +00:00
|
|
|
$result = Router::reverse($request);
|
2011-01-21 02:20:23 +00:00
|
|
|
$expected = '/eng/posts/view/1?test=value';
|
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-04 20:11:47 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'lang' => 'eng',
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' => 'eng/posts/view/1')
|
|
|
|
);
|
|
|
|
$result = Router::reverse($params, true);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/^http(s)?:\/\//', $result);
|
2009-09-30 13:49:39 +00:00
|
|
|
}
|
2009-10-02 05:09:38 +00:00
|
|
|
|
2011-08-23 01:19:35 +00:00
|
|
|
/**
|
|
|
|
* Test that extensions work with Router::reverse()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testReverseWithExtension() {
|
|
|
|
Router::parseExtensions('json');
|
|
|
|
|
|
|
|
$request = new CakeRequest('/posts/view/1.json');
|
|
|
|
$request->addParams(array(
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'view',
|
|
|
|
'pass' => array(1),
|
|
|
|
'named' => array(),
|
|
|
|
'ext' => 'json',
|
|
|
|
));
|
2011-09-27 21:47:44 +00:00
|
|
|
$request->query = array();
|
2011-08-23 01:19:35 +00:00
|
|
|
$result = Router::reverse($request);
|
|
|
|
$expected = '/posts/view/1.json';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2009-11-27 04:46:42 +00:00
|
|
|
/**
|
2010-05-02 06:16:16 +00:00
|
|
|
* test that setRequestInfo can accept arrays and turn that into a CakeRequest object.
|
2009-11-27 04:46:42 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetRequestInfoLegacy() {
|
2010-05-02 06:16:16 +00:00
|
|
|
Router::setRequestInfo(array(
|
|
|
|
array(
|
|
|
|
'plugin' => null, 'controller' => 'images', 'action' => 'index',
|
|
|
|
'url' => array('url' => 'protected/images/index')
|
|
|
|
),
|
2009-12-16 20:04:59 +00:00
|
|
|
array(
|
2010-05-02 06:16:16 +00:00
|
|
|
'base' => '',
|
|
|
|
'here' => '/protected/images/index',
|
|
|
|
'webroot' => '/',
|
2009-12-16 20:04:59 +00:00
|
|
|
)
|
2010-07-31 15:23:02 +00:00
|
|
|
));
|
2010-05-02 06:16:16 +00:00
|
|
|
$result = Router::getRequest();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('images', $result->controller);
|
|
|
|
$this->assertEquals('index', $result->action);
|
|
|
|
$this->assertEquals('', $result->base);
|
|
|
|
$this->assertEquals('/protected/images/index', $result->here);
|
|
|
|
$this->assertEquals('/', $result->webroot);
|
2010-04-07 03:05:04 +00:00
|
|
|
}
|
2010-10-30 01:33:56 +00:00
|
|
|
|
2011-08-13 01:21:05 +00:00
|
|
|
/**
|
|
|
|
* Test that Router::url() uses the first request
|
|
|
|
*/
|
|
|
|
public function testUrlWithRequestAction() {
|
|
|
|
$firstRequest = new CakeRequest('/posts/index');
|
|
|
|
$firstRequest->addParams(array(
|
|
|
|
'plugin' => null,
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'index'
|
|
|
|
))->addPaths(array('base' => ''));
|
|
|
|
|
|
|
|
$secondRequest = new CakeRequest('/posts/index');
|
|
|
|
$secondRequest->addParams(array(
|
|
|
|
'requested' => 1,
|
|
|
|
'plugin' => null,
|
|
|
|
'controller' => 'comments',
|
|
|
|
'action' => 'listing'
|
|
|
|
))->addPaths(array('base' => ''));
|
|
|
|
|
|
|
|
Router::setRequestInfo($firstRequest);
|
|
|
|
Router::setRequestInfo($secondRequest);
|
|
|
|
|
|
|
|
$result = Router::url(array('base' => false));
|
|
|
|
$this->assertEquals('/comments/listing', $result, 'with second requests, the last should win.');
|
|
|
|
|
|
|
|
Router::popRequest();
|
|
|
|
$result = Router::url(array('base' => false));
|
|
|
|
$this->assertEquals('/posts', $result, 'with second requests, the last should win.');
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-10-30 01:33:56 +00:00
|
|
|
/**
|
|
|
|
* test that a route object returning a full url is not modified.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlFullUrlReturnFromRoute() {
|
2010-10-30 01:33:56 +00:00
|
|
|
$url = 'http://example.com/posts/view/1';
|
|
|
|
|
|
|
|
$this->getMock('CakeRoute', array(), array('/'), 'MockReturnRoute');
|
|
|
|
$routes = Router::connect('/:controller/:action', array(), array('routeClass' => 'MockReturnRoute'));
|
|
|
|
$routes[0]->expects($this->any())->method('match')
|
|
|
|
->will($this->returnValue($url));
|
|
|
|
|
|
|
|
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 1));
|
|
|
|
$this->assertEquals($url, $result);
|
|
|
|
}
|
|
|
|
|
2010-11-03 03:26:41 +00:00
|
|
|
/**
|
|
|
|
* test protocol in url
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testUrlProtocol() {
|
|
|
|
$url = 'http://example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($url, Router::url($url));
|
2010-11-03 03:26:41 +00:00
|
|
|
|
|
|
|
$url = 'ed2k://example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($url, Router::url($url));
|
2010-11-03 03:26:41 +00:00
|
|
|
|
|
|
|
$url = 'svn+ssh://example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($url, Router::url($url));
|
2011-10-18 01:03:25 +00:00
|
|
|
|
|
|
|
$url = '://example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($url, Router::url($url));
|
2010-11-03 03:26:41 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:54:44 +00:00
|
|
|
/**
|
2010-11-17 02:48:13 +00:00
|
|
|
* Testing that patterns on the :action param work properly.
|
2010-10-15 01:54:44 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPatternOnAction() {
|
2010-12-13 02:02:42 +00:00
|
|
|
$route = new CakeRoute(
|
2010-11-04 12:29:23 +00:00
|
|
|
'/blog/:action/*',
|
|
|
|
array('controller' => 'blog_posts'),
|
2010-10-15 01:54:44 +00:00
|
|
|
array('action' => 'other|actions')
|
|
|
|
);
|
|
|
|
$result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo'));
|
|
|
|
$this->assertFalse($result);
|
2010-11-04 12:29:23 +00:00
|
|
|
|
2010-10-15 01:54:44 +00:00
|
|
|
$result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions'));
|
2010-11-17 02:48:13 +00:00
|
|
|
$this->assertEquals('/blog/actions/', $result);
|
2010-11-04 12:29:23 +00:00
|
|
|
|
2010-10-15 01:54:44 +00:00
|
|
|
$result = $route->parse('/blog/other');
|
|
|
|
$expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-11-04 12:29:23 +00:00
|
|
|
|
2010-10-15 01:54:44 +00:00
|
|
|
$result = $route->parse('/blog/foobar');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
2012-01-02 11:53:32 +00:00
|
|
|
/**
|
|
|
|
* Tests resourceMap as getter and setter.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testResourceMap() {
|
|
|
|
$default = Router::resourceMap();
|
2012-05-12 17:43:39 +00:00
|
|
|
$expected = array(
|
2012-01-02 11:53:32 +00:00
|
|
|
array('action' => 'index', 'method' => 'GET', 'id' => false),
|
|
|
|
array('action' => 'view', 'method' => 'GET', 'id' => true),
|
|
|
|
array('action' => 'add', 'method' => 'POST', 'id' => false),
|
|
|
|
array('action' => 'edit', 'method' => 'PUT', 'id' => true),
|
|
|
|
array('action' => 'delete', 'method' => 'DELETE', 'id' => true),
|
|
|
|
array('action' => 'edit', 'method' => 'POST', 'id' => true)
|
|
|
|
);
|
2012-05-12 17:43:39 +00:00
|
|
|
$this->assertEquals($default, $expected);
|
2012-03-13 01:36:27 +00:00
|
|
|
|
2012-01-02 11:53:32 +00:00
|
|
|
$custom = array(
|
|
|
|
array('action' => 'index', 'method' => 'GET', 'id' => false),
|
|
|
|
array('action' => 'view', 'method' => 'GET', 'id' => true),
|
|
|
|
array('action' => 'add', 'method' => 'POST', 'id' => false),
|
|
|
|
array('action' => 'edit', 'method' => 'PUT', 'id' => true),
|
|
|
|
array('action' => 'delete', 'method' => 'DELETE', 'id' => true),
|
|
|
|
array('action' => 'update', 'method' => 'POST', 'id' => true)
|
|
|
|
);
|
|
|
|
Router::resourceMap($custom);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(Router::resourceMap(), $custom);
|
2012-03-13 01:36:27 +00:00
|
|
|
|
2012-01-02 11:53:32 +00:00
|
|
|
Router::resourceMap($default);
|
|
|
|
}
|
|
|
|
|
2010-11-08 01:33:05 +00:00
|
|
|
/**
|
|
|
|
* test setting redirect routes
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRouteRedirection() {
|
2010-11-08 01:33:05 +00:00
|
|
|
Router::redirect('/blog', array('controller' => 'posts'), array('status' => 302));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(1, count(Router::$routes));
|
2011-10-23 02:44:21 +00:00
|
|
|
Router::$routes[0]->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2011-10-23 02:56:50 +00:00
|
|
|
Router::$routes[0]->stop = false;
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(302, Router::$routes[0]->options['status']);
|
2010-11-08 01:33:05 +00:00
|
|
|
|
|
|
|
Router::parse('/blog');
|
2012-01-19 05:30:41 +00:00
|
|
|
$header = Router::$routes[0]->response->header();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(Router::url('/posts', true), $header['Location']);
|
|
|
|
$this->assertEquals(302, Router::$routes[0]->response->statusCode());
|
2010-11-08 01:33:05 +00:00
|
|
|
|
|
|
|
Router::$routes[0]->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
|
|
|
Router::parse('/not-a-match');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), Router::$routes[0]->response->header());
|
2010-11-08 01:33:05 +00:00
|
|
|
}
|
2010-11-08 01:42:04 +00:00
|
|
|
|
2012-01-13 03:19:55 +00:00
|
|
|
/**
|
|
|
|
* Test setting the default route class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDefaultRouteClass() {
|
|
|
|
$this->getMock('CakeRoute', array(), array('/test'), 'TestDefaultRouteClass');
|
|
|
|
Router::defaultRouteClass('TestDefaultRouteClass');
|
|
|
|
|
|
|
|
$result = Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
$this->assertInstanceOf('TestDefaultRouteClass', $result[0]);
|
|
|
|
}
|
|
|
|
|
2012-01-13 20:27:48 +00:00
|
|
|
/**
|
|
|
|
* Test getting the default route class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDefaultRouteClassGetter() {
|
|
|
|
$routeClass = 'TestDefaultRouteClass';
|
|
|
|
Router::defaultRouteClass($routeClass);
|
|
|
|
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->assertEquals($routeClass, Router::defaultRouteClass());
|
|
|
|
$this->assertEquals($routeClass, Router::defaultRouteClass(null));
|
2012-01-13 20:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that route classes must extend CakeRoute
|
|
|
|
*
|
|
|
|
* @expectedException RouterException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDefaultRouteException() {
|
|
|
|
Router::defaultRouteClass('');
|
|
|
|
Router::connect('/:controller', array());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that route classes must extend CakeRoute
|
|
|
|
*
|
|
|
|
* @expectedException RouterException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSettingInvalidDefaultRouteException() {
|
|
|
|
Router::defaultRouteClass('Object');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that class must exist
|
|
|
|
*
|
|
|
|
* @expectedException RouterException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSettingNonExistentDefaultRouteException() {
|
|
|
|
Router::defaultRouteClass('NonExistentClass');
|
|
|
|
}
|
|
|
|
|
2012-05-07 20:48:58 +00:00
|
|
|
/**
|
|
|
|
* Tests generating well-formed querystrings
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testQueryString() {
|
|
|
|
$result = Router::queryString(array('var' => 'foo bar'));
|
|
|
|
$expected = '?var=foo+bar';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Router::queryString(false, array('some' => 'param', 'foo' => 'bar'));
|
|
|
|
$expected = '?some=param&foo=bar';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$existing = array('apple' => 'red', 'pear' => 'green');
|
|
|
|
$result = Router::queryString($existing, array('some' => 'param', 'foo' => 'bar'));
|
|
|
|
$expected = '?apple=red&pear=green&some=param&foo=bar';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$existing = 'apple=red&pear=green';
|
|
|
|
$result = Router::queryString($existing, array('some' => 'param', 'foo' => 'bar'));
|
|
|
|
$expected = '?apple=red&pear=green&some=param&foo=bar';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$existing = '?apple=red&pear=green';
|
|
|
|
$result = Router::queryString($existing, array('some' => 'param', 'foo' => 'bar'));
|
|
|
|
$expected = '?apple=red&pear=green&some=param&foo=bar';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Router::queryString('apple=red&pear=green');
|
|
|
|
$expected = '?apple=red&pear=green';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Router::queryString('foo=bar', array('php' => 'nut', 'jose' => 'zap'), true);
|
|
|
|
$expected = '?foo=bar&php=nut&jose=zap';
|
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-09 21:32:57 +00:00
|
|
|
|
|
|
|
$result = Router::queryString('foo=bar&', array('php' => 'nut', 'jose' => 'zap'), true);
|
|
|
|
$expected = '?foo=bar&php=nut&jose=zap';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Router::queryString('foo=bar&', array('php' => 'nut', 'jose' => 'zap'));
|
|
|
|
$expected = '?foo=bar&php=nut&jose=zap';
|
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-07 20:48:58 +00:00
|
|
|
}
|
2010-04-07 03:05:04 +00:00
|
|
|
}
|