2010-05-04 00:35:22 -04:00
|
|
|
<?php
|
2011-10-10 23:18:48 +02:00
|
|
|
/**
|
|
|
|
* CakeRequest Test case file.
|
|
|
|
*
|
2017-06-10 23:33:55 +02:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-11 00:10:52 +02:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2011-10-10 23:18:48 +02:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 21:22:51 +09:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2011-10-10 23:18:48 +02:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-11 00:10:52 +02:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 23:33:55 +02:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-10-10 23:18:48 +02:00
|
|
|
* @package Cake.Test.Case.Routing.Route
|
|
|
|
* @since CakePHP(tm) v 2.0
|
2013-05-31 00:11:14 +02:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2011-10-10 23:18:48 +02:00
|
|
|
*/
|
|
|
|
|
2010-12-10 01:53:27 -04:30
|
|
|
App::uses('PluginShortRoute', 'Routing/Route');
|
|
|
|
App::uses('Router', 'Routing');
|
2012-03-12 21:36:27 -04:00
|
|
|
|
2010-05-04 00:35:22 -04:00
|
|
|
/**
|
|
|
|
* test case for PluginShortRoute
|
|
|
|
*
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.Routing.Route
|
2010-05-04 00:35:22 -04:00
|
|
|
*/
|
2012-11-21 15:39:03 +01:00
|
|
|
class PluginShortRouteTest extends CakeTestCase {
|
2012-03-12 21:36:27 -04:00
|
|
|
|
2010-05-04 00:35:22 -04:00
|
|
|
/**
|
2010-09-25 21:36:49 -04:00
|
|
|
* setUp method
|
2010-05-04 00:35:22 -04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function setUp() {
|
2010-09-25 21:36:49 -04:00
|
|
|
parent::setUp();
|
2010-05-04 00:35:22 -04:00
|
|
|
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
|
|
|
|
Router::reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the parsing of routes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testParsing() {
|
2010-05-04 00:35:22 -04:00
|
|
|
$route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
|
|
|
|
|
|
|
|
$result = $route->parse('/foo');
|
2012-03-22 23:37:12 -07:00
|
|
|
$this->assertEquals('foo', $result['plugin']);
|
|
|
|
$this->assertEquals('foo', $result['controller']);
|
|
|
|
$this->assertEquals('index', $result['action']);
|
2010-05-04 00:35:22 -04:00
|
|
|
|
|
|
|
$result = $route->parse('/wrong');
|
|
|
|
$this->assertFalse($result, 'Wrong plugin name matched %s');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-29 11:05:17 +02:00
|
|
|
* test the reverse routing of the plugin shortcut URLs.
|
2010-05-04 00:35:22 -04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testMatch() {
|
2010-05-04 00:35:22 -04: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-22 23:37:12 -07:00
|
|
|
$this->assertEquals('/foo', $result);
|
2010-05-04 00:35:22 -04:00
|
|
|
}
|
|
|
|
}
|