/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $map = array(); $map[] = array('view.frontpage.page_1', array(), array(), FALSE, '/node'); $map[] = array('node_view', array('node' => '1'), array(), FALSE, '/node/1'); $map[] = array('node_edit', array('node' => '2'), array(), FALSE, '/node/2/edit'); $this->map = $map; $alias_map = array(array('node-alias-test', NULL, FALSE, 'node'), array('node', NULL, FALSE, 'node'), array('node/1', NULL, FALSE, 'node/1'), array('node/2/edit', NULL, FALSE, 'node/2/edit'), array('non-existent', NULL, FALSE, 'non-existent')); // $this->map has $collect_bubbleable_metadata = FALSE; also generate the // $collect_bubbleable_metadata = TRUE case for ::generateFromRoute(). $generate_from_route_map = []; foreach ($this->map as $values) { $generate_from_route_map[] = $values; $generate_from_route_map[] = [$values[0], $values[1], $values[2], TRUE, (new GeneratedUrl())->setGeneratedUrl($values[4])]; } $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface'); $this->urlGenerator->expects($this->any())->method('generateFromRoute')->will($this->returnValueMap($generate_from_route_map)); $this->pathAliasManager = $this->getMock('Drupal\\Core\\Path\\AliasManagerInterface'); $this->pathAliasManager->expects($this->any())->method('getPathByAlias')->will($this->returnValueMap($alias_map)); $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface'); $this->pathValidator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface'); $this->container = new ContainerBuilder(); $this->container->set('router.no_access_checks', $this->router); $this->container->set('url_generator', $this->urlGenerator); $this->container->set('path.alias_manager', $this->pathAliasManager); $this->container->set('path.validator', $this->pathValidator); \Drupal::setContainer($this->container); }
/** * Tests the processOutbound method. * * @see \Drupal\Core\PathProcessor\PathProcessorAlias::processOutbound */ public function testProcessOutbound() { $this->aliasManager->expects($this->exactly(2))->method('getAliasByPath')->will($this->returnValueMap(array(array('internal-url', NULL, 'urlalias'), array('url', NULL, 'url')))); $this->assertEquals('urlalias', $this->pathProcessor->processOutbound('internal-url')); $options = array('alias' => TRUE); $this->assertEquals('internal-url', $this->pathProcessor->processOutbound('internal-url', $options)); $this->assertEquals('url', $this->pathProcessor->processOutbound('url')); }
/** * @covers ::processOutbound * * @dataProvider providerTestProcessOutbound */ public function testProcessOutbound($path, array $options, $expected_path) { $this->aliasManager->expects($this->any())->method('getAliasByPath')->will($this->returnValueMap(array(array('internal-url', NULL, 'urlalias'), array('url', NULL, 'url')))); $bubbleable_metadata = new BubbleableMetadata(); $this->assertEquals($expected_path, $this->pathProcessor->processOutbound($path, $options, NULL, $bubbleable_metadata)); // Cacheability of paths replaced with path aliases is permanent. // @todo https://www.drupal.org/node/2480077 $this->assertEquals((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT), $bubbleable_metadata); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $map = array(); $map[] = array('view.frontpage.page_1', array(), array(), '/node'); $map[] = array('node_view', array('node' => '1'), array(), '/node/1'); $map[] = array('node_edit', array('node' => '2'), array(), '/node/2/edit'); $this->map = $map; $alias_map = array(array('node-alias-test', NULL, 'node'), array('node', NULL, 'node'), array('node/1', NULL, 'node/1'), array('node/2/edit', NULL, 'node/2/edit'), array('non-existent', NULL, 'non-existent')); $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface'); $this->urlGenerator->expects($this->any())->method('generateFromRoute')->will($this->returnValueMap($this->map)); $this->pathAliasManager = $this->getMock('Drupal\\Core\\Path\\AliasManagerInterface'); $this->pathAliasManager->expects($this->any())->method('getPathByAlias')->will($this->returnValueMap($alias_map)); $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface'); $this->pathValidator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface'); $this->container = new ContainerBuilder(); $this->container->set('router.no_access_checks', $this->router); $this->container->set('url_generator', $this->urlGenerator); $this->container->set('path.alias_manager', $this->pathAliasManager); $this->container->set('path.validator', $this->pathValidator); \Drupal::setContainer($this->container); }
/** * Sets up an alias manager that does nothing. */ protected function setupStubAliasManager() { $this->aliasManager->expects($this->any())->method('getPathByAlias')->willReturnArgument(0); }