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\MigrateSourcePluginManager $plugin_manager */
35 $plugin_manager = $this->container->get('plugin.manager.migrate.source');
37 foreach ($plugin_manager->getDefinitions() as $definition) {
38 $id = $definition['id'];
39 $this->assertArrayHasKey('source_module', $definition, "No source_module property in '$id'");
44 * Enable all available modules.
46 protected function enableAllModules() {
47 // Install all available modules.
48 $module_handler = $this->container->get('module_handler');
49 $modules = $this->coreModuleListDataProvider();
50 $modules_enabled = $module_handler->getModuleList();
51 $modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled));
52 $this->enableModules($modules_to_enable);
56 * Tests that modules exist for all field plugins.
58 public function testFieldProvidersExist() {
59 $expected_mappings = [
61 'source_module' => 'userreference',
62 'destination_module' => 'core',
65 'source_module' => 'nodereference',
66 'destination_module' => 'core',
69 'source_module' => 'optionwidgets',
70 'destination_module' => 'options',
73 'source_module' => 'list',
74 'destination_module' => 'options',
77 'source_module' => 'options',
78 'destination_module' => 'options',
81 'source_module' => 'filefield',
82 'destination_module' => 'file',
85 'source_module' => 'imagefield',
86 'destination_module' => 'image',
89 'source_module' => 'file',
90 'destination_module' => 'file',
93 'source_module' => 'image',
94 'destination_module' => 'image',
97 'source_module' => 'phone',
98 'destination_module' => 'telephone',
101 'source_module' => 'link',
102 'destination_module' => 'link',
105 'source_module' => 'link',
106 'destination_module' => 'link',
109 'source_module' => 'text',
110 'destination_module' => 'text',
113 'source_module' => 'text',
114 'destination_module' => 'text',
116 'taxonomy_term_reference' => [
117 'source_module' => 'taxonomy',
118 'destination_module' => 'core',
121 'source_module' => 'date',
122 'destination_module' => 'datetime',
125 'source_module' => 'date',
126 'destination_module' => 'datetime',
129 'source_module' => 'email',
130 'destination_module' => 'core',
132 'number_default' => [
133 'source_module' => 'number',
134 'destination_module' => 'core',
136 'entityreference' => [
137 'source_module' => 'entityreference',
138 'destination_module' => 'core',
141 $this->enableAllModules();
143 $definitions = $this->container->get('plugin.manager.migrate.field')->getDefinitions();
144 foreach ($definitions as $key => $definition) {
145 $this->assertArrayHasKey($key, $expected_mappings);
146 $this->assertEquals($expected_mappings[$key]['source_module'], $definition['source_module']);
147 $this->assertEquals($expected_mappings[$key]['destination_module'], $definition['destination_module']);
152 * Test a missing required definition.
154 * @param array $definitions
155 * A field plugin definition.
156 * @param string $missing_property
157 * The name of the property missing from the definition.
159 * @dataProvider fieldPluginDefinitionsProvider
161 public function testFieldProviderMissingRequiredProperty(array $definitions, $missing_property) {
162 $discovery = $this->getMockBuilder(MigrateFieldPluginManager::class)
163 ->disableOriginalConstructor()
164 ->setMethods(['getDefinitions'])
166 $discovery->method('getDefinitions')
167 ->willReturn($definitions);
169 $plugin_manager = $this->getMockBuilder(MigrateFieldPluginManager::class)
170 ->disableOriginalConstructor()
171 ->setMethods(['getDiscovery'])
173 $plugin_manager->method('getDiscovery')
174 ->willReturn($discovery);
176 $this->setExpectedException(BadPluginDefinitionException::class, "The missing_{$missing_property} plugin must define the $missing_property property.");
177 $plugin_manager->getDefinitions();
181 * Data provider for field plugin definitions.
184 * Array of plugin definitions.
186 public function fieldPluginDefinitionsProvider() {
188 'missing_core_scenario' => [
191 'source_module' => 'migrate',
192 'destination_module' => 'migrate',
193 'id' => 'missing_core',
198 'missing_property' => 'core',
200 'missing_source_scenario' => [
202 'missing_source_module' => [
204 'destination_module' => 'migrate',
205 'id' => 'missing_source_module',
210 'missing_property' => 'source_module',
212 'missing_destination_scenario' => [
214 'missing_destination_module' => [
216 'source_module' => 'migrate',
217 'id' => 'missing_destination_module',
222 'missing_property' => 'destination_module',