Permalink
Browse files

Expanding test coverage of newly added Routing.prefixes.

Flagging legacy support test cases.
  • Loading branch information...
1 parent 552f698 commit dfae21be8b8978d43908fa56f77efad3fcfa5728 @markstory markstory committed Sep 27, 2009
Showing with 107 additions and 6 deletions.
  1. +107 −6 cake/tests/cases/libs/router.test.php
@@ -41,12 +41,22 @@ 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
*
* @access public
@@ -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();
@@ -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(
@@ -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',
@@ -1439,6 +1459,87 @@ function testUrlGenerationWithPrefixes() {
}
/**
+ * 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
*
* @access public

0 comments on commit dfae21b

Please sign in to comment.