Skip to content

Commit

Permalink
Add _middleware to parse results.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 16, 2017
1 parent 9d9e566 commit 48b882a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Routing/Route/Route.php
Expand Up @@ -486,6 +486,9 @@ public function parse($url, $method = '')
}
}
$route['_matchedRoute'] = $this->template;
if (count($this->middleware) > 0) {
$route['_middleware'] = $this->middleware;
}

return $route;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -1095,6 +1095,26 @@ public function testParseWithPassDefaults()
$this->assertEquals($expected, $result);
}

/**
* Test that middleware is returned from parse()
*
* @return void
*/
public function testParseWithMiddleware()
{
$route = new Route('/:controller', ['action' => 'display', 'home']);
$route->setMiddleware(['auth', 'cookie']);
$result = $route->parse('/posts', 'GET');
$expected = [
'controller' => 'posts',
'action' => 'display',
'pass' => ['home'],
'_matchedRoute' => '/:controller',
'_middleware' => ['auth', 'cookie'],
];
$this->assertEquals($expected, $result);
}

/**
* Test that http header conditions can cause route failures.
*
Expand Down

0 comments on commit 48b882a

Please sign in to comment.