3 namespace Drupal\Tests\path\Kernel\Migrate\d6;
5 use Drupal\migrate\Plugin\MigrateIdMapInterface;
6 use Drupal\Core\Database\Database;
7 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
10 * URL alias migration.
12 * @group migrate_drupal_6
14 class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
19 public static $modules = ['language', 'content_translation', 'path', 'menu_ui'];
24 protected function setUp() {
26 $this->installEntitySchema('node');
27 $this->installConfig(['node']);
28 $this->installSchema('node', ['node_access']);
29 $this->migrateUsers(FALSE);
30 $this->migrateFields();
32 $this->executeMigrations([
36 'd6_node_translation',
46 * @param array $conditions
47 * The path conditions.
51 private function assertPath($pid, $conditions, $path) {
52 $this->assertTrue($path, "Path alias for " . $conditions['source'] . " successfully loaded.");
53 $this->assertIdentical($conditions['alias'], $path['alias']);
54 $this->assertIdentical($conditions['langcode'], $path['langcode']);
55 $this->assertIdentical($conditions['source'], $path['source']);
59 * Test the url alias migration.
61 public function testUrlAlias() {
62 $id_map = $this->getMigration('d6_url_alias')->getIdMap();
63 // Test that the field exists.
65 'source' => '/node/1',
66 'alias' => '/alias-one',
69 $path = \Drupal::service('path.alias_storage')->load($conditions);
70 $this->assertPath('1', $conditions, $path);
71 $this->assertIdentical($id_map->lookupDestinationID([$path['pid']]), ['1'], "Test IdMap");
74 'source' => '/node/2',
75 'alias' => '/alias-two',
78 $path = \Drupal::service('path.alias_storage')->load($conditions);
79 $this->assertPath('2', $conditions, $path);
81 // Test that we can re-import using the UrlAlias destination.
82 Database::getConnection('default', 'migrate')
84 ->fields(['dst' => 'new-url-alias'])
85 ->condition('src', 'node/2')
89 ->update($id_map->mapTableName())
90 ->fields(['source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE])
92 $migration = $this->getMigration('d6_url_alias');
93 $this->executeMigration($migration);
95 $path = \Drupal::service('path.alias_storage')->load(['pid' => $path['pid']]);
96 $conditions['alias'] = '/new-url-alias';
97 $this->assertPath('2', $conditions, $path);
100 'source' => '/node/3',
101 'alias' => '/alias-three',
104 $path = \Drupal::service('path.alias_storage')->load($conditions);
105 $this->assertPath('3', $conditions, $path);
107 $path = \Drupal::service('path.alias_storage')->load(['alias' => '/source-noslash']);
109 'source' => '/admin',
110 'alias' => '/source-noslash',
113 $this->assertPath('2', $conditions, $path);
117 * Test the URL alias migration with translated nodes.
119 public function testUrlAliasWithTranslatedNodes() {
120 $alias_storage = $this->container->get('path.alias_storage');
122 // Alias for the 'The Real McCoy' node in English.
123 $path = $alias_storage->load(['alias' => '/the-real-mccoy']);
124 $this->assertSame('/node/10', $path['source']);
125 $this->assertSame('en', $path['langcode']);
127 // Alias for the 'The Real McCoy' French translation,
128 // which should now point to node/10 instead of node/11.
129 $path = $alias_storage->load(['alias' => '/le-vrai-mccoy']);
130 $this->assertSame('/node/10', $path['source']);
131 $this->assertSame('fr', $path['langcode']);
133 // Alias for the 'Abantu zulu' node in Zulu.
134 $path = $alias_storage->load(['alias' => '/abantu-zulu']);
135 $this->assertSame('/node/12', $path['source']);
136 $this->assertSame('zu', $path['langcode']);
138 // Alias for the 'Abantu zulu' English translation,
139 // which should now point to node/12 instead of node/13.
140 $path = $alias_storage->load(['alias' => '/the-zulu-people']);
141 $this->assertSame('/node/12', $path['source']);
142 $this->assertSame('en', $path['langcode']);