Skip to content

Commit

Permalink
Fix scopes with actions not working.
Browse files Browse the repository at this point in the history
Scopes that define an action other than `index` should be able to
connect routes.

Fixes #12535
  • Loading branch information
markstory committed Sep 7, 2018
1 parent fc95e24 commit 1585d0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Routing/RouteBuilder.php
Expand Up @@ -724,14 +724,9 @@ public function loadPlugin($name, $file = 'routes.php')
public function connect($route, $defaults = [], array $options = [])
{
$defaults = $this->parseDefaults($defaults);
if (!isset($options['action']) && !isset($defaults['action'])) {
$defaults['action'] = 'index';
}

if (empty($options['_ext'])) {
$options['_ext'] = $this->_extensions;
}

if (empty($options['routeClass'])) {
$options['routeClass'] = $this->_routeClass;
}
Expand Down Expand Up @@ -823,6 +818,9 @@ protected function _makeRoute($route, $defaults, $options)
}
}
$defaults += $this->_params + ['plugin' => null];
if (!isset($defaults['action']) && !isset($options['action'])) {
$defaults['action'] = 'index';
}

$route = new $routeClass($route, $defaults, $options);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/TestCase/Routing/RouteBuilderTest.php
Expand Up @@ -940,6 +940,27 @@ public function testScope()
});
}

/**
* Test adding a scope with action in the scope
*
* @return void
*/
public function testScopeWithAction()
{
$routes = new RouteBuilder($this->collection, '/api', ['prefix' => 'api']);
$routes->scope('/prices', ['controller' => 'Prices', 'action' => 'view'], function ($routes) {
$routes->connect('/shared', ['shared' => true]);
$routes->get('/exclusive', ['exclusive' => true]);
});
$all = $this->collection->routes();
$this->assertCount(2, $all);
$this->assertSame('view', $all[0]->defaults['action']);
$this->assertArrayHasKey('shared', $all[0]->defaults);

$this->assertSame('view', $all[1]->defaults['action']);
$this->assertArrayHasKey('exclusive', $all[1]->defaults);
}

/**
* Test that nested scopes inherit middleware.
*
Expand Down

0 comments on commit 1585d0e

Please sign in to comment.