More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / PathProcessor / PathProcessorAliasTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\PathProcessor;
4
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;
10
11 /**
12  * @coversDefaultClass \Drupal\Core\PathProcessor\PathProcessorAlias
13  * @group PathProcessor
14  */
15 class PathProcessorAliasTest extends UnitTestCase {
16
17   /**
18    * The mocked alias manager.
19    *
20    * @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
21    */
22   protected $aliasManager;
23
24   /**
25    * The tested path processor.
26    *
27    * @var \Drupal\Core\PathProcessor\PathProcessorAlias
28    */
29   protected $pathProcessor;
30
31   protected function setUp() {
32     $this->aliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
33     $this->pathProcessor = new PathProcessorAlias($this->aliasManager);
34   }
35
36   /**
37    * Tests the processInbound method.
38    *
39    * @see \Drupal\Core\PathProcessor\PathProcessorAlias::processInbound
40    */
41   public function testProcessInbound() {
42     $this->aliasManager->expects($this->exactly(2))
43       ->method('getPathByAlias')
44       ->will($this->returnValueMap([
45         ['urlalias', NULL, 'internal-url'],
46         ['url', NULL, 'url'],
47       ]));
48
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));
53   }
54
55   /**
56    * @covers ::processOutbound
57    *
58    * @dataProvider providerTestProcessOutbound
59    */
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'],
65         ['url', NULL, 'url'],
66       ]));
67
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);
73   }
74
75   /**
76    * @return array
77    */
78   public function providerTestProcessOutbound() {
79     return [
80       ['internal-url', [], 'urlalias'],
81       ['internal-url', ['alias' => TRUE], 'internal-url'],
82       ['url', [], 'url'],
83     ];
84   }
85
86 }