function MigrateUrlAliasTest::testUrlAlias

Same name in other branches
  1. 8.9.x 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()
  3. 11.x core/modules/path/tests/src/Kernel/Migrate/d6/MigrateUrlAliasTest.php \Drupal\Tests\path\Kernel\Migrate\d6\MigrateUrlAliasTest::testUrlAlias()

Tests the url alias migration.

File

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

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);
    // Tests the URL alias migration with translated nodes.
    // Alias for the 'The Real McCoy' node in English.
    $path_alias = $this->loadPathAliasByConditions([
        'alias' => '/the-real-mccoy',
    ]);
    $this->assertSame('/node/10', $path_alias->getPath());
    $this->assertSame('en', $path_alias->get('langcode')->value);
    // Alias for the 'The Real McCoy' French translation,
    // which should now point to node/10 instead of node/11.
    $path_alias = $this->loadPathAliasByConditions([
        'alias' => '/le-vrai-mccoy',
    ]);
    $this->assertSame('/node/10', $path_alias->getPath());
    $this->assertSame('fr', $path_alias->get('langcode')->value);
    // Alias for the 'Abantu zulu' node in Zulu.
    $path_alias = $this->loadPathAliasByConditions([
        'alias' => '/abantu-zulu',
    ]);
    $this->assertSame('/node/12', $path_alias->getPath());
    $this->assertSame('zu', $path_alias->get('langcode')->value);
    // Alias for the 'Abantu zulu' English translation,
    // which should now point to node/12 instead of node/13.
    $path_alias = $this->loadPathAliasByConditions([
        'alias' => '/the-zulu-people',
    ]);
    $this->assertSame('/node/12', $path_alias->getPath());
    $this->assertSame('en', $path_alias->get('langcode')->value);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.