Commit 426c9fd3 authored by alexpott's avatar alexpott
Browse files

Issue #2561049 by phenaproxima, quietone: Add proper unit tests for the Migration process plugin

parent 2d292cd1
......@@ -93,7 +93,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$source_id_values[$migration_id] = $value;
}
// Break out of the loop as soon as a destination ID is found.
if ($destination_ids = $migration->getIdMap()->lookupDestinationID($source_id_values[$migration_id])) {
if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) {
break;
}
}
......@@ -162,7 +162,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
*
* @throws \Drupal\migrate\MigrateSkipProcessException
*/
protected function skipOnEmpty($value) {
protected function skipOnEmpty(array $value) {
if (!array_filter($value)) {
throw new MigrateSkipProcessException();
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\Migration;
use Drupal\migrate\Plugin\MigrateDestinationInterface;
......@@ -86,4 +87,51 @@ public function testTransformWithStubbing() {
$this->assertEquals(2, $result);
}
/**
* Tests that processing is skipped when the input value is empty.
*
* @expectedException \Drupal\migrate\MigrateSkipProcessException
*/
public function testSkipOnEmpty() {
$migration_plugin = $this->prophesize(MigrationInterface::class);
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
$configuration = [
'migration' => 'foobaz',
];
$migration_plugin->id()->willReturn(uniqid());
$migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
}
/**
* Tests a successful lookup.
*/
public function testSuccessfulLookup() {
$migration_plugin = $this->prophesize(MigrationInterface::class);
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
$configuration = [
'migration' => 'foobaz',
];
$migration_plugin->id()->willReturn(uniqid());
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$id_map->lookupDestinationId([1])->willReturn([3]);
$migration_plugin->getIdMap()->willReturn($id_map->reveal());
$migration_plugin_manager->createInstances(['foobaz'])
->willReturn(['foobaz' => $migration_plugin->reveal()]);
$migrationStorage = $this->prophesize(EntityStorageInterface::class);
$migrationStorage
->loadMultiple(['foobaz'])
->willReturn([$migration_plugin->reveal()]);
$migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
$this->assertSame(3, $migration->transform(1, $this->migrateExecutable, $this->row, 'foo'));
}
}
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