You are here

public function MigrateUrlAliasTest::testUrlAlias in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php \Drupal\Tests\path\Kernel\Migrate\d6\MigrateUrlAliasTest::testUrlAlias()
  2. 10 core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php \Drupal\Tests\path\Kernel\Migrate\d6\MigrateUrlAliasTest::testUrlAlias()

Test the url alias migration.

File

core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php, line 72

Class

MigrateUrlAliasTest
URL alias migration.

Namespace

Drupal\Tests\path\Kernel\Migrate\d6

Code

public function testUrlAlias() {
  $id_map = $this
    ->getMigration('d6_url_alias')
    ->getIdMap();

  // Test that the field exists.
  $conditions = [
    'path' => '/node/1',
    'alias' => '/alias-one',
    'langcode' => 'af',
  ];
  $path_alias = $this
    ->loadPathAliasByConditions($conditions);
  $this
    ->assertPath(1, $conditions, $path_alias);
  $this
    ->assertSame([
    [
      '1',
    ],
  ], $id_map
    ->lookupDestinationIds([
    $path_alias
      ->id(),
  ]), "Test IdMap");
  $conditions = [
    'path' => '/node/2',
    'alias' => '/alias-two',
    'langcode' => 'en',
  ];
  $path_alias = $this
    ->loadPathAliasByConditions($conditions);
  $this
    ->assertPath(2, $conditions, $path_alias);

  // Test that we can re-import using the UrlAlias destination.
  Database::getConnection('default', 'migrate')
    ->update('url_alias')
    ->fields([
    'dst' => 'new-url-alias',
  ])
    ->condition('src', 'node/2')
    ->execute();
  \Drupal::database()
    ->update($id_map
    ->mapTableName())
    ->fields([
    'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
  ])
    ->execute();
  $migration = $this
    ->getMigration('d6_url_alias');
  $this
    ->executeMigration($migration);
  $path_alias = $this
    ->loadPathAliasByConditions([
    'id' => $path_alias
      ->id(),
  ]);
  $conditions['alias'] = '/new-url-alias';
  $this
    ->assertPath(2, $conditions, $path_alias);
  $conditions = [
    'path' => '/node/3',
    'alias' => '/alias-three',
    'langcode' => 'und',
  ];
  $path_alias = $this
    ->loadPathAliasByConditions($conditions);
  $this
    ->assertPath(3, $conditions, $path_alias);
  $path_alias = $this
    ->loadPathAliasByConditions([
    'alias' => '/source-noslash',
  ]);
  $conditions = [
    'path' => '/admin',
    'alias' => '/source-noslash',
    'langcode' => 'und',
  ];
  $this
    ->assertPath(8, $conditions, $path_alias);
}