2010-05-04 04:35:22 +00:00
|
|
|
<?php
|
2011-10-10 21:18:48 +00:00
|
|
|
/**
|
|
|
|
* CakeRequest Test case file.
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-10-10 21:18:48 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2011-10-10 21:18:48 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-10-10 21:18:48 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @package Cake.Test.Case.Routing.Route
|
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('PluginShortRoute', 'Routing/Route');
|
|
|
|
App::uses('Router', 'Routing');
|
2012-03-13 01:36:27 +00:00
|
|
|
|
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
|
|
|
*/
|
2012-11-21 14:39:03 +00:00
|
|
|
class PluginShortRouteTest extends CakeTestCase {
|
2012-03-13 01:36:27 +00:00
|
|
|
|
2010-05-04 04:35:22 +00:00
|
|
|
/**
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('foo', $result['plugin']);
|
|
|
|
$this->assertEquals('foo', $result['controller']);
|
|
|
|
$this->assertEquals('index', $result['action']);
|
2010-05-04 04:35:22 +00:00
|
|
|
|
|
|
|
$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'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/foo', $result);
|
2010-05-04 04:35:22 +00:00
|
|
|
}
|
|
|
|
}
|