Skip to content
Snippets Groups Projects
Unverified Commit b208b077 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2865247 by Jo Fitzgerald, NickWilde, rakesh.gectcr, heddn, maxocub:...

Issue #2865247 by Jo Fitzgerald, NickWilde, rakesh.gectcr, heddn, maxocub: Migration lookup process plugin doesn't check validity of provided migration(s)
parent 9ed571d5
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
......@@ -155,10 +156,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$migration_ids = [$migration_ids];
}
$self = FALSE;
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
$destination_ids = NULL;
$source_id_values = [];
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
$migrations = $this->migrationPluginManager->createInstances($migration_ids);
// If no migrations are loaded it means either the migration is unavailable
// (perhaps in a disabled module) or doesn't exist (probably mis-typed).
if (empty($migrations)) {
throw new MigrateException(sprintf("The '%s' plugin failed because at least one of the migrations with the following ID(s) does not exist: %s.", $this->getPluginId(), implode(', ', $migration_ids)));
}
foreach ($migrations as $migration_id => $migration) {
if ($migration_id == $this->migration->id()) {
$self = TRUE;
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\MigrationLookup;
......@@ -298,4 +299,49 @@ public function testMultipleSourceIds() {
$this->assertEquals(2, $result);
}
/**
* Tests that invalid migrations trigger the exception in transform().
*
* @covers ::transform
*
* @dataProvider transformWithInvalidMigrationsDataProvider
*
* @param string|string[] $migration_ids
* The ID(s) of migration(s) including at least one invalid ID.
* @param string $invalid_migrations
* The list of migration IDs containing at least one invalid ID.
*/
public function testTransformWithInvalidMigrations($migration_ids, $invalid_migrations) {
$migration_plugin = $this->prophesize(MigrationInterface::class);
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$migration_plugin_manager->createInstances(Argument::any())->willReturn([]);
$migration = new MigrationLookup(['migration' => $migration_ids], 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
$this->setExpectedException(MigrateException::class, "The 'migration_lookup' plugin failed because at least one of the migrations with the following ID(s) does not exist: $invalid_migrations.");
$migration->transform(1, $this->migrateExecutable, $this->row, '');
}
/**
* Provides data for the invalid migrations test.
*
* @return array
*/
public function transformWithInvalidMigrationsDataProvider() {
return [
'migration_id_string' => [
'migration_ids' => 'invalid_migration',
'invalid_migrations' => 'invalid_migration',
],
'migration_id_array_single' => [
'migration_ids' => ['invalid_migration'],
'invalid_migrations' => 'invalid_migration',
],
'migration_id_array_multiple' => [
'migration_ids' => ['invalid_migration_1', 'invalid_migration_2'],
'invalid_migrations' => 'invalid_migration_1, invalid_migration_2',
],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment