X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FUnit%2Fprocess%2FMigrationLookupTest.php;h=9158cdbdbdec3e00825bfd83791e227c8d747166;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=dd18928d4a0b185c2ea0c9f1b2d15540f3fc012d;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php b/web/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php index dd18928d4..9158cdbdb 100644 --- a/web/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php +++ b/web/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\migrate\Unit\process; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\migrate\MigrateSkipProcessException; +use Drupal\migrate\Plugin\migrate\process\Get; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\process\MigrationLookup; use Drupal\migrate\Plugin\MigrateDestinationInterface; @@ -11,6 +12,7 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigratePluginManager; use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate\Row; use Prophecy\Argument; /** @@ -100,6 +102,8 @@ class MigrationLookupTest extends MigrateProcessTestCase { 'migration' => 'foobaz', ]; $migration_plugin->id()->willReturn(uniqid()); + $migration_plugin_manager->createInstances(['foobaz']) + ->willReturn(['foobaz' => $migration_plugin->reveal()]); $migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); $this->setExpectedException(MigrateSkipProcessException::class); $migration->transform(0, $this->migrateExecutable, $this->row, 'foo'); @@ -238,4 +242,61 @@ class MigrationLookupTest extends MigrateProcessTestCase { $migration->transform(1, $this->migrateExecutable, $this->row, ''); } + /** + * Tests processing multiple source IDs. + */ + public function testMultipleSourceIds() { + $migration_plugin = $this->prophesize(MigrationInterface::class); + $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); + $process_plugin_manager = $this->prophesize(MigratePluginManager::class); + $foobaz_migration = $this->prophesize(MigrationInterface::class); + $get_migration = $this->prophesize(Get::class); + $id_map = $this->prophesize(MigrateIdMapInterface::class); + $destination_plugin = $this->prophesize(MigrateDestinationInterface::class); + $source_plugin = $this->prophesize(MigrateSourceInterface::class); + + $migration_plugin_manager->createInstances(['foobaz']) + ->willReturn(['foobaz' => $foobaz_migration->reveal()]); + + $process_plugin_manager->createInstance('get', ['source' => ['string_id', 'integer_id']], $migration_plugin->reveal()) + ->willReturn($get_migration->reveal()); + + $foobaz_migration->getIdMap()->willReturn($id_map->reveal()); + $foobaz_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal()); + $foobaz_migration->getProcess()->willReturn([]); + $foobaz_migration->getSourcePlugin()->willReturn($source_plugin->reveal()); + $foobaz_migration->id()->willReturn('foobaz'); + $foobaz_migration->getSourceConfiguration()->willReturn([]); + + $get_migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo') + ->willReturn(['example_string', 99]); + + $source_plugin_ids = [ + 'string_id' => [ + 'type' => 'string', + 'max_length' => 128, + 'is_ascii' => TRUE, + 'alias' => 'wpt', + ], + 'integer_id' => [ + 'type' => 'integer', + 'unsigned' => FALSE, + 'alias' => 'wpt', + ], + ]; + + $stub_row = new Row(['string_id' => 'example_string', 'integer_id' => 99], $source_plugin_ids, TRUE); + $destination_plugin->import($stub_row)->willReturn([2]); + + $source_plugin->getIds()->willReturn($source_plugin_ids); + + $configuration = [ + 'migration' => 'foobaz', + 'source_ids' => ['foobaz' => ['string_id', 'integer_id']], + ]; + $migration = new MigrationLookup($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); + $result = $migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo'); + $this->assertEquals(2, $result); + } + }