3 namespace Drupal\Tests\Core\PathProcessor;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\PathProcessor\PathProcessorAlias;
7 use Drupal\Core\Render\BubbleableMetadata;
8 use Drupal\Tests\UnitTestCase;
9 use Symfony\Component\HttpFoundation\Request;
12 * @coversDefaultClass \Drupal\Core\PathProcessor\PathProcessorAlias
13 * @group PathProcessor
15 class PathProcessorAliasTest extends UnitTestCase {
18 * The mocked alias manager.
20 * @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
22 protected $aliasManager;
25 * The tested path processor.
27 * @var \Drupal\Core\PathProcessor\PathProcessorAlias
29 protected $pathProcessor;
31 protected function setUp() {
32 $this->aliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
33 $this->pathProcessor = new PathProcessorAlias($this->aliasManager);
37 * Tests the processInbound method.
39 * @see \Drupal\Core\PathProcessor\PathProcessorAlias::processInbound
41 public function testProcessInbound() {
42 $this->aliasManager->expects($this->exactly(2))
43 ->method('getPathByAlias')
44 ->will($this->returnValueMap([
45 ['urlalias', NULL, 'internal-url'],
49 $request = Request::create('/urlalias');
50 $this->assertEquals('internal-url', $this->pathProcessor->processInbound('urlalias', $request));
51 $request = Request::create('/url');
52 $this->assertEquals('url', $this->pathProcessor->processInbound('url', $request));
56 * @covers ::processOutbound
58 * @dataProvider providerTestProcessOutbound
60 public function testProcessOutbound($path, array $options, $expected_path) {
61 $this->aliasManager->expects($this->any())
62 ->method('getAliasByPath')
63 ->will($this->returnValueMap([
64 ['internal-url', NULL, 'urlalias'],
68 $bubbleable_metadata = new BubbleableMetadata();
69 $this->assertEquals($expected_path, $this->pathProcessor->processOutbound($path, $options, NULL, $bubbleable_metadata));
70 // Cacheability of paths replaced with path aliases is permanent.
71 // @todo https://www.drupal.org/node/2480077
72 $this->assertEquals((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT), $bubbleable_metadata);
78 public function providerTestProcessOutbound() {
80 ['internal-url', [], 'urlalias'],
81 ['internal-url', ['alias' => TRUE], 'internal-url'],