Commit c4273308 authored by catch's avatar catch
Browse files

Issue #2045453 by pwolanin, tim.plunkett, dawehner: Fixed...

Issue #2045453 by pwolanin, tim.plunkett, dawehner: Fixed menu_item_route_access() does not catch ResourceNotFoundException.
parent 42fcb356
......@@ -963,6 +963,9 @@ function _menu_link_translate(&$item, $translate = FALSE) {
* @return bool
* TRUE if the user has access or FALSE if the user should be presented
* with access denied.
*
* @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException
* If the system path in $href does not match the $route.
*/
function menu_item_route_access(Route $route, $href, &$map) {
$request = Request::create('/' . $href);
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Routing;
use Drupal\Component\Utility\String;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\RouteCollection;
......@@ -99,7 +100,7 @@ public function getRouteCollectionForRequest(Request $request) {
$collection = $this->getRoutesByPath($path);
if (!count($collection)) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(String::format("The route for '@path' could not be found", array('@path' => $path)));
}
return $collection;
......
......@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Routing;
use Drupal\simpletest\WebTestBase;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
/**
* Basic tests for access permissions in routes.
......@@ -33,8 +34,20 @@ public static function getInfo() {
* Tests permission requirements on routes.
*/
public function testPermissionAccess() {
$this->drupalGet('router_test/test7');
$path = 'router_test/test7';
$this->drupalGet($path);
$this->assertResponse(403, "Access denied for a route where we don't have a permission");
// An invalid path should throw an exception.
$map = array();
$route = \Drupal::service('router.route_provider')->getRouteByName('router_test_7');
try {
menu_item_route_access($route, $path . 'invalid', $map);
$exception = FALSE;
}
catch (ResourceNotFoundException $e) {
$exception = TRUE;
}
$this->assertTrue($exception, 'A ResourceNotFoundException was thrown while checking access for an invalid route.');
$this->drupalGet('router_test/test8');
$this->assertResponse(403, 'Access denied by default if no access specified');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment