3 namespace Drupal\Tests\migrate\Kernel\Plugin;
5 use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
6 use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException;
7 use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager;
8 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
11 * Tests that modules exist for all source and destination plugins.
13 * @group migrate_drupal_ui
15 class MigrationProvidersExistTest extends MigrateDrupalTestBase {
17 use FileSystemModuleDiscoveryDataProviderTrait;
20 * Tests that a missing source_module property raises an exception.
22 public function testSourceProvider() {
23 $this->enableModules(['migration_provider_test']);
24 $this->setExpectedException(BadPluginDefinitionException::class, 'The no_source_module plugin must define the source_module property.');
25 $this->container->get('plugin.manager.migration')->getDefinition('migration_provider_no_annotation');
29 * Tests that modules exist for all source plugins.
31 public function testProvidersExist() {
32 $this->enableAllModules();
34 /** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
35 $plugin_manager = $this->container->get('plugin.manager.migration');
37 // Instantiate all migrations.
38 $migrations = array_keys($plugin_manager->getDefinitions());
39 $migrations = $plugin_manager->createInstances($migrations);
41 /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
42 foreach ($migrations as $migration) {
43 $this->assertInternalType('string', $migration->getSourcePlugin()->getSourceModule());
48 * Enable all available modules.
50 protected function enableAllModules() {
51 // Install all available modules.
52 $module_handler = $this->container->get('module_handler');
53 $modules = $this->coreModuleListDataProvider();
54 $modules_enabled = $module_handler->getModuleList();
55 $modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled));
56 $this->enableModules($modules_to_enable);
60 * Tests that modules exist for all field plugins.
62 public function testFieldProvidersExist() {
63 $expected_mappings = [
65 'source_module' => 'userreference',
66 'destination_module' => 'core',
69 'source_module' => 'nodereference',
70 'destination_module' => 'core',
73 'source_module' => 'optionwidgets',
74 'destination_module' => 'options',
77 'source_module' => 'list',
78 'destination_module' => 'options',
81 'source_module' => 'options',
82 'destination_module' => 'options',
85 'source_module' => 'filefield',
86 'destination_module' => 'file',
89 'source_module' => 'imagefield',
90 'destination_module' => 'image',
93 'source_module' => 'file',
94 'destination_module' => 'file',
97 'source_module' => 'image',
98 'destination_module' => 'image',
101 'source_module' => 'phone',
102 'destination_module' => 'telephone',
105 'source_module' => 'link',
106 'destination_module' => 'link',
109 'source_module' => 'link',
110 'destination_module' => 'link',
113 'source_module' => 'text',
114 'destination_module' => 'text',
117 'source_module' => 'text',
118 'destination_module' => 'text',
120 'taxonomy_term_reference' => [
121 'source_module' => 'taxonomy',
122 'destination_module' => 'core',
125 'source_module' => 'date',
126 'destination_module' => 'datetime',
129 'source_module' => 'date',
130 'destination_module' => 'datetime',
133 'source_module' => 'email',
134 'destination_module' => 'core',
136 'number_default' => [
137 'source_module' => 'number',
138 'destination_module' => 'core',
140 'entityreference' => [
141 'source_module' => 'entityreference',
142 'destination_module' => 'core',
145 $this->enableAllModules();
147 $definitions = $this->container->get('plugin.manager.migrate.field')->getDefinitions();
148 foreach ($definitions as $key => $definition) {
149 $this->assertArrayHasKey($key, $expected_mappings);
150 $this->assertEquals($expected_mappings[$key]['source_module'], $definition['source_module']);
151 $this->assertEquals($expected_mappings[$key]['destination_module'], $definition['destination_module']);
156 * Test a missing required definition.
158 * @param array $definitions
159 * A field plugin definition.
160 * @param string $missing_property
161 * The name of the property missing from the definition.
163 * @dataProvider fieldPluginDefinitionsProvider
165 public function testFieldProviderMissingRequiredProperty(array $definitions, $missing_property) {
166 $discovery = $this->getMockBuilder(MigrateFieldPluginManager::class)
167 ->disableOriginalConstructor()
168 ->setMethods(['getDefinitions'])
170 $discovery->method('getDefinitions')
171 ->willReturn($definitions);
173 $plugin_manager = $this->getMockBuilder(MigrateFieldPluginManager::class)
174 ->disableOriginalConstructor()
175 ->setMethods(['getDiscovery'])
177 $plugin_manager->method('getDiscovery')
178 ->willReturn($discovery);
180 $this->setExpectedException(BadPluginDefinitionException::class, "The missing_{$missing_property} plugin must define the $missing_property property.");
181 $plugin_manager->getDefinitions();
185 * Data provider for field plugin definitions.
188 * Array of plugin definitions.
190 public function fieldPluginDefinitionsProvider() {
192 'missing_core_scenario' => [
195 'source_module' => 'migrate',
196 'destination_module' => 'migrate',
197 'id' => 'missing_core',
202 'missing_property' => 'core',
204 'missing_source_scenario' => [
206 'missing_source_module' => [
208 'destination_module' => 'migrate',
209 'id' => 'missing_source_module',
214 'missing_property' => 'source_module',
216 'missing_destination_scenario' => [
218 'missing_destination_module' => [
220 'source_module' => 'migrate',
221 'id' => 'missing_destination_module',
226 'missing_property' => 'destination_module',