MigrateUrlAliasTest.php in Zircon Profile 8.0
File
core/modules/path/src/Tests/Migrate/d6/MigrateUrlAliasTest.php
View source
<?php
namespace Drupal\path\Tests\Migrate\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\Core\Database\Database;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
public static $modules = array(
'path',
);
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'url_alias',
]);
$this
->executeMigration('d6_url_alias');
}
public function testUrlAlias() {
$id_map = Migration::load('d6_url_alias')
->getIdMap();
$conditions = array(
'source' => '/node/1',
'alias' => '/alias-one',
'langcode' => 'en',
);
$path = \Drupal::service('path.alias_storage')
->load($conditions);
$this
->assertNotNull($path, "Path alias for node/1 successfully loaded.");
$this
->assertIdentical($id_map
->lookupDestinationID(array(
$path['pid'],
)), array(
'1',
), "Test IdMap");
$conditions = array(
'source' => '/node/2',
'alias' => '/alias-two',
'langcode' => 'en',
);
$path = \Drupal::service('path.alias_storage')
->load($conditions);
$this
->assertNotNull($path, "Path alias for node/2 successfully loaded.");
Database::getConnection('default', 'migrate')
->update('url_alias')
->fields(array(
'dst' => 'new-url-alias',
))
->condition('src', 'node/2')
->execute();
\Drupal::database()
->update($id_map
->mapTableName())
->fields(array(
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
))
->execute();
$migration = \Drupal::entityManager()
->getStorage('migration')
->loadUnchanged('d6_url_alias');
$this
->executeMigration($migration);
$path = \Drupal::service('path.alias_storage')
->load(array(
'pid' => $path['pid'],
));
$this
->assertIdentical('/new-url-alias', $path['alias']);
}
}