2010-05-04 04:35:22 +00:00
|
|
|
<?php
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('PluginShortRoute', 'Routing/Route');
|
|
|
|
App::uses('Router', 'Routing');
|
2010-05-04 04:35:22 +00:00
|
|
|
/**
|
|
|
|
* test case for PluginShortRoute
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing.Route
|
2010-05-04 04:35:22 +00:00
|
|
|
*/
|
|
|
|
class PluginShortRouteTestCase extends CakeTestCase {
|
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2010-05-04 04:35:22 +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();
|
2010-05-04 04:35:22 +00:00
|
|
|
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
|
|
|
|
Router::reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the parsing of routes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testParsing() {
|
2010-05-04 04:35:22 +00:00
|
|
|
$route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
|
|
|
|
|
|
|
|
$result = $route->parse('/foo');
|
|
|
|
$this->assertEqual($result['plugin'], 'foo');
|
|
|
|
$this->assertEqual($result['controller'], 'foo');
|
|
|
|
$this->assertEqual($result['action'], 'index');
|
|
|
|
|
|
|
|
$result = $route->parse('/wrong');
|
|
|
|
$this->assertFalse($result, 'Wrong plugin name matched %s');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the reverse routing of the plugin shortcut urls.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMatch() {
|
2010-05-04 04:35:22 +00:00
|
|
|
$route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'foo', 'controller' => 'posts', 'action' => 'index'));
|
|
|
|
$this->assertFalse($result, 'plugin controller mismatch was converted. %s');
|
|
|
|
|
|
|
|
$result = $route->match(array('plugin' => 'foo', 'controller' => 'foo', 'action' => 'index'));
|
|
|
|
$this->assertEqual($result, '/foo');
|
|
|
|
}
|
|
|
|
}
|