diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index ea4ecdac1d2..6d6cc498986 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -43135,6 +43135,30 @@ $connection->insert('url_alias') 'alias' => 'term33', 'language' => 'und', )) +->values(array( + 'pid' => '2', + 'source' => 'node/2', + 'alias' => 'deep-space-9', + 'language' => 'en', +)) +->values(array( + 'pid' => '3', + 'source' => 'node/3', + 'alias' => 'deep-space-9-is', + 'language' => 'is', +)) +->values(array( + 'pid' => '4', + 'source' => 'node/4', + 'alias' => 'firefly-is', + 'language' => 'is', +)) +->values(array( + 'pid' => '5', + 'source' => 'node/5', + 'alias' => 'firefly', + 'language' => 'en', +)) ->execute(); $connection->schema()->createTable('users', array( diff --git a/core/modules/path/migration_templates/d7_url_alias.yml b/core/modules/path/migration_templates/d7_url_alias.yml index a3ddec1ad0f..713a34676f7 100644 --- a/core/modules/path/migration_templates/d7_url_alias.yml +++ b/core/modules/path/migration_templates/d7_url_alias.yml @@ -18,5 +18,17 @@ process: - constants/slash - alias langcode: language + node_translation: + - + plugin: explode + source: source + delimiter: / + - + plugin: extract + index: + - 1 + - + plugin: migration + migration: d7_node_translation destination: plugin: url_alias diff --git a/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php b/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php index 88c102b4e58..18452fedf19 100644 --- a/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php +++ b/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php @@ -14,14 +14,33 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase { /** * {@inheritdoc} */ - public static $modules = ['path']; + public static $modules = [ + 'content_translation', + 'language', + 'node', + 'path', + 'text', + ]; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $this->executeMigration('d7_url_alias'); + + $this->installEntitySchema('node'); + $this->installConfig('node'); + $this->installSchema('node', ['node_access']); + + $this->executeMigrations([ + 'language', + 'd7_user_role', + 'd7_user', + 'd7_node_type', + 'd7_node', + 'd7_node_translation', + 'd7_url_alias', + ]); } /** @@ -38,4 +57,33 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase { $this->assertIdentical('und', $path['langcode']); } + /** + * Test the URL alias migration with translated nodes. + */ + public function testUrlAliasWithTranslatedNodes() { + $alias_storage = $this->container->get('path.alias_storage'); + + // Alias for the 'The thing about Deep Space 9' node in English. + $path = $alias_storage->load(['alias' => '/deep-space-9']); + $this->assertSame('/node/2', $path['source']); + $this->assertSame('en', $path['langcode']); + + // Alias for the 'The thing about Deep Space 9' Icelandic translation, + // which should now point to node/2 instead of node/3. + $path = $alias_storage->load(['alias' => '/deep-space-9-is']); + $this->assertSame('/node/2', $path['source']); + $this->assertSame('is', $path['langcode']); + + // Alias for the 'The thing about Firefly' node in Icelandic. + $path = $alias_storage->load(['alias' => '/firefly-is']); + $this->assertSame('/node/4', $path['source']); + $this->assertSame('is', $path['langcode']); + + // Alias for the 'The thing about Firefly' English translation, + // which should now point to node/4 instead of node/5. + $path = $alias_storage->load(['alias' => '/firefly']); + $this->assertSame('/node/4', $path['source']); + $this->assertSame('en', $path['langcode']); + } + }