5 * Contains \Drupal\Tests\Core\UrlTest.
8 namespace Drupal\Tests\Core;
10 use Drupal\Component\Utility\UrlHelper;
11 use Drupal\Core\Access\AccessManagerInterface;
12 use Drupal\Core\DependencyInjection\ContainerBuilder;
13 use Drupal\Core\GeneratedUrl;
14 use Drupal\Core\Routing\RouteMatch;
16 use Drupal\Tests\UnitTestCase;
17 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
18 use Symfony\Component\HttpFoundation\ParameterBag;
19 use Symfony\Component\HttpFoundation\Request;
20 use Symfony\Component\Routing\Exception\InvalidParameterException;
21 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
22 use Symfony\Component\Routing\Route;
25 * @coversDefaultClass \Drupal\Core\Url
28 class UrlTest extends UnitTestCase {
31 * @var \Symfony\Component\DependencyInjection\ContainerInterface
38 * @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
40 protected $urlGenerator;
43 * The path alias manager.
45 * @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
47 protected $pathAliasManager;
52 * @var \Drupal\Tests\Core\Routing\TestRouterInterface|\PHPUnit_Framework_MockObject_MockObject
57 * An array of values to use for the test.
64 * The mocked path validator.
66 * @var \Drupal\Core\Path\PathValidatorInterface|\PHPUnit_Framework_MockObject_MockObject
68 protected $pathValidator;
73 protected function setUp() {
77 $map[] = ['view.frontpage.page_1', [], [], FALSE, '/node'];
78 $map[] = ['node_view', ['node' => '1'], [], FALSE, '/node/1'];
79 $map[] = ['node_edit', ['node' => '2'], [], FALSE, '/node/2/edit'];
83 // Set up one proper alias that can be resolved to a system path.
84 ['node-alias-test', NULL, FALSE, 'node'],
85 // Passing in anything else should return the same string.
86 ['node', NULL, FALSE, 'node'],
87 ['node/1', NULL, FALSE, 'node/1'],
88 ['node/2/edit', NULL, FALSE, 'node/2/edit'],
89 ['non-existent', NULL, FALSE, 'non-existent'],
92 // $this->map has $collect_bubbleable_metadata = FALSE; also generate the
93 // $collect_bubbleable_metadata = TRUE case for ::generateFromRoute().
94 $generate_from_route_map = [];
95 foreach ($this->map as $values) {
96 $generate_from_route_map[] = $values;
97 $generate_from_route_map[] = [$values[0], $values[1], $values[2], TRUE, (new GeneratedUrl())->setGeneratedUrl($values[4])];
99 $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
100 $this->urlGenerator->expects($this->any())
101 ->method('generateFromRoute')
102 ->will($this->returnValueMap($generate_from_route_map));
104 $this->pathAliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
105 $this->pathAliasManager->expects($this->any())
106 ->method('getPathByAlias')
107 ->will($this->returnValueMap($alias_map));
109 $this->router = $this->getMock('Drupal\Tests\Core\Routing\TestRouterInterface');
110 $this->pathValidator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');
112 $this->container = new ContainerBuilder();
113 $this->container->set('router.no_access_checks', $this->router);
114 $this->container->set('url_generator', $this->urlGenerator);
115 $this->container->set('path.alias_manager', $this->pathAliasManager);
116 $this->container->set('path.validator', $this->pathValidator);
117 \Drupal::setContainer($this->container);
121 * Tests creating a Url from a request.
123 public function testUrlFromRequest() {
124 $this->router->expects($this->at(0))
125 ->method('matchRequest')
126 ->with($this->getRequestConstraint('/node'))
128 RouteObjectInterface::ROUTE_NAME => 'view.frontpage.page_1',
129 '_raw_variables' => new ParameterBag(),
131 $this->router->expects($this->at(1))
132 ->method('matchRequest')
133 ->with($this->getRequestConstraint('/node/1'))
135 RouteObjectInterface::ROUTE_NAME => 'node_view',
136 '_raw_variables' => new ParameterBag(['node' => '1']),
138 $this->router->expects($this->at(2))
139 ->method('matchRequest')
140 ->with($this->getRequestConstraint('/node/2/edit'))
142 RouteObjectInterface::ROUTE_NAME => 'node_edit',
143 '_raw_variables' => new ParameterBag(['node' => '2']),
147 foreach ($this->map as $index => $values) {
148 $path = array_pop($values);
149 $url = Url::createFromRequest(Request::create("$path"));
150 $expected = Url::fromRoute($values[0], $values[1], $values[2]);
151 $this->assertEquals($expected, $url);
152 $urls[$index] = $url;
158 * This constraint checks whether a Request object has the right path.
160 * @param string $path
163 * @return \PHPUnit_Framework_Constraint_Callback
164 * The constraint checks whether a Request object has the right path.
166 protected function getRequestConstraint($path) {
167 return $this->callback(function (Request $request) use ($path) {
168 return $request->getPathInfo() == $path;
173 * Tests the fromRoute() method with the special <front> path.
175 * @covers ::fromRoute
177 public function testFromRouteFront() {
178 $url = Url::fromRoute('<front>');
179 $this->assertSame('<front>', $url->getRouteName());
183 * Tests the fromUserInput method with valid paths.
185 * @covers ::fromUserInput
186 * @dataProvider providerFromValidInternalUri
188 public function testFromUserInput($path) {
189 $url = Url::fromUserInput($path);
190 $uri = $url->getUri();
192 $this->assertInstanceOf('Drupal\Core\Url', $url);
193 $this->assertFalse($url->isRouted());
194 $this->assertEquals(0, strpos($uri, 'base:'));
196 $parts = UrlHelper::parse($path);
197 $options = $url->getOptions();
199 if (!empty($parts['fragment'])) {
200 $this->assertSame($parts['fragment'], $options['fragment']);
203 $this->assertArrayNotHasKey('fragment', $options);
206 if (!empty($parts['query'])) {
207 $this->assertEquals($parts['query'], $options['query']);
210 $this->assertArrayNotHasKey('query', $options);
215 * Tests the fromUserInput method with invalid paths.
217 * @covers ::fromUserInput
218 * @dataProvider providerFromInvalidInternalUri
220 public function testFromInvalidUserInput($path) {
221 $this->setExpectedException(\InvalidArgumentException::class);
222 $url = Url::fromUserInput($path);
226 * Tests fromUri() method with a user-entered path not matching any route.
230 public function testFromRoutedPathWithInvalidRoute() {
231 $this->pathValidator->expects($this->once())
232 ->method('getUrlIfValidWithoutAccessCheck')
233 ->with('invalid-path')
235 $url = Url::fromUri('internal:/invalid-path');
236 $this->assertSame(FALSE, $url->isRouted());
237 $this->assertSame('base:invalid-path', $url->getUri());
241 * Tests fromUri() method with user-entered path matching a valid route.
245 public function testFromRoutedPathWithValidRoute() {
246 $url = Url::fromRoute('test_route');
247 $this->pathValidator->expects($this->once())
248 ->method('getUrlIfValidWithoutAccessCheck')
251 $result_url = Url::fromUri('internal:/valid-path');
252 $this->assertSame($url, $result_url);
256 * Tests the createFromRequest method.
258 * @covers ::createFromRequest
260 public function testCreateFromRequest() {
262 '_raw_variables' => new ParameterBag([
263 'color' => 'chartreuse',
265 RouteObjectInterface::ROUTE_NAME => 'the_route_name',
267 $request = new Request([], [], $attributes);
269 $this->router->expects($this->once())
270 ->method('matchRequest')
272 ->will($this->returnValue($attributes));
274 $url = Url::createFromRequest($request);
275 $expected = new Url('the_route_name', ['color' => 'chartreuse']);
276 $this->assertEquals($expected, $url);
280 * Tests that an invalid request will thrown an exception.
282 * @covers ::createFromRequest
284 public function testUrlFromRequestInvalid() {
285 $request = Request::create('/test-path');
287 $this->router->expects($this->once())
288 ->method('matchRequest')
290 ->will($this->throwException(new ResourceNotFoundException()));
292 $this->setExpectedException(ResourceNotFoundException::class);
293 Url::createFromRequest($request);
297 * Tests the isExternal() method.
299 * @depends testUrlFromRequest
301 * @covers ::isExternal
303 public function testIsExternal($urls) {
304 foreach ($urls as $url) {
305 $this->assertFalse($url->isExternal());
310 * Tests the getUri() method for internal URLs.
312 * @param \Drupal\Core\Url[] $urls
313 * Array of URL objects.
315 * @depends testUrlFromRequest
319 public function testGetUriForInternalUrl($urls) {
320 $this->setExpectedException(\UnexpectedValueException::class);
321 foreach ($urls as $url) {
327 * Tests the getUri() method for external URLs.
331 public function testGetUriForExternalUrl() {
332 $url = Url::fromUri('http://example.com/test');
333 $this->assertEquals('http://example.com/test', $url->getUri());
337 * Tests the getUri() and isExternal() methods for protocol-relative URLs.
340 * @covers ::isExternal
342 public function testGetUriForProtocolRelativeUrl() {
343 $url = Url::fromUri('//example.com/test');
344 $this->assertEquals('//example.com/test', $url->getUri());
345 $this->assertTrue($url->isExternal());
349 * Tests the getInternalPath method().
351 * @param \Drupal\Core\Url[] $urls
352 * Array of URL objects.
354 * @covers ::getInternalPath
356 * @depends testUrlFromRequest
358 public function testGetInternalPath($urls) {
360 $map[] = ['view.frontpage.page_1', [], '/node'];
361 $map[] = ['node_view', ['node' => '1'], '/node/1'];
362 $map[] = ['node_edit', ['node' => '2'], '/node/2/edit'];
364 foreach ($urls as $index => $url) {
365 // Clone the url so that there is no leak of internal state into the
368 $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
369 $url_generator->expects($this->once())
370 ->method('getPathFromRoute')
371 ->will($this->returnValueMap($map, $index));
372 $url->setUrlGenerator($url_generator);
374 $url->getInternalPath();
375 $url->getInternalPath();
380 * Tests the toString() method.
382 * @param \Drupal\Core\Url[] $urls
383 * An array of Url objects.
385 * @depends testUrlFromRequest
389 public function testToString($urls) {
390 foreach ($urls as $index => $url) {
391 $path = array_pop($this->map[$index]);
392 $this->assertSame($path, $url->toString());
393 $generated_url = $url->toString(TRUE);
394 $this->assertSame($path, $generated_url->getGeneratedUrl());
395 $this->assertInstanceOf('\Drupal\Core\Render\BubbleableMetadata', $generated_url);
400 * Tests the getRouteName() method.
402 * @param \Drupal\Core\Url[] $urls
403 * An array of Url objects.
405 * @depends testUrlFromRequest
407 * @covers ::getRouteName
409 public function testGetRouteName($urls) {
410 foreach ($urls as $index => $url) {
411 $this->assertSame($this->map[$index][0], $url->getRouteName());
416 * Tests the getRouteName() with an external URL.
418 * @covers ::getRouteName
420 public function testGetRouteNameWithExternalUrl() {
421 $url = Url::fromUri('http://example.com');
422 $this->setExpectedException(\UnexpectedValueException::class);
423 $url->getRouteName();
427 * Tests the getRouteParameters() method.
429 * @param \Drupal\Core\Url[] $urls
430 * An array of Url objects.
432 * @depends testUrlFromRequest
434 * @covers ::getRouteParameters
436 public function testGetRouteParameters($urls) {
437 foreach ($urls as $index => $url) {
438 $this->assertSame($this->map[$index][1], $url->getRouteParameters());
443 * Tests the getRouteParameters() with an external URL.
445 * @covers ::getRouteParameters
447 public function testGetRouteParametersWithExternalUrl() {
448 $url = Url::fromUri('http://example.com');
449 $this->setExpectedException(\UnexpectedValueException::class);
450 $url->getRouteParameters();
454 * Tests the getOptions() method.
456 * @param \Drupal\Core\Url[] $urls
457 * An array of Url objects.
459 * @depends testUrlFromRequest
461 * @covers ::getOptions
463 public function testGetOptions($urls) {
464 foreach ($urls as $index => $url) {
465 $this->assertSame($this->map[$index][2], $url->getOptions());
470 * Tests the setOptions() method.
472 * @covers ::setOptions
474 public function testSetOptions() {
475 $url = Url::fromRoute('test_route', []);
476 $this->assertEquals([], $url->getOptions());
477 $url->setOptions(['foo' => 'bar']);
478 $this->assertEquals(['foo' => 'bar'], $url->getOptions());
479 $url->setOptions([]);
480 $this->assertEquals([], $url->getOptions());
484 * Tests the mergeOptions() method.
486 * @covers ::mergeOptions
488 public function testMergeOptions() {
489 $url = Url::fromRoute('test_route', [], ['foo' => 'bar', 'bar' => ['key' => 'value']]);
490 $url->mergeOptions(['bar' => ['key' => 'value1', 'key2' => 'value2']]);
491 $this->assertEquals(['foo' => 'bar', 'bar' => ['key' => 'value1', 'key2' => 'value2']], $url->getOptions());
495 * Tests the access() method for routed URLs.
497 * @param bool $access
500 * @covers ::accessManager
501 * @dataProvider accessProvider
503 public function testAccessRouted($access) {
504 $account = $this->getMock('Drupal\Core\Session\AccountInterface');
505 $url = new TestUrl('entity.node.canonical', ['node' => 3]);
506 $url->setAccessManager($this->getMockAccessManager($access, $account));
507 $this->assertEquals($access, $url->access($account));
511 * Tests the access() method for unrouted URLs (they always have access).
515 public function testAccessUnrouted() {
516 $account = $this->getMock('Drupal\Core\Session\AccountInterface');
517 $url = TestUrl::fromUri('base:kittens');
518 $access_manager = $this->getMock('Drupal\Core\Access\AccessManagerInterface');
519 $access_manager->expects($this->never())
520 ->method('checkNamedRoute');
521 $url->setAccessManager($access_manager);
522 $this->assertTrue($url->access($account));
526 * Tests the renderAccess() method.
528 * @param bool $access
530 * @covers ::renderAccess
531 * @dataProvider accessProvider
533 public function testRenderAccess($access) {
535 '#url' => Url::fromRoute('entity.node.canonical', ['node' => 3]),
537 $this->container->set('current_user', $this->getMock('Drupal\Core\Session\AccountInterface'));
538 $this->container->set('access_manager', $this->getMockAccessManager($access));
539 $this->assertEquals($access, TestUrl::renderAccess($element));
543 * Tests the fromRouteMatch() method.
545 public function testFromRouteMatch() {
546 $route = new Route('/test-route/{foo}');
547 $route_match = new RouteMatch('test_route', $route, ['foo' => (object) [1]], ['foo' => 1]);
548 $url = Url::fromRouteMatch($route_match);
549 $this->assertSame('test_route', $url->getRouteName());
550 $this->assertEquals(['foo' => '1'], $url->getRouteParameters());
554 * Data provider for testing entity URIs
556 public function providerTestEntityUris() {
559 'entity:test_entity/1',
561 'entity.test_entity.canonical',
562 ['test_entity' => '1'],
567 // Ensure a fragment of #0 is handled correctly.
568 'entity:test_entity/1#0',
570 'entity.test_entity.canonical',
571 ['test_entity' => '1'],
575 // Ensure an empty fragment of # is in options discarded as expected.
577 'entity:test_entity/1',
579 'entity.test_entity.canonical',
580 ['test_entity' => '1'],
584 // Ensure an empty fragment of # in the URI is discarded as expected.
586 'entity:test_entity/1#',
588 'entity.test_entity.canonical',
589 ['test_entity' => '1'],
594 'entity:test_entity/2?page=1&foo=bar#bottom',
595 [], 'entity.test_entity.canonical',
596 ['test_entity' => '2'],
597 ['page' => '1', 'foo' => 'bar'],
601 'entity:test_entity/2?page=1&foo=bar#bottom',
602 ['fragment' => 'top', 'query' => ['foo' => 'yes', 'focus' => 'no']],
603 'entity.test_entity.canonical',
604 ['test_entity' => '2'],
605 ['page' => '1', 'foo' => 'yes', 'focus' => 'no'],
613 * Tests the fromUri() method with an entity: URI.
617 * @dataProvider providerTestEntityUris
619 public function testEntityUris($uri, $options, $route_name, $route_parameters, $query, $fragment) {
620 $url = Url::fromUri($uri, $options);
621 $this->assertSame($route_name, $url->getRouteName());
622 $this->assertEquals($route_parameters, $url->getRouteParameters());
623 $this->assertEquals($url->getOption('query'), $query);
624 $this->assertSame($url->getOption('fragment'), $fragment);
628 * Tests the fromUri() method with an invalid entity: URI.
632 public function testInvalidEntityUriParameter() {
633 // Make the mocked URL generator behave like the actual one.
634 $this->urlGenerator->expects($this->once())
635 ->method('generateFromRoute')
636 ->with('entity.test_entity.canonical', ['test_entity' => '1/blah'])
637 ->willThrowException(new InvalidParameterException('Parameter "test_entity" for route "/test_entity/{test_entity}" must match "[^/]++" ("1/blah" given) to generate a corresponding URL..'));
639 $this->setExpectedException(InvalidParameterException::class);
640 Url::fromUri('entity:test_entity/1/blah')->toString();
644 * Tests the toUriString() method with entity: URIs.
646 * @covers ::toUriString
648 * @dataProvider providerTestToUriStringForEntity
650 public function testToUriStringForEntity($uri, $options, $uri_string) {
651 $url = Url::fromUri($uri, $options);
652 $this->assertSame($url->toUriString(), $uri_string);
656 * Data provider for testing string entity URIs
658 public function providerTestToUriStringForEntity() {
660 ['entity:test_entity/1', [], 'route:entity.test_entity.canonical;test_entity=1'],
661 ['entity:test_entity/1', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'],
662 ['entity:test_entity/1?page=2#top', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'],
667 * Tests the toUriString() method with internal: URIs.
669 * @covers ::toUriString
671 * @dataProvider providerTestToUriStringForInternal
673 public function testToUriStringForInternal($uri, $options, $uri_string) {
674 $url = Url::fromRoute('entity.test_entity.canonical', ['test_entity' => '1']);
675 $this->pathValidator->expects($this->any())
676 ->method('getUrlIfValidWithoutAccessCheck')
678 ['test-entity/1', $url],
679 ['<front>', Url::fromRoute('<front>')],
680 ['<none>', Url::fromRoute('<none>')],
682 $url = Url::fromUri($uri, $options);
683 $this->assertSame($url->toUriString(), $uri_string);
687 * Data provider for testing internal URIs.
689 public function providerTestToUriStringForInternal() {
691 // The four permutations of a regular path.
692 ['internal:/test-entity/1', [], 'route:entity.test_entity.canonical;test_entity=1'],
693 ['internal:/test-entity/1', ['fragment' => 'top'], 'route:entity.test_entity.canonical;test_entity=1#top'],
694 ['internal:/test-entity/1', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'],
695 ['internal:/test-entity/1?page=2#top', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'],
697 // The four permutations of the special '<front>' path.
698 ['internal:/', [], 'route:<front>'],
699 ['internal:/', ['fragment' => 'top'], 'route:<front>#top'],
700 ['internal:/', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:<front>?page=2#top'],
701 ['internal:/?page=2#top', [], 'route:<front>?page=2#top'],
703 // The four permutations of the special '<none>' path.
704 ['internal:', [], 'route:<none>'],
705 ['internal:', ['fragment' => 'top'], 'route:<none>#top'],
706 ['internal:', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:<none>?page=2#top'],
707 ['internal:?page=2#top', [], 'route:<none>?page=2#top'],
712 * Tests the fromUri() method with a valid internal: URI.
715 * @dataProvider providerFromValidInternalUri
717 public function testFromValidInternalUri($path) {
718 $url = Url::fromUri('internal:' . $path);
719 $this->assertInstanceOf('Drupal\Core\Url', $url);
723 * Data provider for testFromValidInternalUri().
725 public function providerFromValidInternalUri() {
727 // Normal paths with a leading slash.
730 // Fragments with and without leading slashes.
731 ['/#about-our-kittens'],
732 ['/kittens#feeding'],
734 // Query strings with and without leading slashes.
735 ['/kittens?page=1000'],
738 ['?breed=bengal&page=1000'],
739 ['?referrer=https://kittenfacts'],
740 // Paths with various token formats but no leading slash.
744 // Disallowed characters in the authority (host name) that are valid
745 // elsewhere in the path.
752 * Tests the fromUri() method with an invalid internal: URI.
755 * @dataProvider providerFromInvalidInternalUri
757 public function testFromInvalidInternalUri($path) {
758 $this->setExpectedException(\InvalidArgumentException::class);
759 Url::fromUri('internal:' . $path);
763 * Data provider for testFromInvalidInternalUri().
765 public function providerFromInvalidInternalUri() {
767 // Normal paths without a leading slash.
768 'normal_path0' => ['kittens'],
769 'normal_path1' => ['kittens/bengal'],
770 // Path without a leading slash containing a fragment.
771 'fragment' => ['kittens#feeding'],
772 // Path without a leading slash containing a query string.
773 'without_leading_slash_query' => ['kittens?page=1000'],
774 // Paths with various token formats but no leading slash.
775 'path_with_tokens0' => ['[duckies]'],
776 'path_with_tokens1' => ['%bunnies'],
777 'path_with_tokens2' => ['{{ puppies }}'],
778 // Disallowed characters in the authority (host name) that are valid
779 // elsewhere in the path.
780 'disallowed_hostname_chars0' => ['(:;2&+h^'],
781 'disallowed_hostname_chars1' => ['AKI@&hO@'],
782 // Leading slash with a domain.
783 'leading_slash_with_domain' => ['/http://example.com'],
788 * Tests the fromUri() method with a base: URI starting with a number.
792 public function testFromUriNumber() {
793 $url = Url::fromUri('base:2015/10/06');
794 $this->assertSame($url->toUriString(), 'base:/2015/10/06');
798 * Tests the toUriString() method with route: URIs.
800 * @covers ::toUriString
802 * @dataProvider providerTestToUriStringForRoute
804 public function testToUriStringForRoute($uri, $options, $uri_string) {
805 $url = Url::fromUri($uri, $options);
806 $this->assertSame($url->toUriString(), $uri_string);
810 * Data provider for testing route: URIs.
812 public function providerTestToUriStringForRoute() {
814 ['route:entity.test_entity.canonical;test_entity=1', [], 'route:entity.test_entity.canonical;test_entity=1'],
815 ['route:entity.test_entity.canonical;test_entity=1', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'],
816 ['route:entity.test_entity.canonical;test_entity=1?page=2#top', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'],
817 // Check that an empty fragment is discarded.
818 ['route:entity.test_entity.canonical;test_entity=1?page=2#', [], 'route:entity.test_entity.canonical;test_entity=1?page=2'],
819 // Check that an empty fragment is discarded.
820 ['route:entity.test_entity.canonical;test_entity=1?page=2', ['fragment' => ''], 'route:entity.test_entity.canonical;test_entity=1?page=2'],
821 // Check that a fragment of #0 is preserved.
822 ['route:entity.test_entity.canonical;test_entity=1?page=2#0', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#0'],
829 public function testFromRouteUriWithMissingRouteName() {
830 $this->setExpectedException(\InvalidArgumentException::class, "The route URI 'route:' is invalid.");
831 Url::fromUri('route:');
835 * Creates a mock access manager for the access tests.
837 * @param bool $access
838 * @param \Drupal\Core\Session\AccountInterface|null $account
840 * @return \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject
842 protected function getMockAccessManager($access, $account = NULL) {
843 $access_manager = $this->getMock('Drupal\Core\Access\AccessManagerInterface');
844 $access_manager->expects($this->once())
845 ->method('checkNamedRoute')
846 ->with('entity.node.canonical', ['node' => 3], $account)
847 ->willReturn($access);
848 return $access_manager;
852 * Data provider for the access test methods.
854 public function accessProvider() {
863 class TestUrl extends Url {
866 * Sets the access manager.
868 * @param \Drupal\Core\Access\AccessManagerInterface $access_manager
870 public function setAccessManager(AccessManagerInterface $access_manager) {
871 $this->accessManager = $access_manager;