2010-05-04 04:35:22 +00:00
|
|
|
<?php
|
2011-10-10 21:18:48 +00:00
|
|
|
/**
|
|
|
|
* CakeRequest Test case file.
|
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://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.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-10-10 21:18:48 +00:00
|
|
|
* @package Cake.Test.Case.Routing.Route
|
|
|
|
* @since CakePHP(tm) v 2.0
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2011-10-10 21:18:48 +00:00
|
|
|
*/
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-29 09:05:17 +00:00
|
|
|
* test the reverse routing of the plugin shortcut URLs.
|
2010-05-04 04:35:22 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
}
|
|
|
|
}
|