mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Expanding test coverage of newly added Routing.prefixes.
Flagging legacy support test cases.
This commit is contained in:
parent
552f698d4e
commit
dfae21be8b
1 changed files with 107 additions and 6 deletions
|
@ -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
|
||||
*
|
||||
|
@ -1043,12 +1053,13 @@ class RouterTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class RouterTest extends CakeTestCase {
|
|||
$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 @@ class RouterTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
|
@ -1438,6 +1458,87 @@ class RouterTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue