Version 1
[yaffs-website] / web / core / modules / path / tests / src / Kernel / Migrate / d7 / MigrateUrlAliasTest.php
1 <?php
2
3 namespace Drupal\Tests\path\Kernel\Migrate\d7;
4
5 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
6
7 /**
8  * Tests URL alias migration.
9  *
10  * @group path
11  */
12 class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = [
18     'content_translation',
19     'language',
20     'menu_ui',
21     'node',
22     'path',
23     'text',
24   ];
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     parent::setUp();
31
32     $this->installEntitySchema('node');
33     $this->installConfig('node');
34     $this->installSchema('node', ['node_access']);
35
36     $this->executeMigrations([
37       'language',
38       'd7_user_role',
39       'd7_user',
40       'd7_node_type',
41       'd7_node',
42       'd7_node_translation',
43       'd7_url_alias',
44     ]);
45   }
46
47   /**
48    * Test the URL alias migration.
49    */
50   public function testUrlAlias() {
51     $path = \Drupal::service('path.alias_storage')->load([
52       'source' => '/taxonomy/term/4',
53       'alias' => '/term33',
54       'langcode' => 'und',
55     ]);
56     $this->assertIdentical('/taxonomy/term/4', $path['source']);
57     $this->assertIdentical('/term33', $path['alias']);
58     $this->assertIdentical('und', $path['langcode']);
59   }
60
61   /**
62    * Test the URL alias migration with translated nodes.
63    */
64   public function testUrlAliasWithTranslatedNodes() {
65     $alias_storage = $this->container->get('path.alias_storage');
66
67     // Alias for the 'The thing about Deep Space 9' node in English.
68     $path = $alias_storage->load(['alias' => '/deep-space-9']);
69     $this->assertSame('/node/2', $path['source']);
70     $this->assertSame('en', $path['langcode']);
71
72     // Alias for the 'The thing about Deep Space 9' Icelandic translation,
73     // which should now point to node/2 instead of node/3.
74     $path = $alias_storage->load(['alias' => '/deep-space-9-is']);
75     $this->assertSame('/node/2', $path['source']);
76     $this->assertSame('is', $path['langcode']);
77
78     // Alias for the 'The thing about Firefly' node in Icelandic.
79     $path = $alias_storage->load(['alias' => '/firefly-is']);
80     $this->assertSame('/node/4', $path['source']);
81     $this->assertSame('is', $path['langcode']);
82
83     // Alias for the 'The thing about Firefly' English translation,
84     // which should now point to node/4 instead of node/5.
85     $path = $alias_storage->load(['alias' => '/firefly']);
86     $this->assertSame('/node/4', $path['source']);
87     $this->assertSame('en', $path['langcode']);
88   }
89
90 }