diff -u b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php --- b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php @@ -8,13 +8,13 @@ /** * @MigrateField( - * id = "imagefield", + * id = "filefield", * core = {6}, - * source_module = "imagefield", + * source_module = "filefield", * destination_module = "file" * ) */ -class ImageField extends FieldPluginBase { +class FileField extends FieldPluginBase { /** * {@inheritdoc} diff -u b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php --- b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php @@ -62,7 +62,7 @@ foreach (['core', 'source_module', 'destination_module'] as $required_property) { if (empty($definition[$required_property])) { - throw new InvalidPluginDefinitionException($plugin_id, sprintf('The %s plugin should define the %s property.', $definition['class'], $required_property)); + throw new InvalidPluginDefinitionException($plugin_id, sprintf('The %s plugin should define the %s property.', $definition['id'], $required_property)); } } } only in patch2: unchanged: --- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php @@ -2,8 +2,10 @@ namespace Drupal\Tests\migrate\Kernel\Plugin; +use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; /** @@ -61,4 +63,180 @@ public function testProvidersExist() { } } + public function testFieldProvidersExist() { + $expected_mappings = [ + 'userreference' => [ + 'source_module' => 'user_reference', + 'destination_module' => 'entity_reference', + ], + 'nodereference' => [ + 'source_module' => 'node_reference', + 'destination_module' => 'entity_reference', + ], + 'optionwidgets' => [ + 'source_module' => 'optionwidgets', + 'destination_module' => 'options', + ], + 'list' => [ + 'source_module' => 'list', + 'destination_module' => 'options', + ], + 'options' => [ + 'source_module' => 'options', + 'destination_module' => 'options', + ], + 'filefield' => [ + 'source_module' => 'filefield', + 'destination_module' => 'file', + ], + 'imagefield' => [ + 'source_module' => 'imagefield', + 'destination_module' => 'file', + ], + 'file' => [ + 'source_module' => 'file', + 'destination_module' => 'file', + ], + 'image' => [ + 'source_module' => 'image', + 'destination_module' => 'file', + ], + 'phone' => [ + 'source_module' => 'phone', + 'destination_module' => 'telephone', + ], + 'link' => [ + 'source_module' => 'link', + 'destination_module' => 'link', + ], + 'link_field' => [ + 'source_module' => 'link', + 'destination_module' => 'link', + ], + 'd6_text' => [ + 'source_module' => 'text', + 'destination_module' => 'text', + ], + 'd7_text' => [ + 'source_module' => 'text', + 'destination_module' => 'text', + ], + 'taxonomy_term_reference' => [ + 'source_module' => 'taxonomy', + 'destination_module' => 'entity_reference', + ], + 'date' => [ + 'source_module' => 'date', + 'destination_module' => 'datetime', + ], + 'datetime' => [ + 'source_module' => 'date', + 'destination_module' => 'datetime', + ], + 'email' => [ + 'source_module' => 'email', + 'destination_module' => 'core', + ], + 'number_default' => [ + 'source_module' => 'number', + 'destination_module' => 'core', + ], + 'entityreference' => [ + 'source_module' => 'entityreference', + 'destination_module' => 'core', + ], + ]; + // Install all available modules. + $module_handler = $this->container->get('module_handler'); + $modules = $this->coreModuleListDataProvider(); + $modules_enabled = $module_handler->getModuleList(); + $modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled)); + $this->enableModules($modules_to_enable); + + /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $plugin_manager */ + $plugin_manager = $this->container->get('plugin.manager.migrate.field'); + $definitions = $plugin_manager->getDefinitions(); + foreach ($definitions as $key => $definition) { + $this->assertEquals($expected_mappings[$key]['source_module'], $definition['source_module']); + $this->assertEquals($expected_mappings[$key]['destination_module'], $definition['destination_module']); + unset($definitions[$key]); + } + // Make sure we test all the fields. + $this->assertEmpty($definitions); + } + + /** + * Test a missing required definition. + * + * @dataProvider fieldPluginDefinitionsProvider + */ + public function testFieldProviderMissingRequiredProperty($definitions, $missing_property) { + $mock_discovery = $this->getMockBuilder(MigrateFieldPluginManager::class) + ->disableOriginalConstructor() + ->setMethods(['getDefinitions']) + ->getMock(); + $mock_discovery->method('getDefinitions') + ->willReturn($definitions); + $mock_plugin_manager = $this->getMockBuilder(MigrateFieldPluginManager::class) + ->disableOriginalConstructor() + ->setMethods(['getDiscovery']) + ->getMock(); + $mock_plugin_manager->method('getDiscovery') + ->willReturn($mock_discovery); + $this->setExpectedException(InvalidPluginDefinitionException::class, "The missing_{$missing_property} plugin should define the $missing_property property."); + $mock_plugin_manager->getDefinitions(); + } + + /** + * Data provider for field plugin definitions. + * + * @return array + */ + public function fieldPluginDefinitionsProvider() { + return [ + 'missing_core_scenario' => [ + 'definitions' => [ + 'missing_core' => [ + 'source_module' => 'migrate', + 'destination_module' => 'migrate', + 'id' => 'missing_core', + 'class' => 'foo', + 'provider' => 'foo', + ], + ], + 'missing_property' => 'core', + ], + 'missing_source_scenario' => [ + 'definitions' => [ + 'missing_source_module' => [ + 'core' => [ + 0 => 6, + 1 => 7, + ], + 'destination_module' => 'migrate', + 'id' => 'missing_source_module', + 'class' => 'foo', + 'provider' => 'foo', + ], + ], + 'missing_property' => 'source_module', + ], + 'missing_destination_scenario' => [ + 'definitions' => [ + 'missing_destination_module' => [ + 'core' => [ + 0 => 6, + 1 => 7, + ], + 'source_module' => 'migrate', + 'id' => 'missing_destination_module', + 'class' => 'foo', + 'provider' => 'foo', + ], + ], + 'missing_property' => 'destination_module', + ], + ]; + } + }