diff --git a/core/lib/Drupal/Core/Path/PathValidator.php b/core/lib/Drupal/Core/Path/PathValidator.php index 689625c..1634b4e 100644 --- a/core/lib/Drupal/Core/Path/PathValidator.php +++ b/core/lib/Drupal/Core/Path/PathValidator.php @@ -16,6 +16,7 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Matcher\UrlMatcherInterface; @@ -170,6 +171,9 @@ protected function getPathAttributes($path, Request $request, $access_check) { catch (AccessDeniedHttpException $e) { return FALSE; } + catch (MethodNotAllowedException $e) { + return FALSE; + } } } diff --git a/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php b/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php index b0acb12..e0b7ccd 100644 --- a/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php @@ -13,6 +13,7 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; /** @@ -106,6 +107,8 @@ public function testIsValidWithExternalUrl() { /** * Tests the isValid() method with an invalid external URL. + * + * @covers ::isValid */ public function testIsValidWithInvalidExternalUrl() { $this->accessAwareRouter->expects($this->never()) @@ -118,6 +121,7 @@ public function testIsValidWithInvalidExternalUrl() { * Tests the isValid() method with a 'link to any page' permission. * * @covers ::isValid + * @covers ::getPathAttributes */ public function testIsValidWithLinkToAnyPageAccount() { $this->account->expects($this->once()) @@ -189,6 +193,7 @@ public function testIsValidWithPathAlias() { * Tests the isValid() method with a user without access to the path. * * @covers ::isValid + * @covers ::getPathAttributes */ public function testIsValidWithAccessDenied() { $this->account->expects($this->once()) @@ -209,6 +214,72 @@ public function testIsValidWithAccessDenied() { } /** + * @covers ::isValid + * @covers ::getPathAttributes + */ + public function testIsValidWithResourceNotFound() { + $this->account->expects($this->once()) + ->method('hasPermission') + ->with('link to any page') + ->willReturn(FALSE); + $this->accessUnawareRouter->expects($this->never()) + ->method('match'); + $this->accessAwareRouter->expects($this->once()) + ->method('match') + ->with('/test-path') + ->willThrowException(new ResourceNotFoundException()); + $this->pathProcessor->expects($this->once()) + ->method('processInbound') + ->willReturnArgument(0); + + $this->assertFalse($this->pathValidator->isValid('test-path')); + } + + /** + * @covers ::isValid + * @covers ::getPathAttributes + */ + public function testIsValidWithParamNotConverted() { + $this->account->expects($this->once()) + ->method('hasPermission') + ->with('link to any page') + ->willReturn(FALSE); + $this->accessUnawareRouter->expects($this->never()) + ->method('match'); + $this->accessAwareRouter->expects($this->once()) + ->method('match') + ->with('/test-path') + ->willThrowException(new ParamNotConvertedException()); + $this->pathProcessor->expects($this->once()) + ->method('processInbound') + ->willReturnArgument(0); + + $this->assertFalse($this->pathValidator->isValid('test-path')); + } + + /** + * @covers ::isValid + * @covers ::getPathAttributes + */ + public function testIsValidWithMethodNotAllowed() { + $this->account->expects($this->once()) + ->method('hasPermission') + ->with('link to any page') + ->willReturn(FALSE); + $this->accessUnawareRouter->expects($this->never()) + ->method('match'); + $this->accessAwareRouter->expects($this->once()) + ->method('match') + ->with('/test-path') + ->willThrowException(new MethodNotAllowedException([])); + $this->pathProcessor->expects($this->once()) + ->method('processInbound') + ->willReturnArgument(0); + + $this->assertFalse($this->pathValidator->isValid('test-path')); + } + + /** * Tests the isValid() method with a not working param converting. * * @covers ::isValid @@ -256,6 +327,9 @@ public function testIsValidWithNotExistingPath() { /** * Tests the getUrlIfValid() method when there is access. + * + * @covers ::getUrlIfValid + * @covers ::getPathAttributes */ public function testGetUrlIfValidWithAccess() { $this->account->expects($this->exactly(2)) @@ -287,6 +361,8 @@ public function testGetUrlIfValidWithAccess() { /** * Tests the getUrlIfValid() method with a query in the path. + * + * @covers ::getUrlIfValid */ public function testGetUrlIfValidWithQuery() { $this->account->expects($this->once()) @@ -311,6 +387,8 @@ public function testGetUrlIfValidWithQuery() { /** * Tests the getUrlIfValid() method where there is no access. + * + * @covers ::getUrlIfValid */ public function testGetUrlIfValidWithoutAccess() { $this->account->expects($this->once()) @@ -333,6 +411,8 @@ public function testGetUrlIfValidWithoutAccess() { /** * Tests the getUrlIfValid() method with a front page + query + fragments. + * + * @covers ::getUrlIfValid */ public function testGetUrlIfValidWithFrontPageAndQueryAndFragments() { $url = $this->pathValidator->getUrlIfValid('?hei=sen#berg'); @@ -345,6 +425,7 @@ public function testGetUrlIfValidWithFrontPageAndQueryAndFragments() { * Tests the getUrlIfValidWithoutAccessCheck() method. * * @covers ::getUrlIfValidWithoutAccessCheck + * @covers ::getPathAttributes */ public function testGetUrlIfValidWithoutAccessCheck() { $this->account->expects($this->never())