Skip to content

Commit

Permalink
Expanding test coverage of newly added Routing.prefixes.
Browse files Browse the repository at this point in the history
Flagging legacy support test cases.
  • Loading branch information
markstory committed Sep 27, 2009
1 parent 552f698 commit dfae21b
Showing 1 changed file with 107 additions and 6 deletions.
113 changes: 107 additions & 6 deletions cake/tests/cases/libs/router.test.php
Expand Up @@ -41,11 +41,21 @@ class RouterTest extends CakeTestCase {
* @return void
*/
function setUp() {
Configure::write('Routing.admin', null);
$this->_routing = Configure::read('Routing');
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
Router::reload();
$this->router =& Router::getInstance();
}

/**
* end the test and reset the environment
*
* @return void
**/
function endTest() {
Configure::write('Routing', $this->_routing);
}

/**
* testReturnedInstanceReference method
*
Expand Down Expand Up @@ -1043,12 +1053,13 @@ function testRoutingPrefixesSetting() {
}

/**
* testAdminRouting method
* test compatibility with old Routing.admin config setting.
*
* @access public
* @return void
* @todo Once Routing.admin is removed update these tests.
*/
function testAdminRouting() {
function testAdminRoutingCompatibility() {
Configure::write('Routing.admin', 'admin');

Router::reload();
Expand Down Expand Up @@ -1104,8 +1115,15 @@ function testAdminRouting() {
$result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
$expected = '/beheer/posts/index/0?var=test&var2=test2';
$this->assertEqual($result, $expected);
}

Configure::write('Routing.admin', 'admin');
/**
* Test prefix routing and plugin combinations
*
* @return void
**/
function testPrefixRoutingAndPlugins() {
Configure::write('Routing.prefixes', array('admin'));
$paths = App::path('plugins');
App::build(array(
'plugins' => array(
Expand Down Expand Up @@ -1376,12 +1394,14 @@ function testNamedArgsUrlParsing() {
}

/**
* testUrlGenerationWithPrefixes method
* test url generation with legacy (1.2) style prefix routes.
*
* @access public
* @return void
* @todo Remove tests related to legacy style routes.
* @see testUrlGenerationWithAutoPrefixes
*/
function testUrlGenerationWithPrefixes() {
function testUrlGenerationWithLegacyPrefixes() {
Router::reload();
Router::connect('/protected/:controller/:action/*', array(
'controller' => 'users',
Expand Down Expand Up @@ -1438,6 +1458,87 @@ function testUrlGenerationWithPrefixes() {
$this->assertEqual($result, $expected);
}

/**
* test newer style automatically generated prefix routes.
*
* @return void
**/
function testUrlGenerationWithAutoPrefixes() {
Configure::write('Routing.prefixes', array('protected'));
Router::reload();
Router::parse('/');

Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'protected' => false, 'form' => array(), 'url' => array('url' => 'images/index')),
array('base' => '', 'here' => '/images/index', 'webroot' => '/')
));

$result = Router::url(array('controller' => 'images', 'action' => 'add'));
$expected = '/images/add';
$this->assertEqual($result, $expected);

$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true));
$expected = '/protected/images/add';
$this->assertEqual($result, $expected);

$result = Router::url(array('action' => 'edit', 1));
$expected = '/images/edit/1';
$this->assertEqual($result, $expected);

$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
$expected = '/protected/images/edit/1';
$this->assertEqual($result, $expected);

$result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true));
$expected = '/protected/images/edit/1';
$this->assertEqual($result, $expected);

$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
$expected = '/protected/images/edit/1';
$this->assertEqual($result, $expected);

$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1));
$expected = '/others/edit/1';
$this->assertEqual($result, $expected);

$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true));
$expected = '/protected/others/edit/1';
$this->assertEqual($result, $expected);

$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1));
$expected = '/protected/others/edit/1/page:1';
$this->assertEqual($result, $expected);

Router::connectNamed(array('random'));
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'random' => 'my-value'));
$expected = '/protected/others/edit/1/random:my-value';
$this->assertEqual($result, $expected);
}

/**
* test that auto-generated prefix routes persist
*
* @return void
**/
function testAutoPrefixRoutePersistence() {
Configure::write('Routing.prefixes', array('protected'));
Router::reload();
Router::parse('/');

Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array('url' => 'protected/images/index')),
array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/')
));

$result = Router::url(array('controller' => 'images', 'action' => 'add'));
$expected = '/protected/images/add';
$this->assertEqual($result, $expected);

$result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => false));
$expected = '/images/add';
$this->assertEqual($result, $expected);
}

/**
* testRemoveBase method
*
Expand Down

0 comments on commit dfae21b

Please sign in to comment.