dae024950010a5627f123a2094911555f2eed971
[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     $alias_storage = $this->container->get('path.alias_storage');
52
53     $path = $alias_storage->load([
54       'source' => '/taxonomy/term/4',
55       'alias' => '/term33',
56       'langcode' => 'und',
57     ]);
58     $this->assertIdentical('/taxonomy/term/4', $path['source']);
59     $this->assertIdentical('/term33', $path['alias']);
60     $this->assertIdentical('und', $path['langcode']);
61
62     // Alias with no slash.
63     $path = $alias_storage->load(['alias' => '/source-noslash']);
64     $this->assertSame('/admin', $path['source']);
65     $this->assertSame('und', $path['langcode']);
66   }
67
68   /**
69    * Test the URL alias migration with translated nodes.
70    */
71   public function testUrlAliasWithTranslatedNodes() {
72     $alias_storage = $this->container->get('path.alias_storage');
73
74     // Alias for the 'The thing about Deep Space 9' node in English.
75     $path = $alias_storage->load(['alias' => '/deep-space-9']);
76     $this->assertSame('/node/2', $path['source']);
77     $this->assertSame('en', $path['langcode']);
78
79     // Alias for the 'The thing about Deep Space 9' Icelandic translation,
80     // which should now point to node/2 instead of node/3.
81     $path = $alias_storage->load(['alias' => '/deep-space-9-is']);
82     $this->assertSame('/node/2', $path['source']);
83     $this->assertSame('is', $path['langcode']);
84
85     // Alias for the 'The thing about Firefly' node in Icelandic.
86     $path = $alias_storage->load(['alias' => '/firefly-is']);
87     $this->assertSame('/node/4', $path['source']);
88     $this->assertSame('is', $path['langcode']);
89
90     // Alias for the 'The thing about Firefly' English translation,
91     // which should now point to node/4 instead of node/5.
92     $path = $alias_storage->load(['alias' => '/firefly']);
93     $this->assertSame('/node/4', $path['source']);
94     $this->assertSame('en', $path['langcode']);
95   }
96
97 }