diff -u b/core/modules/migrate/config/migrate.migration.d6_system_site.yml b/core/modules/migrate/config/migrate.migration.d6_system_site.yml --- b/core/modules/migrate/config/migrate.migration.d6_system_site.yml +++ b/core/modules/migrate/config/migrate.migration.d6_system_site.yml @@ -3,38 +3,24 @@ - plugin: drupal6_variable - variables: - - site_name - - site_mail - - site_slogan - - site_frontpage - - site_403 - - site_404 - - drupal_weight_select_max - - admin_compact_mode + plugin: drupal6_variable + variables: + - site_name + - site_mail + - site_slogan + - site_frontpage + - site_403 + - site_404 + - drupal_weight_select_max + - admin_compact_mode process: - - - source: site_name - destination: name - - - source: site_mail - destination: mail - - - source: site_slogan - destination: slogan - - - source: site_frontpage - destination: page:front - - - source: site_403 - destination: page:403 - - - source: site_404 - destination: page:404 - - - source: drupal_weight_select_max - destination: weight_select_max - - - source: admin_compact_mode - destination: admin_compact_mode + - + plugin: copy_from_source + site_name: name + site_mail: mail + site_slogan: slogan + site_frontpage: 'page:front' + site_403: 'page:403' + site_404: 'page:404' + drupal_weight_select_max: weight_select_max + admin_compact_mode: admin_compact_mode destination: - plugin: d8_config - config_name: system.site + plugin: d8_config + config_name: system.site diff -u b/core/modules/migrate/lib/Drupal/migrate/Entity/Migration.php b/core/modules/migrate/lib/Drupal/migrate/Entity/Migration.php --- b/core/modules/migrate/lib/Drupal/migrate/Entity/Migration.php +++ b/core/modules/migrate/lib/Drupal/migrate/Entity/Migration.php @@ -8,13 +8,15 @@ namespace Drupal\migrate\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; -use Drupal\Core\Database\Database; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrateProcessBag; /** * Defines the Migration entity. * + * The migration entity stores the information about a single migration, like + * the source, process and destination plugins. + * * @EntityType( * id = "migration", * label = @Translation("Migration"), @@ -128,6 +130,15 @@ * @var array */ public $sourceIds = array(); + + /** + * The destination identifiers. + * + * An array of destination identifiers: the keys are the name of the + * properties, the values are dependent on the id map plugin. + * + * @var array + */ public $destinationIds = array(); /** @@ -178,7 +189,7 @@ } /** - * @return \Drupal\migrate\Plugin\MigrateProcessBag + * {@inheritdoc} */ public function getProcess() { if (!$this->migrateProcessBag) { @@ -188,7 +199,7 @@ } /** - * @return \Drupal\migrate\Plugin\MigrateDestinationInterface + * {@inheritdoc} */ public function getDestination() { if (!isset($this->destinationPlugin)) { @@ -198,7 +209,7 @@ } /** - * @return \Drupal\migrate\Plugin\MigrateIdMapInterface + * {@inheritdoc} */ public function getIdMap() { if (!isset($this->idMapPlugin)) { @@ -212,7 +223,7 @@ /** * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface */ - protected function getHigherWaterStorage() { + protected function getHighWaterStorage() { if (!isset($this->highwaterStorage)) { $this->highwaterStorage = \Drupal::keyValue('migrate:highwater'); } @@ -221,9 +232,9 @@ public function getHighwater() { - return $this->getHigherWaterStorage()->get($this->id()); + return $this->getHighWaterStorage()->get($this->id()); } public function saveHighwater($highwater) { - $this->getHigherWaterStorage()->set($this->id(), $highwater); + $this->getHighWaterStorage()->set($this->id(), $highwater); } } diff -u b/core/modules/migrate/lib/Drupal/migrate/Entity/MigrationInterface.php b/core/modules/migrate/lib/Drupal/migrate/Entity/MigrationInterface.php --- b/core/modules/migrate/lib/Drupal/migrate/Entity/MigrationInterface.php +++ b/core/modules/migrate/lib/Drupal/migrate/Entity/MigrationInterface.php @@ -13,8 +13,10 @@ * Interface for migrations. */ interface MigrationInterface extends ConfigEntityInterface { + const SOURCE = 'source'; const DESTINATION = 'destination'; + /** * Codes representing the current status of a migration, and stored in the * migrate_status table. @@ -27,9 +29,9 @@ /** * Message types to be passed to saveMessage() and saved in message tables. - * MESSAGE_INFORMATIONAL represents a condition that did not prevent the operation - * from succeeding - all others represent different severities of conditions - * resulting in a source record not being imported. + * MESSAGE_INFORMATIONAL represents a condition that did not prevent the + * operation from succeeding - all others represent different severities of + * conditions resulting in a source record not being imported. */ const MESSAGE_ERROR = 1; const MESSAGE_WARNING = 2; @@ -49,21 +51,29 @@ const RESULT_DISABLED = 6; // This migration is disabled, skipping /** + * Returns the initialized source plugin. + * * @return \Drupal\migrate\Plugin\MigrateSourceInterface */ public function getSource(); /** + * Returns the initialized process plugin. + * * @return \Drupal\migrate\Plugin\MigrateProcessBag */ public function getProcess(); /** + * Returns the initialized destination plugin. + * * @return \Drupal\migrate\Plugin\MigrateDestinationInterface */ public function getDestination(); /** + * Returns the initialized id_map plugin. + * * @return \Drupal\migrate\Plugin\MigrateIdMapInterface */ public function getIdMap(); @@ -76,2 +86,3 @@ public function saveHighwater($highwater); + } diff -u b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php --- b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php +++ b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php @@ -66,6 +66,13 @@ protected $processed_since_feedback = 0; /** + * The translation manager. + * + * @var \Drupal\Core\StringTranslation\TranslationInterface + */ + protected $translationManager; + + /** * @param MigrationInterface $migration * @param MigrateMessageInterface $message * @@ -92,7 +99,7 @@ $limit *= 1024; break; default: - throw new MigrateException(t('Invalid PHP memory_limit !limit', + throw new MigrateException($this->t('Invalid PHP memory_limit !limit', array('!limit' => $limit))); } } @@ -158,7 +165,7 @@ } catch (\Exception $e) { $this->message->display( - t('Migration failed with source plugin exception: !e', + $this->t('Migration failed with source plugin exception: !e', array('!e' => $e->getMessage()))); return MigrationInterface::RESULT_FAILED; } @@ -182,7 +189,7 @@ else { $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); if ($id_map->messageCount() == 0) { - $message = t('New object was not saved, no error provided'); + $message = $this->t('New object was not saved, no error provided'); $this->saveMessage($message); $this->message->display($message); } @@ -227,7 +234,7 @@ } catch (\Exception $e) { $this->message->display( - t('Migration failed with source plugin exception: !e', + $this->t('Migration failed with source plugin exception: !e', array('!e' => $e->getMessage()))); return MigrationInterface::RESULT_FAILED; } @@ -365,7 +372,7 @@ $pct_memory = $usage / $this->memoryLimit; if ($pct_memory > $this->memoryThreshold) { $this->message->display( - t('Memory usage is !usage (!pct% of limit !limit), resetting statics', + $this->t('Memory usage is !usage (!pct% of limit !limit), resetting statics', array('!pct' => round($pct_memory*100), '!usage' => format_size($usage), '!limit' => format_size($this->memoryLimit))), @@ -379,7 +386,7 @@ // coming back here and trimming a tiny amount if ($pct_memory > (.90 * $this->memoryThreshold)) { $this->message->display( - t('Memory usage is now !usage (!pct% of limit !limit), not enough reclaimed, starting new batch', + $this->t('Memory usage is now !usage (!pct% of limit !limit), not enough reclaimed, starting new batch', array('!pct' => round($pct_memory*100), '!usage' => format_size($usage), '!limit' => format_size($this->memoryLimit))), @@ -388,7 +395,7 @@ } else { $this->message->display( - t('Memory usage is now !usage (!pct% of limit !limit), reclaimed enough, continuing', + $this->t('Memory usage is now !usage (!pct% of limit !limit), reclaimed enough, continuing', array('!pct' => round($pct_memory*100), '!usage' => format_size($usage), '!limit' => format_size($this->memoryLimit))), @@ -442,2 +449,23 @@ + /** + * Translates a string to the current language or to a given language. + * + * See the t() documentation for details. + */ + protected function t($string, array $args = array(), array $options = array()) { + return $this->translationManager()->translate($string, $args, $options); + } + + /** + * Gets the translation manager. + * + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The translation manager. + */ + protected function translationManager() { + if (!$this->translationManager) { + $this->translationManager = \Drupal::translation(); + } + return $this->translationManager; + } } diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php @@ -147,12 +147,12 @@ * Given a (possibly multi-field) source key, return the (possibly multi-field) * destination key it is mapped to. * - * @param array $source_id - * Array of source key values. + * @param array $source_id_values + * Array of source identifier values. * @return array * Array of destination key values, or NULL on failure. */ - public function lookupDestinationID(array $source_id); + public function lookupDestinationID(array $source_id_values); /** * Remove any persistent storage used by this map (e.g., map and message tables) diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php @@ -12,19 +12,40 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\migrate\Entity\MigrationInterface; +/** + * Contains all active process plugins on a migration. + */ class MigrateProcessBag extends DefaultPluginBag { /** + * The migration entity this process bag is attached to. + * * @var \Drupal\migrate\Entity\MigrationInterface */ protected $migration; + /** + * The key within the plugin configuration that contains the plugin ID. + * + * @var string + */ protected $pluginKey = 'plugin'; /** - * @param PluginManagerInterface $manager + * @var \Drupal\migrate\Plugin\MigratePluginManager + */ + protected $manager; + + /** + * Constructs a new MigrateProcessBag. + * + * @param \Drupal\Component\Plugin\PluginManagerInterface $manager + * The plugin manager to initialize process plugins. * @param array $configurations - * @param MigrationInterface $migration + * (optional) An associative array containing the initial configuration for + * each plugin in the bag, keyed by plugin instance ID. + * @param \Drupal\migrate\Entity\MigrationInterface $migration + * The migration entity this process bag is attached to. */ public function __construct(PluginManagerInterface $manager, array $configurations = array(), MigrationInterface $migration) { parent::__construct($manager, $configurations); @@ -34,22 +55,17 @@ /** * {@inheritdoc} * - * @return \Drupal\migrate\Plugin\ProcessInterface - */ - public function &get($instance_id) { - return parent::get($instance_id); - } - - /** - * {@inheritdoc} + * Extends in order to pass the migration entity to the plugin manager. */ public function initializePlugin($instance_id) { - $this->configurations[$instance_id] += array('plugin' => 'property_map'); + $this->configurations[$instance_id] += array('plugin' => 'copy_from_source'); $configuration = isset($this->configurations[$instance_id]) ? $this->configurations[$instance_id] : array(); if (!isset($configuration[$this->pluginKey])) { throw new UnknownPluginException($instance_id); } - $this->pluginInstances[$instance_id] = $this->manager->createInstance($configuration[$this->pluginKey], $configuration, $this->migration); + $plugin_key = $configuration[$this->pluginKey]; + unset($configuration[$this->pluginKey]); + $this->pluginInstances[$instance_id] = $this->manager->createInstance($plugin_key, $configuration, $this->migration); $this->addInstanceID($instance_id); } diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php @@ -7,7 +7,8 @@ namespace Drupal\migrate\Plugin\migrate\id_map; -use Drupal\Core\Database\Database; +use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateMessageInterface; @@ -16,6 +17,11 @@ use Drupal\migrate\Row; /** + * Defines the sql based ID map implementation. + * + * It creates one map and one message table per migration entity to store the + * relevant information. + * * @PluginID("sql") */ class Sql extends PluginBase implements MigrateIdMapInterface { @@ -40,6 +46,8 @@ } /** + * The database connection for the map/message tables on the destination. + * * @var \Drupal\Core\Database\Connection */ protected $database; @@ -86,7 +94,9 @@ } /** - * We don't need to check the tables more than once per request. + * Stores whether the the tables (map/message) already exist. + * + * This is determined just once per request/instance of the class. * * @var boolean */ @@ -94,19 +104,20 @@ public function __construct($configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->migration = $migration; $machine_name = $migration->id(); - // Default generated table names, limited to 63 characters + // Default generated table names, limited to 63 characters. $prefixLength = strlen($this->getDatabase()->tablePrefix()) ; - $this->mapTable = 'migrate_map_' . drupal_strtolower($machine_name); - $this->mapTable = drupal_substr($this->mapTable, 0, 63 - $prefixLength); - $this->messageTable = 'migrate_message_' . drupal_strtolower($machine_name); - $this->messageTable = drupal_substr($this->messageTable, 0, 63 - $prefixLength); + $this->mapTable = 'migrate_map_' . Unicode::strtolower($machine_name); + $this->mapTable = Unicode::substr($this->mapTable, 0, 63 - $prefixLength); + $this->messageTable = 'migrate_message_' . Unicode::strtolower($machine_name); + $this->messageTable = Unicode::substr($this->messageTable, 0, 63 - $prefixLength); $this->sourceIds = $migration->get('sourceIds'); $this->destinationIds = $migration->get('destinationIds'); - // Build the source and destination key maps + // Build the source and destination key maps. $this->sourceIdFields = array(); $count = 1; foreach ($this->sourceIds as $field => $schema) { @@ -124,6 +135,9 @@ return SqlBase::getDatabaseConnection($this->migration->id(), $this->configuration); } + /** + * {@inheritdoc} + */ public function setMessage(MigrateMessageInterface $message) { $this->message = $message; } @@ -252,9 +266,13 @@ } /** - * Retrieve a row from the map table, given a source ID + * Retrieve a row from the map table, given a source ID. * * @param array $source_id + * A list of source IDs, even there is just one source ID. + * + * @return array + * The raw row data as associative array. */ public function getRowBySource(array $source_id) { $query = $this->getDatabase()->select($this->mapTable, 'map') @@ -270,6 +288,7 @@ * Retrieve a row from the map table, given a destination ID * * @param array $destination_id + * A list of destination IDs, even there is just one destination ID. * * @return mixed * The row(s) of data reverted: --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/PropertyMap.php +++ /dev/null @@ -1,180 +0,0 @@ -configuration['source']) && $row->hasSourceProperty($this->configuration['source'])) { - $destination_values = $row->getSourceProperty($this->configuration['source']); - } - // Otherwise, apply the default value (if any) - elseif (isset($this->configuration['default'])) { - $destination_values = $this->configuration['default']; - } - - // If there's a separator specified for this destination, then it - // will be populated as an array exploded from the source value - if (!empty($this->configuration['separator']) && isset($destination_values)) { - $destination_values = explode($this->configuration['separator'], $destination_values); - } - - // If a source migration is supplied, use the current value for this property - // to look up a destination ID from the provided migration - if (!empty($this->configuration['source_migration']) && isset($destination_values)) { - $destination_values = $migrate_executable->handleSourceMigration($this->configuration['source_migration'], $destination_values, $this->configuration['default'], $this); - } - - // Call any designated callbacks - if (!empty($this->configuration['callbacks'])) { - foreach ($this->callbacks as $callback) { - if (isset($destination_values) && is_callable($callback)) { - $destination_values = call_user_func($callback, $destination_values); - } - } - } - - // If specified, assure a unique value for this property. - if (!empty($this->configuration['dedupe'])&& isset($destination_values)) { - $destination_values = $migrate_executable->handleDedupe($this->configuration['dedupe'], $destination_values); - } - - // Store the destination together with possible configuration. - if (isset($destination_values)) { - $keys = explode(':', $this->configuration['destination']); - $row->setDestinationPropertyDeep($keys, $destination_values); - } - } -} diff -u b/core/modules/migrate/lib/Drupal/migrate/Row.php b/core/modules/migrate/lib/Drupal/migrate/Row.php --- b/core/modules/migrate/lib/Drupal/migrate/Row.php +++ b/core/modules/migrate/lib/Drupal/migrate/Row.php @@ -16,18 +16,18 @@ class Row { /** + * The actual values of the source row. + * * @var array */ protected $source = array(); /** - * The value of the source identifiers. - * - * This is a subset of the $source array. + * The source identifiers. * * @var array */ - protected $sourceIdValues = array(); + protected $sourceIds = array(); /** * The destination values. @@ -57,24 +57,25 @@ protected $frozen = FALSE; /** - * Constructs a Migrate>Row object. + * Constructs a \Drupal\Migrate\Row object. * + * @param array $values + * An array of values to add as properties on the object. * @param array $source_ids * An array containing the ids of the source using the keys as the field * names. - * @param array $values - * An array of values to add as properties on the object. + * @param array $destination_ids + * An array containing the ids of the destination using the keys as the field + * names. * * @throws \InvalidArgumentException * Thrown when a source id property does not exist. */ - public function __construct(array $source_ids, array $values) { + public function __construct(array $values, array $source_ids) { $this->source = $values; + $this->sourceIds = $source_ids; foreach (array_keys($source_ids) as $id) { - if ($this->hasSourceProperty($id)) { - $this->sourceIdValues[$id] = $values[$id]; - } - else { + if (!$this->hasSourceProperty($id)) { throw new \InvalidArgumentException("$id has no value"); } } @@ -87,7 +88,7 @@ * An array containing the values of the source identifiers. */ public function getSourceIdValues() { - return $this->sourceIdValues; + return array_intersect_key($this->source, $this->sourceIds); } /** @@ -155,50 +156,43 @@ } /** - * Determines whether a destination has a property. - * - * @param string $property - * A property on the destination. - * - * @return bool - * TRUE if the destination has property; FALSE otherwise. + * @param array $property_keys + * An array of properties on the destination. */ public function hasDestinationProperty($property) { - return isset($this->destination[$property]) || array_key_exists($property, $this->destination); + return NestedArray::keyExists($this->destination, explode(':', $property)); } /** - * Sets a destination property. + * Sets destination properties. * * @param string $property - * A property on the destination. + * The name of the destination property. * @param mixed $value * The property value to set on the destination. */ public function setDestinationProperty($property, $value) { - $this->destination[$property] = $value; + NestedArray::setValue($this->destination, explode(':', $property), $value, TRUE); } /** - * Sets destination properties. + * This returns the whole destination array. * - * @param array $property_keys - * An array of properties on the destination. - * @param mixed $value - * The property value to set on the destination. + * @return array + * An array of destination values. */ - public function setDestinationPropertyDeep(array $property_keys, $value) { - NestedArray::setValue($this->destination, $property_keys, $value, TRUE); + public function getDestination() { + return $this->destination; } /** - * This returns the whole destination array. + * Return a the value of a destination property. * - * @return array - * An array of destination plugins. + * @return mixed + * The destination value. */ - public function getDestination() { - return $this->destination; + public function getDestinationProperty($property) { + return NestedArray::getValue($this->destination, explode(':', $property)); } /** diff -u b/core/modules/migrate/lib/Drupal/migrate/Source.php b/core/modules/migrate/lib/Drupal/migrate/Source.php --- b/core/modules/migrate/lib/Drupal/migrate/Source.php +++ b/core/modules/migrate/lib/Drupal/migrate/Source.php @@ -11,10 +11,12 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface; /** - * A base class for migrate sources. + * Source is a caching / decision making wrapper around the source plugin. * * Derived classes are expected to define __toString(), returning a string * describing the source and significant options, i.e. the query. + * + * @see \Drupal\migrate\MigrateSourceInterface */ class Source implements \Iterator, \Countable { @@ -272,7 +274,7 @@ while ($this->getIterator()->valid()) { $row_data = $this->getIterator()->current(); $this->getIterator()->next(); - $row = new Row($this->migration->get('sourceIds'), $row_data); + $row = new Row($row_data, $this->migration->get('sourceIds'), $this->migration->get('destinationIds')); // Populate the source key for this row $this->currentIds = $row->getSourceIdValues(); diff -u b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php --- b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php @@ -70,23 +70,6 @@ } /** - * Sets attribute values for a source test. - * - * @param object $object - * The destination of the written attribute value. - * @param string $attribute_name - * The name of the attribute to write. - * @param mixed $value - * The value of the written attribute. - */ - protected function writeAttribute($object, $attribute_name, $value) { - $reflection = new \ReflectionClass($object); - $reflection_property = $reflection->getProperty($attribute_name); - $reflection_property->setAccessible(TRUE); - $reflection_property->setValue($object, $value); - } - - /** * Tests retrieval. */ public function testRetrieval() { diff -u b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php --- b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php @@ -64,2 +64,19 @@ + /** + * Sets attribute values for a source test. + * + * @param object $object + * The destination of the written attribute value. + * @param string $attribute_name + * The name of the attribute to write. + * @param mixed $value + * The value of the written attribute. + */ + protected function writeAttribute($object, $attribute_name, $value) { + $reflection = new \ReflectionClass($object); + $reflection_property = $reflection->getProperty($attribute_name); + $reflection_property->setAccessible(TRUE); + $reflection_property->setValue($object, $value); + } + } only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/lib/Drupal/migrate/MigrateMessage.php @@ -0,0 +1,27 @@ +configuration as $from => $to) { + if ($row->hasSourceProperty($from)) { + $destination_values = $row->getSourceProperty($from); + $row->setDestinationProperty($to, $destination_values); + } + } + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/DefaultValue.php @@ -0,0 +1,35 @@ +configuration as $key => $default_value) { + if (!$row->hasDestinationProperty($key)) { + $row->setDestinationProperty($key, $default_value); + } + } + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/CopyFromSourceTest.php @@ -0,0 +1,91 @@ + 'Node ID', + ); + protected $destinationIds = array( + 'nid' => 'Destination Id', + ); + protected $values = array( + 'nid' => 1, + 'title' => 'node 1', + ); + + /** + * @var \Drupal\migrate\MigrateExecutable + */ + protected $migrateExecutable; + + /** + * @var \Drupal\migrate\Row + */ + protected $row; + + /** + * {@inheritdoc} + */ + public static function getInfo() { + return array( + 'name' => 'PropertyMap class functionality', + 'description' => 'Tests PropertyMap class functionality.', + 'group' => 'Migrate', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->migrateExecutable = $this->getMockBuilder('Drupal\migrate\MigrateExecutable') + ->disableOriginalConstructor() + ->getMock(); + $this->row = new Row($this->values, $this->sourceIds, $this->destinationIds); + } + + /** + * Tests sub destination. + */ + public function testSubDestination() { + $configuration = array( + 'nid' => 'testproperty:sub', + ); + $map = new CopyFromSource($configuration, 'copy_from_source', array()); + $map->apply($this->row, $this->migrateExecutable); + $destination = $this->row->getDestination(); + $this->assertSame(1, $destination['testproperty']['sub']); + } + + /** + * Tests missing source. + */ + public function testNoSourceValue() { + $configuration = array( + 'foo' => 'testproperty:sub', + ); + $map = new CopyFromSource($configuration, 'copy_from_source', array()); + $map->apply($this->row, $this->migrateExecutable); + $destination = $this->row->getDestination(); + $this->assertSame(array(), $destination); + } + +}