Commit 02c560d8 authored by alexpott's avatar alexpott

Issue #3100190 by quietone: Change ValidateMigrationStateTestTrait to only test one version

(cherry picked from commit 5367f8a5)
parent 0ec10129
......@@ -4,6 +4,7 @@
use Drupal\Component\Discovery\YamlDiscovery;
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
use Drupal\migrate_drupal\MigrationConfigurationTrait;
use Drupal\migrate_drupal\MigrationState;
/**
......@@ -18,6 +19,7 @@
trait ValidateMigrationStateTestTrait {
use FileSystemModuleDiscoveryDataProviderTrait;
use MigrationConfigurationTrait;
/**
* Tests the migration information in .migrate_drupal.yml.
......@@ -35,36 +37,34 @@ public function testMigrationState() {
$this->enableAllModules();
$version = (string) $this->getLegacyDrupalVersion($this->sourceDatabase);
// Build an array for each migration keyed by provider. The value is a
// string consisting of the version number, the provider, the source_module
// and the destination module.
$discovered = [];
$versions = ['6', '7'];
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
$plugin_manager = $this->container->get('plugin.manager.migration');
foreach ($versions as $version) {
$migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
/** @var \Drupal\migrate\Plugin\Migration $migration */
foreach ($migrations as $migration) {
$definition = $migration->getPluginDefinition();
if (is_array($definition['provider'])) {
$provider = reset($definition['provider']);
}
else {
$provider = $definition['provider'];
}
$migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
/** @var \Drupal\migrate\Plugin\Migration $migration */
foreach ($migrations as $migration) {
$definition = $migration->getPluginDefinition();
if (is_array($definition['provider'])) {
$provider = reset($definition['provider']);
}
else {
$provider = $definition['provider'];
}
$source_module = $migration->getSourcePlugin()->getSourceModule();
$destination_module = $migration->getDestinationPlugin()
->getDestinationModule();
$source_module = $migration->getSourcePlugin()->getSourceModule();
$destination_module = $migration->getDestinationPlugin()
->getDestinationModule();
$discovered[$version][] = implode($separator, [
$version,
$provider,
$source_module,
$destination_module,
]);
}
$discovered[] = implode($separator, [
$provider,
$source_module,
$destination_module,
]);
}
// Add the field migrations.
......@@ -72,9 +72,8 @@ public function testMigrationState() {
$definitions = $this->container->get('plugin.manager.migrate.field')
->getDefinitions();
foreach ($definitions as $key => $definition) {
foreach ($definition['core'] as $version) {
$discovered[$version][] = implode($separator, [
$version,
if (isset($definition['core'][$version])) {
$discovered[] = implode($separator, [
$definition['provider'],
$definition['source_module'],
$definition['destination_module'],
......@@ -95,17 +94,15 @@ public function testMigrationState() {
$states = [MigrationState::FINISHED, MigrationState::NOT_FINISHED];
foreach ($system_info as $module => $info) {
foreach ($states as $state) {
if (isset($info[$state])) {
foreach ($info[$state] as $info_version => $migrate_info) {
foreach ($migrate_info as $source => $destination) {
// Do not add the source module i18nstrings or i18_string. The
// 18n migrations can have up to three source modules but only one
// can be handled in the migration.
if (($source !== 'i18nstrings') && ($source !== 'i18n_string')) {
foreach ((array) $destination as $dest) {
$key = [$info_version, $module, $source, trim($dest)];
$declared[$info_version][$state][] = implode($separator, $key);
}
if (isset($info[$state][$version])) {
foreach ($info[$state][$version] as $source => $destination) {
// Do not add the source module i18nstrings or i18_string. The
// 18n migrations can have up to three source modules but only one
// can be handled in the migration.
if (($source !== 'i18nstrings') && ($source !== 'i18n_string')) {
foreach ((array) $destination as $dest) {
$key = [$module, $source, trim($dest)];
$declared[$state][] = implode($separator, $key);
}
}
}
......@@ -113,34 +110,31 @@ public function testMigrationState() {
}
}
$versions = ['6', '7'];
foreach ($versions as $version) {
// Sort and make the array values unique.
sort($declared[$version][MigrationState::FINISHED]);
sort($declared[$version][MigrationState::NOT_FINISHED]);
$declared_unique[$version][MigrationState::FINISHED] = array_unique($declared[$version][MigrationState::FINISHED]);
$declared_unique[$version][MigrationState::NOT_FINISHED] = array_unique($declared[$version][MigrationState::NOT_FINISHED]);
sort($discovered[$version]);
$discovered_unique[$version] = array_unique($discovered[$version]);
// Assert that each discovered migration has a corresponding declaration
// in a migrate_drupal.yml.
foreach ($discovered_unique[$version] as $datum) {
$data = str_getcsv($datum);
$in_finished = in_array($datum, $declared_unique[$version][MigrationState::FINISHED]);
$in_not_finished = in_array($datum, $declared_unique[$version][MigrationState::NOT_FINISHED]);
$found = $in_finished || $in_not_finished;
$this->assertTrue($found, sprintf("No migration state found for version '%s' with source_module '%s' and destination_module '%s' declared in module '%s'", $data[0], $data[2], $data[3], $data[1]));
}
// Sort and make the array values unique.
sort($declared[MigrationState::FINISHED]);
sort($declared[MigrationState::NOT_FINISHED]);
$declared_unique[MigrationState::FINISHED] = array_unique($declared[MigrationState::FINISHED]);
$declared_unique[MigrationState::NOT_FINISHED] = array_unique($declared[MigrationState::NOT_FINISHED]);
sort($discovered);
$discovered_unique = array_unique($discovered);
// Assert that each discovered migration has a corresponding declaration
// in a migrate_drupal.yml.
foreach ($discovered_unique as $datum) {
$data = str_getcsv($datum);
$in_finished = in_array($datum, $declared_unique[MigrationState::FINISHED]);
$in_not_finished = in_array($datum, $declared_unique[MigrationState::NOT_FINISHED]);
$found = $in_finished || $in_not_finished;
$this->assertTrue($found, sprintf("No migration state found for version '%s' with source_module '%s' and destination_module '%s' declared in module '%s'", $version, $data[1], $data[2], $data[0]));
}
// Remove the declared finished from the discovered, leaving just the not
// finished, if there are any. These should have an entry in the declared
// not finished.
$discovered_not_finished = array_diff($discovered_unique[$version], $declared_unique[$version][MigrationState::FINISHED]);
foreach ($discovered_not_finished as $datum) {
$data = str_getcsv($datum);
$this->assertContains($datum, $declared_unique[$version][MigrationState::NOT_FINISHED], sprintf("No migration found for version '%s' with source_module '%s' and destination_module '%s' declared in module '%s'", $data[0], $data[2], $data[3], $data[1]));
}
// Remove the declared finished from the discovered, leaving just the not
// finished, if there are any. These should have an entry in the declared
// not finished.
$discovered_not_finished = array_diff($discovered_unique, $declared_unique[MigrationState::FINISHED]);
foreach ($discovered_not_finished as $datum) {
$data = str_getcsv($datum);
$this->assertContains($datum, $declared_unique[MigrationState::NOT_FINISHED], sprintf("No migration found for version '%s' with source_module '%s' and destination_module '%s' declared in module '%s'", $version, $data[1], $data[2], $data[0]));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment