/** * Tests Migration::set(). * * @covers ::set */ public function testSetInvalidation() { $migration = new Migration([], uniqid(), ['source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'entity:entity_view_mode']]); $this->assertEqual('empty', $migration->getSourcePlugin()->getPluginId()); $this->assertEqual('entity:entity_view_mode', $migration->getDestinationPlugin()->getPluginId()); // Test the source plugin is invalidated. $migration->set('source', ['plugin' => 'd6_field']); $this->assertEqual('d6_field', $migration->getSourcePlugin()->getPluginId()); // Test the destination plugin is invalidated. $migration->set('destination', ['plugin' => 'null']); $this->assertEqual('null', $migration->getDestinationPlugin()->getPluginId()); }
/** * {@inheritdoc} */ public function getProcess() { if (!$this->init) { $this->init = TRUE; $definition['source'] = ['entity_type' => 'user', 'ignore_map' => TRUE] + $this->source; $definition['destination']['plugin'] = 'null'; if (\Drupal::moduleHandler()->moduleExists('field')) { $definition['source']['plugin'] = 'd7_field_instance'; $field_migration = new Migration([], uniqid(), $definition); foreach ($field_migration->getSourcePlugin() as $row) { $field_name = $row->getSourceProperty('field_name'); $this->process[$field_name] = $field_name; } } try { $definition['source']['plugin'] = 'profile_field'; $profile_migration = new Migration([], uniqid(), $definition); // Ensure that Profile is enabled in the source DB. $profile_migration->checkRequirements(); foreach ($profile_migration->getSourcePlugin() as $row) { $name = $row->getSourceProperty('name'); $this->process[$name] = $name; } } catch (RequirementsException $e) { // The checkRequirements() call will fail when the profile module does // not exist on the source site. } } return parent::getProcess(); }
/** * Tests the embedded_data source plugin. */ public function testEmbeddedData() { $data_rows = [['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'], ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2']]; $ids = ['key' => ['type' => 'integer']]; $definition = ['migration_tags' => ['Embedded data test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $data_rows, 'ids' => $ids], 'process' => [], 'destination' => ['plugin' => 'null']]; $migration = new Migration([], uniqid(), $definition); $source = $migration->getSourcePlugin(); // Validate the plugin returns the source data that was provided. $results = []; /** @var \Drupal\migrate\Row $row */ foreach ($source as $row) { $data_row = $row->getSource(); // The "data" row returned by getSource() also includes all source // configuration - we remove it so we see only the data itself. unset($data_row['plugin']); unset($data_row['data_rows']); unset($data_row['ids']); $results[] = $data_row; } $this->assertIdentical($results, $data_rows); // Validate the public APIs. $this->assertIdentical($source->count(), count($data_rows)); $this->assertIdentical($source->getIds(), $ids); $expected_fields = ['key' => 'key', 'field1' => 'field1', 'field2' => 'field2']; $this->assertIdentical($source->fields(), $expected_fields); }
/** * {@inheritdoc} */ public function getProcess() { if (!$this->init) { $this->init = TRUE; $definition['source'] = ['plugin' => 'profile_field', 'ignore_map' => TRUE] + $this->source; $definition['destination']['plugin'] = 'null'; try { $profile_field_migration = new Migration([], uniqid(), $definition); $source_plugin = $profile_field_migration->getSourcePlugin(); $source_plugin->checkRequirements(); foreach ($source_plugin as $row) { $name = $row->getSourceProperty('name'); $this->process[$name] = $name; } } catch (RequirementsException $e) { // The checkRequirements() call will fail when the profile module does // not exist on the source site. } } return parent::getProcess(); }