/**
  * Tests the getUrlIfValid() method where there is no access.
  */
 public function testGetUrlIfValidWithoutAccess()
 {
     $this->account->expects($this->once())->method('hasPermission')->with('link to any page')->willReturn(FALSE);
     $this->accessAwareRouter->expects($this->once())->method('match')->with('/test-path')->willThrowException(new AccessDeniedHttpException());
     $this->pathProcessor->expects($this->once())->method('processInbound')->willReturnArgument(0);
     $url = $this->pathValidator->getUrlIfValid('test-path');
     $this->assertFalse($url);
 }
示例#2
0
 /**
  * Tests the getUrlIfValidWithoutAccessCheck() method.
  *
  * @covers ::getUrlIfValidWithoutAccessCheck
  */
 public function testGetUrlIfValidWithoutAccessCheck()
 {
     $this->account->expects($this->never())->method('hasPermission')->with('link to any page');
     $this->accessAwareRouter->expects($this->never())->method('match');
     $this->accessUnawareRouter->expects($this->once())->method('match')->with('/test-path')->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new ParameterBag(['key' => 'value'])]);
     $this->pathProcessor->expects($this->once())->method('processInbound')->willReturnArgument(0);
     $url = $this->pathValidator->getUrlIfValidWithoutAccessCheck('test-path');
     $this->assertInstanceOf('Drupal\\Core\\Url', $url);
     $this->assertEquals('test_route', $url->getRouteName());
     $this->assertEquals(['key' => 'value'], $url->getRouteParameters());
 }