View source
<?php
namespace Drupal\Tests\migrate_upgrade\Kernel {
use Drupal\Component\Plugin\PluginBase;
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
use Drupal\migrate_drupal\MigrationConfigurationTrait;
use Drupal\migrate_plus\Entity\Migration;
use Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands;
use Drupal\Tests\DeprecatedModulesTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
class DrushTest extends MigrateDrupalTestBase {
use CreateMigrationsTrait;
use FileSystemModuleDiscoveryDataProviderTrait;
use MigrationConfigurationTrait;
protected $migrationManager;
protected $commands;
protected function setUp() : void {
self::$modules = array_merge(array_keys($this
->coreModuleListDataProvider()), [
'migrate_plus',
'migrate_upgrade',
]);
self::$modules = array_diff(self::$modules, [
'block_place',
]);
parent::setUp();
$this
->installSchema('system', [
'key_value',
'key_value_expire',
]);
$this
->installConfig(self::$modules);
$this
->installEntitySchema('migration_group');
$this
->installEntitySchema('migration');
$this->migrationManager = \Drupal::service('plugin.manager.migration');
$this->state = $this->container
->get('state');
$loggerProphet = $this
->prophesize('\\Drush\\Log\\Logger');
$loggerFactoryProphet = $this
->prophesize('\\Drupal\\Core\\Logger\\LoggerChannelFactoryInterface');
$loggerFactoryProphet
->get('drush')
->willReturn($loggerProphet
->reveal());
$this->commands = new MigrateUpgradeCommands($this->state, $loggerFactoryProphet
->reveal());
}
public function testD6Migrations() : void {
$this
->drupal6Migrations();
$options = [
'configure-only' => TRUE,
'legacy-db-key' => $this->sourceDatabase
->getKey(),
];
$this->commands
->upgrade($options);
$migrate_plus_migrations = Migration::loadMultiple();
$migrations = $this
->getMigrations($this->sourceDatabase
->getKey(), 6);
$this
->assertMigrations($migrations, $migrate_plus_migrations);
$optional = array_flip($migrate_plus_migrations['upgrade_d6_url_alias']
->toArray()['migration_dependencies']['optional']);
$node_migrations = array_intersect_key([
'upgrade_d6_node_translation_page' => TRUE,
'upgrade_d6_node_complete_page' => TRUE,
], $optional);
$this
->assertNotEmpty($node_migrations);
}
public function testD7Migrations() : void {
$this
->drupal7Migrations();
$this->sourceDatabase
->update('system')
->fields([
'status' => 1,
])
->condition('name', 'profile')
->execute();
$options = [
'configure-only' => TRUE,
'legacy-db-key' => $this->sourceDatabase
->getKey(),
];
$this->commands
->upgrade($options);
$migrate_plus_migrations = Migration::loadMultiple();
$migrations = $this
->getMigrations($this->sourceDatabase
->getKey(), 7);
$this
->assertMigrations($migrations, $migrate_plus_migrations);
$optional = array_flip($migrate_plus_migrations['upgrade_d7_url_alias']
->toArray()['migration_dependencies']['optional']);
$node_migrations = array_intersect_key([
'upgrade_d7_node_translation_page' => TRUE,
'upgrade_d7_node_complete_page' => TRUE,
], $optional);
$this
->assertNotEmpty($node_migrations);
}
protected function assertMigrations(array $migrations, array $migrate_plus_migrations) : void {
foreach ($migrations as $id => $migration) {
$migration_id = 'upgrade_' . str_replace(PluginBase::DERIVATIVE_SEPARATOR, '_', $migration
->id());
$this
->assertArrayHasKey($migration_id, $migrate_plus_migrations);
}
$this
->assertCount(count($migrations), $migrate_plus_migrations);
}
}
}
namespace {
if (!function_exists('dt')) {
function dt($message, array $replace = []) {
return strtr($message, $replace);
}
}
if (!function_exists('drush_op')) {
function drush_op(callable $callable) {
$args = func_get_args();
array_shift($args);
call_user_func_array($callable, $args);
}
}
}