Skip to content
Permalink
Browse files

Router::parseExtensions() only works at the top of the routes.

The global methods still mostly work like before, but with limitations.
Router::parseExtensions() now should only be used at the top of the
routes file. After that, extensions() should be set on the individual
scopes.
  • Loading branch information...
markstory committed Jun 27, 2014
1 parent 42fb1a4 commit e05a9672f498eebcbf32cfac6c3661f8a7e7c822
Showing with 9 additions and 16 deletions.
  1. +5 −2 src/Routing/Router.php
  2. +4 −14 tests/TestCase/Routing/RouterTest.php
@@ -1085,10 +1085,14 @@ public static function parseNamedParams(Request $request, $options = []) {
* If you have no parameters, this argument can be a callable.
* @param callable $callback The callback to invoke with the scoped collection.
* @throws \InvalidArgumentException When an invalid callable is provided.
* @return \Cake\Routing\ScopedRouteCollection The scoped collection that
* @return null|\Cake\Routing\ScopedRouteCollection The scoped collection that
* was created/used.
*/
public static function scope($path, $params = [], $callback = null) {
if ($params === [] && $callback === null && isset(static::$_pathScopes[$path])) {
return static::$_pathScopes[$path];
}
if ($callback === null) {
$callback = $params;
$params = [];
@@ -1107,7 +1111,6 @@ public static function scope($path, $params = [], $callback = null) {
static::$_pathScopes[$path]->merge($collection);
}
static::$_named += $collection->named();
return static::$_pathScopes[$path];
}
/**
@@ -286,11 +286,12 @@ public function testMapResourcesWithPrefix() {
* @return void
*/
public function testMapResourcesWithExtension() {
Router::parseExtensions(['json', 'xml'], false);
$resources = Router::mapResources('Posts', ['_ext' => 'json']);
$this->assertEquals(['posts'], $resources);
$_SERVER['REQUEST_METHOD'] = 'GET';
Router::parseExtensions(['json', 'xml'], false);
$expected = array(
'plugin' => null,
@@ -317,15 +318,14 @@ public function testMapResourcesWithExtension() {
*/
public function testMapResourcesConnectOptions() {
Plugin::load('TestPlugin');
$collection = new RouteCollection();
Router::setRouteCollection($collection);
Router::mapResources('Posts', array(
'connectOptions' => array(
'routeClass' => 'TestPlugin.TestRoute',
'foo' => '^(bar)$',
),
));
$route = $collection->get(0);
$routes = Router::scope('/');
$route = $routes->routes()[0];
$this->assertInstanceOf('TestPlugin\Routing\Route\TestRoute', $route);
$this->assertEquals('^(bar)$', $route->options['foo']);
}
@@ -1632,7 +1632,6 @@ public function testParseExtensions() {
* @return void
*/
public function testSetExtensions() {
Router::extensions();
Router::parseExtensions('rss', false);
$this->assertContains('rss', Router::extensions());
@@ -1645,15 +1644,6 @@ public function testSetExtensions() {
$this->assertFalse(isset($result['_ext']));
Router::parseExtensions(array('xml'));
$result = Router::extensions();
$this->assertContains('rss', $result);
$this->assertContains('xml', $result);
$result = Router::parse('/posts.xml');
$this->assertEquals('xml', $result['_ext']);
$result = Router::parseExtensions(array('pdf'), false);
$this->assertEquals(array('pdf'), $result);
}
/**

0 comments on commit e05a967

Please sign in to comment.
You can’t perform that action at this time.