Update to Drupal 8.0.2. For more information, see https://www.drupal.org/drupal-8.0.2-release-notes

This commit is contained in:
Pantheon Automation 2016-01-06 16:31:26 -08:00 committed by Greg Anderson
parent 1a0e9d9fac
commit a6b049dd05
538 changed files with 5247 additions and 1594 deletions

View file

@ -26,6 +26,10 @@ migrate_source:
type: ignore
label: 'Constants'
migrate_process:
type: migrate_plugin
label: 'Process'
# Base schema for migrate source plugins that extend
# \Drupal\migrate\Plugin\migrate\source\SqlBase.
migrate_source_sql:

View file

@ -0,0 +1,134 @@
# Schema for the migrate process plugins.
migrate.process.*:
type: migrate_process
label: 'Default process'
migrate.process.callback:
type: migrate_process
label: 'Callback process'
mapping:
callback:
type: string
label: 'Callback'
migrate.process.concat:
type: migrate_process
label: 'Concat process'
mapping:
delimiter:
type: string
label: 'Delimiter'
migrate.process.dedupe_entity:
type: migrate_process
label: 'Dedupe Entity process'
mapping:
entity_type:
type: string
label: 'Entity type'
field:
type: string
label: 'Field name'
postfix:
type: string
label: 'Postfix'
start:
type: integer
label: 'Start'
length:
type: integer
label: 'Length'
migrate.process.extract:
type: migrate_process
label: 'Extract process'
mapping:
default:
type: string
label: 'Default value'
migrate.process.flatten:
type: migrate_process
label: 'Flatten process'
migrate.process.get:
type: migrate_process
label: 'Get process'
mapping:
source:
type: string
label: 'Source key'
migrate.process.iterator:
type: migrate_process
label: 'Iterator process'
mapping:
process:
type: ignore
label: 'Process'
key:
type: string
label: 'Key'
migrate.process.machine_name:
type: migrate_process
label: 'Machine name process'
migrate.process.migration:
type: migrate_process
label: 'Migration process'
mapping:
migration:
type: sequence
label: 'Migration'
source:
type: sequence
label: 'Source keys'
source_ids:
type: string
label: 'Source IDs'
stub_id:
type: string
label: 'Stub ID'
migrate.process.route:
type: migrate_process
label: 'Route process'
migrate.process.skip_on_empty:
type: migrate_process
label: 'Skip on Empty'
migrate.process.skip_row_if_not_set:
type: migrate_process
label: 'Skip Row process if not set'
mapping:
index:
type: integer
label: 'Index'
migrate.process.static_map:
type: migrate_process
label: 'Static Map'
mapping:
map:
type: sequence
label: 'Map'
default_value:
type: string
label: 'Default value'
bypass:
type: boolean
label: 'Bypass lookup'
migrate.process.default_value:
type: migrate_process
label: 'Default value'
mapping:
strict:
type: boolean
label: 'Strict type check'
default_value:
type: string
label: 'Default value'

View file

@ -81,7 +81,7 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
*
* @var array
*/
protected $process;
protected $process = [];
/**
* The cached process plugins.
@ -320,10 +320,10 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
* {@inheritdoc}
*/
public function getDestinationPlugin($stub_being_requested = FALSE) {
if ($stub_being_requested && !empty($this->destination['no_stub'])) {
throw new MigrateSkipRowException;
}
if (!isset($this->destinationPlugin)) {
if ($stub_being_requested && !empty($this->destination['no_stub'])) {
throw new MigrateSkipRowException;
}
$this->destinationPlugin = \Drupal::service('plugin.manager.migrate.destination')->createInstance($this->destination['plugin'], $this->destination, $this);
}
return $this->destinationPlugin;

View file

@ -13,7 +13,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Storage to access migration template configuration in enabled extensions.
*/
class MigrateTemplateStorage {
class MigrateTemplateStorage implements MigrateTemplateStorageInterface {
/**
* Extension sub-directory containing default configuration for migrations.
*/
@ -41,13 +41,7 @@ class MigrateTemplateStorage {
}
/**
* Find all migration templates with the specified tag.
*
* @param $tag
* The tag to match.
*
* @return array
* Any templates (parsed YAML config) that matched, keyed by the ID.
* {@inheritdoc}
*/
public function findTemplatesByTag($tag) {
$templates = $this->getAllTemplates();
@ -63,13 +57,7 @@ class MigrateTemplateStorage {
}
/**
* Retrieve a template given a specific name.
*
* @param string $name
* A migration template name.
*
* @return NULL|array
* A parsed migration template, or NULL if it doesn't exist.
* {@inheritdoc}
*/
public function getTemplateByName($name) {
$templates = $this->getAllTemplates();
@ -77,10 +65,7 @@ class MigrateTemplateStorage {
}
/**
* Retrieves all migration templates belonging to enabled extensions.
*
* @return array
* Array of parsed templates, keyed by the fully-qualified id.
* {@inheritdoc}
*/
public function getAllTemplates() {
$templates = [];

View file

@ -0,0 +1,45 @@
<?php
/**
* @file
* Contains \Drupal\migrate\MigrateTemplateStorageInterface.
*/
namespace Drupal\migrate;
/**
* The MigrateTemplateStorageInterface interface.
*/
interface MigrateTemplateStorageInterface {
/**
* Find all migration templates with the specified tag.
*
* @param $tag
* The tag to match.
*
* @return array
* Any templates (parsed YAML config) that matched, keyed by the ID.
*/
public function findTemplatesByTag($tag);
/**
* Retrieve a template given a specific name.
*
* @param string $name
* A migration template name.
*
* @return NULL|array
* A parsed migration template, or NULL if it doesn't exist.
*/
public function getTemplateByName($name);
/**
* Retrieves all migration templates belonging to enabled extensions.
*
* @return array
* Array of parsed templates, keyed by the fully-qualified id.
*/
public function getAllTemplates();
}

View file

@ -13,7 +13,7 @@ use Drupal\migrate\Plugin\MigratePluginManager;
/**
* Builds migration entities from migration templates.
*/
class MigrationBuilder {
class MigrationBuilder implements MigrationBuilderInterface {
/**
* The builder plugin manager.
@ -33,14 +33,7 @@ class MigrationBuilder {
}
/**
* Builds migration entities from templates.
*
* @param array $templates
* The parsed templates (each of which is an array parsed from YAML), keyed
* by ID.
*
* @return \Drupal\migrate\Entity\MigrationInterface[]
* The migration entities derived from the templates.
* {@inheritdoc}
*/
public function createMigrations(array $templates) {
/** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */

View file

@ -0,0 +1,27 @@
<?php
/**
* @file
* Contains \Drupal\migrate\MigrationBuilderInterface.
*/
namespace Drupal\migrate;
/**
* The migration builder interface.
*/
interface MigrationBuilderInterface {
/**
* Builds migration entities from templates.
*
* @param array $templates
* The parsed templates (each of which is an array parsed from YAML), keyed
* by ID.
*
* @return \Drupal\migrate\Entity\MigrationInterface[]
* The migration entities derived from the templates.
*/
public function createMigrations(array $templates);
}

View file

@ -173,13 +173,13 @@ class MigrationStorage extends ConfigEntityStorage implements MigrateBuildDepend
* Add one or more dependencies to a graph.
*
* @param array $graph
* The graph so far.
* The graph so far, passed by reference.
* @param int $id
* The migration id.
* The migration ID.
* @param string $dependency
* The dependency string.
* @param array $dynamic_ids
* The dynamic id mapping.
* The dynamic ID mapping.
*/
protected function addDependency(array &$graph, $id, $dependency, $dynamic_ids) {
$dependencies = isset($dynamic_ids[$dependency]) ? $dynamic_ids[$dependency] : array($dependency);

View file

@ -11,8 +11,8 @@ namespace Drupal\migrate\Plugin;
* Defines the builder plugin type.
*
* Builder plugins implement custom logic to generate migration entities from
* migration templates. For example, a migration may need to be customized
* based on data that's present in the source database; such customization is
* migration templates. For example, a migration may need to be customized based
* on data that's present in the source database; such customization is
* implemented by builders.
*/
interface MigrateBuilderInterface {

View file

@ -12,6 +12,8 @@ use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
/**
* Defines an interface for Migration Destination classes.
*
* Destinations are responsible for persisting source data into the destination
* Drupal.
*
@ -25,7 +27,7 @@ use Drupal\migrate\Row;
interface MigrateDestinationInterface extends PluginInspectionInterface {
/**
* Get the destination ids.
* Get the destination IDs.
*
* To support MigrateIdMap maps, derived destination classes should return
* schema field definition(s) corresponding to the primary key of the
@ -33,7 +35,7 @@ interface MigrateDestinationInterface extends PluginInspectionInterface {
* key fields of the map table for a migration using this destination.
*
* @return array
* An array of ids.
* An array of IDs.
*/
public function getIds();
@ -43,11 +45,11 @@ interface MigrateDestinationInterface extends PluginInspectionInterface {
* Derived classes must implement fields(), returning a list of available
* destination fields.
*
* @todo Review the cases where we need the Migration parameter,
* can we avoid that?
* @todo Review the cases where we need the Migration parameter, can we avoid
* that? To be resolved with https://www.drupal.org/node/2543568.
*
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* (optional) the migration containing this destination.
* (optional) The migration containing this destination. Defaults to NULL.
*
* @return array
* - Keys: machine names of the fields
@ -64,10 +66,10 @@ interface MigrateDestinationInterface extends PluginInspectionInterface {
* @param \Drupal\migrate\Row $row
* The row object.
* @param array $old_destination_id_values
* The old destination ids.
* (optional) The old destination IDs. Defaults to an empty array.
*
* @return mixed
* The entity id or an indication of success.
* The entity ID or an indication of success.
*/
public function import(Row $row, array $old_destination_id_values = array());
@ -95,4 +97,5 @@ interface MigrateDestinationInterface extends PluginInspectionInterface {
* item should be handled on rollback.
*/
public function rollbackAction();
}

View file

@ -5,7 +5,6 @@
* Contains \Drupal\migrate\Plugin\MigrateDestinationPluginManager.
*/
namespace Drupal\migrate\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
@ -37,7 +36,7 @@ class MigrateDestinationPluginManager extends MigratePluginManager {
*
* @param string $type
* The type of the plugin: row, source, process, destination, entity_field,
* id_map.
* id_map.
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
@ -48,7 +47,8 @@ class MigrateDestinationPluginManager extends MigratePluginManager {
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param string $annotation
* The annotation class name.
* (optional) The annotation class name. Defaults to
* 'Drupal\migrate\Annotation\MigrateDestination'.
*/
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager, $annotation = 'Drupal\migrate\Annotation\MigrateDestination') {
parent::__construct($type, $namespaces, $cache_backend, $module_handler, $annotation);

View file

@ -37,8 +37,8 @@ interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
/**
* Saves a mapping from the source identifiers to the destination identifiers.
*
* Called upon import of one row, we record a mapping from the source ID
* to the destination ID. Also may be called, setting the third parameter to
* Called upon import of one row, we record a mapping from the source ID to
* the destination ID. Also may be called, setting the third parameter to
* NEEDS_UPDATE, to signal an existing record should be re-migrated.
*
* @param \Drupal\migrate\Row $row
@ -47,9 +47,11 @@ interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
* @param array $destination_id_values
* An array of destination identifier values.
* @param int $status
* Status of the source row in the map.
* (optional) Status of the source row in the map. Defaults to
* self::STATUS_IMPORTED.
* @param int $rollback_action
* How to handle the destination object on rollback.
* (optional) How to handle the destination object on rollback. Defaults to
* self::ROLLBACK_DELETE.
*/
public function saveIdMapping(Row $row, array $destination_id_values, $status = self::STATUS_IMPORTED, $rollback_action = self::ROLLBACK_DELETE);
@ -61,7 +63,8 @@ interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
* @param string $message
* The message to record.
* @param int $level
* Optional message severity (defaults to MESSAGE_ERROR).
* (optional) The message severity. Defaults to
* MigrationInterface::MESSAGE_ERROR.
*/
public function saveMessage(array $source_id_values, $message, $level = MigrationInterface::MESSAGE_ERROR);
@ -69,10 +72,11 @@ interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
* Retrieves an iterator over messages relate to source records.
*
* @param array $source_id_values
* (optional) The source identifier keyed values of the record, e.g. ['nid' => 5].
* If empty, all messages are retrieved.
* (optional) The source identifier keyed values of the record, e.g.
* ['nid' => 5]. If empty (the default), all messages are retrieved.
* @param int $level
* (optional) Message severity. If NULL, retrieve messages of all severities.
* (optional) Message severity. If NULL (the default), retrieve messages of
* all severities.
*
* @return \Iterator
* Retrieves an iterator over the message rows.
@ -136,7 +140,7 @@ interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
* @param array $source_id_values
* The source identifier keyed values of the record, e.g. ['nid' => 5].
* @param bool $messages_only
* TRUE to only delete the migrate messages.
* (optional) TRUE to only delete the migrate messages. Defaults to FALSE.
*/
public function delete(array $source_id_values, $messages_only = FALSE);

View file

@ -34,7 +34,7 @@ class MigratePluginManager extends DefaultPluginManager {
*
* @param string $type
* The type of the plugin: row, source, process, destination, entity_field,
* id_map.
* id_map.
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
@ -43,7 +43,8 @@ class MigratePluginManager extends DefaultPluginManager {
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
* @param string $annotation
* The annotation class name.
* (optional) The annotation class name. Defaults to
* 'Drupal\Component\Annotation\PluginID'.
*/
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, $annotation = 'Drupal\Component\Annotation\PluginID') {
$plugin_interface = isset($plugin_interface_map[$type]) ? $plugin_interface_map[$type] : NULL;

View file

@ -37,12 +37,12 @@ interface MigrateProcessInterface extends PluginInspectionInterface {
* @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
* The migration in which this process is being executed.
* @param \Drupal\migrate\Row $row
* The row from the source to process. Normally, just transforming the
* value is adequate but very rarely you might need to change two columns
* at the same time or something like that.
* The row from the source to process. Normally, just transforming the value
* is adequate but very rarely you might need to change two columns at the
* same time or something like that.
* @param string $destination_property
* The destination property currently worked on. This is only used
* together with the $row above.
* The destination property currently worked on. This is only used together
* with the $row above.
*
* @return string|array
* The newly transformed value.

View file

@ -31,7 +31,7 @@ interface MigrateSourceInterface extends \Countable, \Iterator, PluginInspection
public function fields();
/**
* Add additional data to the row.
* Adds additional data to the row.
*
* @param \Drupal\Migrate\Row $row
* The row object.
@ -41,13 +41,17 @@ interface MigrateSourceInterface extends \Countable, \Iterator, PluginInspection
*/
public function prepareRow(Row $row);
/**
* Allows class to decide how it will react when it is treated like a string.
*/
public function __toString();
/**
* Defines the source fields uniquely identifying a source row. None of these
* fields should contain a NULL value - if necessary, use prepareRow() or
* hook_migrate_prepare_row() to rewrite NULL values to appropriate empty
* values (such as '' or 0).
* Defines the source fields uniquely identifying a source row.
*
* None of these fields should contain a NULL value. If necessary, use
* prepareRow() or hook_migrate_prepare_row() to rewrite NULL values to
* appropriate empty values (such as '' or 0).
*
* @return array
* Array keyed by source field name, with values being a schema array

View file

@ -12,7 +12,7 @@ use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Plugin\MigrateBuilderInterface;
/**
* Base class for builder plugins.
* Provides abstract base class for builder plugins.
*/
abstract class BuilderBase extends PluginBase implements MigrateBuilderInterface {
@ -22,7 +22,8 @@ abstract class BuilderBase extends PluginBase implements MigrateBuilderInterface
* @param string $plugin_id
* The plugin ID.
* @param array $configuration
* (optional) Additional configuration for the plugin.
* (optional) Additional configuration for the plugin. Defaults to an empty
* array.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface|\Drupal\migrate\Plugin\RequirementsInterface
* The fully initialized source plugin.

View file

@ -10,6 +10,9 @@ namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
/**
* Defines the base abstract class for component entity display.
*/
abstract class ComponentEntityDisplayBase extends DestinationBase {
const MODE_NAME = '';
@ -54,7 +57,7 @@ abstract class ComponentEntityDisplayBase extends DestinationBase {
}
/**
* Get the entity.
* Gets the entity.
*
* @param string $entity_type
* The entity type to retrieve.

View file

@ -3,8 +3,6 @@
/**
* @file
* Contains \Drupal\migrate\Plugin\migrate\destination\Config.
*
* Provides Configuration Management destination plugin.
*/
namespace Drupal\migrate\Plugin\migrate\destination;
@ -18,6 +16,8 @@ use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides Configuration Management destination plugin.
*
* Persist data to the config system.
*
* When a property is NULL, the default is used unless the configuration option
@ -28,6 +28,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* )
*/
class Config extends DestinationBase implements ContainerFactoryPluginInterface, DependentPluginInterface {
use DependencyTrait;
/**

View file

@ -5,7 +5,6 @@
* Contains \Drupal\migrate\Plugin\migrate\destination\DestinationBase.
*/
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Core\Plugin\PluginBase;
@ -113,4 +112,5 @@ abstract class DestinationBase extends PluginBase implements MigrateDestinationI
$this->rollbackAction = MigrateIdMapInterface::ROLLBACK_PRESERVE;
}
}
}

View file

@ -16,12 +16,15 @@ use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides entity destination plugin.
*
* @MigrateDestination(
* id = "entity",
* deriver = "Drupal\migrate\Plugin\Derivative\MigrateEntity"
* )
*/
abstract class Entity extends DestinationBase implements ContainerFactoryPluginInterface, DependentPluginInterface {
use DependencyTrait;
/**
@ -77,16 +80,16 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
}
/**
* Finds the entity type from configuration or plugin id.
* Finds the entity type from configuration or plugin ID.
*
* @param string $plugin_id
* The plugin id.
* The plugin ID.
*
* @return string
* The entity type.
*/
protected static function getEntityTypeId($plugin_id) {
// Remove "entity:"
// Remove "entity:".
return substr($plugin_id, 7);
}
@ -103,10 +106,10 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
* @param \Drupal\migrate\Row $row
* The row object.
* @param array $old_destination_id_values
* The old destination ids.
* The old destination IDs.
*
* @return \Drupal\Core\Entity\EntityInterface
* The entity we're importing into.
* The entity we are importing into.
*/
protected function getEntity(Row $row, array $old_destination_id_values) {
$entity_id = $old_destination_id_values ? reset($old_destination_id_values) : $this->getEntityId($row);
@ -125,12 +128,13 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
}
/**
* Get the entity id of the row.
* Gets the entity ID of the row.
*
* @param \Drupal\migrate\Row $row
* The row of data.
*
* @return string
* The entity id for the row we're importing.
* The entity ID for the row that we are importing.
*/
protected function getEntityId(Row $row) {
return $row->getDestinationProperty($this->getKey('id'));

View file

@ -10,6 +10,8 @@ namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\migrate\Row;
/**
* Provides entity base field override plugin.
*
* @MigrateDestination(
* id = "entity:base_field_override"
* )

View file

@ -18,7 +18,7 @@ use Drupal\migrate\Row;
*
* This class serves as the import class for most configuration entities.
* It can be necessary to provide a specific entity class if the configuration
* entity has a compound id (see EntityFieldEntity) or it has specific setter
* entity has a compound ID (see EntityFieldEntity) or it has specific setter
* methods (see EntityDateFormat). When implementing an entity destination for
* the latter case, make sure to add a test not only for importing but also
* for re-importing (if that is supported).
@ -39,14 +39,14 @@ class EntityConfigBase extends Entity {
// Ids is keyed by the key name so grab the keys.
$id_keys = array_keys($ids);
if (!$row->getDestinationProperty($id_key)) {
// Set the id into the destination in for form "val1.val2.val3".
// Set the ID into the destination in for form "val1.val2.val3".
$row->setDestinationProperty($id_key, $this->generateId($row, $id_keys));
}
}
$entity = $this->getEntity($row, $old_destination_id_values);
$entity->save();
if (count($ids) > 1) {
// This can only be a config entity, content entities have their id key
// This can only be a config entity, content entities have their ID key
// and that's it.
$return = array();
foreach ($id_keys as $id_key) {
@ -105,15 +105,15 @@ class EntityConfigBase extends Entity {
}
/**
* Generate an entity id.
* Generates an entity ID.
*
* @param \Drupal\migrate\Row $row
* The current row.
* @param array $ids
* The destination ids.
* The destination IDs.
*
* @return string
* The generated entity id.
* The generated entity ID.
*/
protected function generateId(Row $row, array $ids) {
$id_values = array();

View file

@ -7,15 +7,12 @@
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Component\Utility\Random;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\link\LinkItemInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
@ -97,15 +94,15 @@ class EntityContentBase extends Entity {
}
/**
* Save the entity.
* Saves the entity.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The content entity.
* @param array $old_destination_id_values
* An array of destination id values.
* (optional) An array of destination ID values. Defaults to an empty array.
*
* @return array
* An array containing the entity id.
* An array containing the entity ID.
*/
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) {
$entity->save();
@ -122,7 +119,7 @@ class EntityContentBase extends Entity {
}
/**
* Update an entity with the new values from row.
* Updates an entity with the new values from row.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to update.
@ -152,7 +149,7 @@ class EntityContentBase extends Entity {
}
/**
* Do as much population of the stub row as we can.
* Populates as much of the stub row as possible.
*
* @param \Drupal\migrate\Row $row
* The row of data.
@ -185,7 +182,6 @@ class EntityContentBase extends Entity {
if (is_null($values)) {
// Handle failure to generate a sample value.
throw new MigrateException('Stubbing failed, unable to generate value for field ' . $field_name);
break;
}
}

View file

@ -8,6 +8,8 @@
namespace Drupal\migrate\Plugin\migrate\destination;
/**
* Provides entity field instance plugin.
*
* @MigrateDestination(
* id = "entity:field_config"
* )

View file

@ -8,6 +8,8 @@
namespace Drupal\migrate\Plugin\migrate\destination;
/**
* Provides entity field storage configuration plugin.
*
* @MigrateDestination(
* id = "entity:field_storage_config"
* )

View file

@ -12,6 +12,8 @@ use Drupal\migrate\MigrateException;
use Drupal\migrate\Row;
/**
* Provides entity revision destination plugin.
*
* @MigrateDestination(
* id = "entity_revision",
* deriver = "Drupal\migrate\Plugin\Derivative\MigrateEntityRevision"
@ -28,12 +30,12 @@ class EntityRevision extends EntityContentBase {
}
/**
* Get the entity.
* Gets the entity.
*
* @param \Drupal\migrate\Row $row
* The row object.
* @param array $old_destination_id_values
* The old destination ids.
* The old destination IDs.
*
* @return \Drupal\Core\Entity\EntityInterface|false
* The entity or false if it can not be created.

View file

@ -8,6 +8,8 @@
namespace Drupal\migrate\Plugin\migrate\destination;
/**
* Provides entity view mode destination plugin.
*
* @MigrateDestination(
* id = "entity:entity_view_mode"
* )

View file

@ -11,6 +11,8 @@ use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
/**
* Provides null destination plugin.
*
* @MigrateDestination(
* id = "null",
* requirements_met = false

View file

@ -69,6 +69,8 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
protected $database;
/**
* The select query.
*
* @var \Drupal\Core\Database\Query\SelectInterface
*/
protected $query;
@ -300,7 +302,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
$fields = $source_id_schema;
// Add destination identifiers to map table.
// TODO: How do we discover the destination schema?
// @todo How do we discover the destination schema?
$count = 1;
foreach ($this->migration->getDestinationPlugin()->getIds() as $id_definition) {
// Allow dest identifier fields to be NULL (for IGNORED/FAILED
@ -383,35 +385,40 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
// Add any missing columns to the map table.
if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName,
'rollback_action')) {
$this->getDatabase()->schema()->addField($this->mapTableName,
'rollback_action', array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Flag indicating what to do for this item on rollback',
));
$this->getDatabase()->schema()->addField($this->mapTableName, 'rollback_action',
array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Flag indicating what to do for this item on rollback',
)
);
}
if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName, 'hash')) {
$this->getDatabase()->schema()->addField($this->mapTableName, 'hash', array(
'type' => 'varchar',
'length' => '64',
'not null' => FALSE,
'description' => 'Hash of source row data, for detecting changes',
));
$this->getDatabase()->schema()->addField($this->mapTableName, 'hash',
array(
'type' => 'varchar',
'length' => '64',
'not null' => FALSE,
'description' => 'Hash of source row data, for detecting changes',
)
);
}
}
}
/**
* Create schema from an id definition.
* Creates schema from an ID definition.
*
* @param array $id_definition
* A field schema definition. Can be SQL schema or a type data
* based schema. In the latter case, the value of type needs to be
* $typed_data_type.$column
* $typed_data_type.$column.
*
* @return array
* The schema definition.
*/
protected function getFieldSchema(array $id_definition) {
$type_parts = explode('.', $id_definition['type']);
@ -593,8 +600,8 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
*/
public function prepareUpdate() {
$this->getDatabase()->update($this->mapTableName())
->fields(array('source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE))
->execute();
->fields(array('source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE))
->execute();
}
/**
@ -642,10 +649,11 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
/**
* Counts records in a table.
*
* @param $status
* @param int $status
* An integer for the source_row_status column.
* @param $table
* The table to work
* @param string $table
* (optional) The table to work. Defaults to NULL.
*
* @return int
* The number of records.
*/
@ -779,7 +787,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function currentDestination() {
if ($this->valid()) {

View file

@ -22,6 +22,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface {
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactoryInterface
*/
protected $entityQueryFactory;

View file

@ -11,7 +11,6 @@ use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* This plugin sets missing values on the destination.
*
@ -30,4 +29,5 @@ class DefaultValue extends ProcessPluginBase {
}
return $value ?: $this->configuration['default_value'];
}
}

View file

@ -34,4 +34,5 @@ class Flatten extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($value)), FALSE);
}
}

View file

@ -21,6 +21,8 @@ use Drupal\migrate\Row;
class Get extends ProcessPluginBase {
/**
* Flag indicating whether there are multiple values.
*
* @var bool
*/
protected $multiple;
@ -69,4 +71,5 @@ class Get extends ProcessPluginBase {
public function multiple() {
return $this->multiple;
}
}

View file

@ -65,4 +65,5 @@ class Iterator extends ProcessPluginBase {
public function multiple() {
return TRUE;
}
}

View file

@ -29,6 +29,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class MachineName extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The transliteration service.
*
* @var \Drupal\Component\Transliteration\TransliterationInterface
*/
protected $transliteration;
@ -37,13 +39,13 @@ class MachineName extends ProcessPluginBase implements ContainerFactoryPluginInt
* Constructs a MachineName plugin.
*
* @param array $configuration
* The plugin configuration.
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* The plugin definition.
* @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
* The transliteration service.
* The transliteration service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, TransliterationInterface $transliteration) {
parent::__construct($configuration, $plugin_id, $plugin_definition);

View file

@ -0,0 +1,109 @@
<?php
/**
* @file
* Contains \Drupal\migrate\Plugin\migrate\process\MenuLinkContent.
*/
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* This plugin figures out menu link parent plugin IDs.
*
* @MigrateProcessPlugin(
* id = "menu_link_parent"
* )
*/
class MenuLinkParent extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*/
protected $migrationPlugin;
/**
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $menuLinkStorage;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateProcessInterface $migration_plugin, MenuLinkManagerInterface $menu_link_manager, EntityStorageInterface $menu_link_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrationPlugin = $migration_plugin;
$this->menuLinkManager = $menu_link_manager;
$this->menuLinkStorage = $menu_link_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$migration_configuration['migration'][] = $migration->id();
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration),
$container->get('plugin.manager.menu.link'),
$container->get('entity.manager')->getStorage('menu_link_content')
);
}
/**
* {@inheritdoc}
*
* Find the parent link GUID.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$parent_id = array_shift($value);
if (!$parent_id) {
// Top level item.
return '';
}
try {
$already_migrated_id = $this
->migrationPlugin
->transform($parent_id, $migrate_executable, $row, $destination_property);
if ($already_migrated_id && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
return $link->getPluginId();
}
}
catch (MigrateSkipRowException $e) {
}
if (isset($value[1])) {
list($menu_name, $parent_link_path) = $value;
$url = Url::fromUserInput("/$parent_link_path");
if ($url->isRouted()) {
$links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name);
if (count($links) == 1) {
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = reset($links);
return $link->getPluginId();
}
}
}
throw new MigrateSkipRowException;
}
}

View file

@ -5,7 +5,6 @@
* Contains \Drupal\migrate\Plugin\migrate\process\Migration.
*/
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\Core\Entity\EntityStorageInterface;
@ -28,11 +27,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class Migration extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The process plugin manager.
*
* @var \Drupal\migrate\Plugin\MigratePluginManager
*/
protected $processPluginManager;
/**
* The entity storage manager.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $migrationStorage;
@ -115,7 +118,7 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter
// Only keep the process necessary to produce the destination ID.
$process = $migration->get('process');
// We already have the source id values but need to key them for the Row
// We already have the source ID values but need to key them for the Row
// constructor.
$source_ids = $migration->getSourcePlugin()->getIds();
$values = array();
@ -148,7 +151,7 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter
}
/**
* Skip the migration process entirely if the value is FALSE.
* Skips the migration process entirely if the value is FALSE.
*
* @param mixed $value
* The incoming value to transform.

View file

@ -1,4 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\migrate\Plugin\migrate\process\Route.
@ -22,6 +23,8 @@ use Drupal\migrate\Row;
class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The path validator service.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
@ -29,10 +32,10 @@ class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, PathValidatorInterface $pathValidator) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, PathValidatorInterface $path_validator) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->pathValidator = $pathValidator;
$this->pathValidator = $path_validator;
}
/**
@ -60,7 +63,7 @@ class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface
if ($extracted) {
if ($extracted->isExternal()) {
$route['route_name'] = null;
$route['route_name'] = NULL;
$route['route_parameters'] = array();
$route['options'] = $options;
$route['url'] = $extracted->getUri();
@ -83,7 +86,7 @@ class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface
unset($route['options']['query']);
}
$route['options'] = $route['options'] + $options;
$route['url'] = null;
$route['url'] = NULL;
}
}
@ -91,4 +94,3 @@ class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface
}
}

View file

@ -8,10 +8,12 @@
namespace Drupal\migrate\Plugin\migrate\source;
/**
* Provides a dummy select query object for source plugins.
*
* Trait providing a dummy select query object for source plugins based on
* SqlBase which override initializeIterator() to obtain their data from other
* SqlBase services instead of a direct query. This ensures that query() returns
* a valid object, even though it isn't used for iteration.
* a valid object, even though it is not used for iteration.
*/
trait DummyQueryTrait {
@ -19,7 +21,8 @@ trait DummyQueryTrait {
* {@inheritdoc}
*/
public function query() {
// Pass an arbritrary table name - the query should never be executed anyway.
// Pass an arbritrary table name - the query should never be executed
// anyway.
$query = $this->select(uniqid(), 's')
->range(0, 1);
$query->addExpression('1');

View file

@ -34,6 +34,9 @@ class EmptySource extends SourcePluginBase {
return new \ArrayIterator(array(array('id' => '')));
}
/**
* Allows class to decide how it will react when it is treated like a string.
*/
public function __toString() {
return '';
}

View file

@ -28,11 +28,15 @@ use Drupal\migrate\Row;
abstract class SourcePluginBase extends PluginBase implements MigrateSourceInterface {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The entity migration object.
*
* @var \Drupal\migrate\Entity\MigrationInterface
*/
protected $migration;
@ -47,14 +51,14 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
protected $highWaterProperty;
/**
* The current row from the query
* The current row from the query.
*
* @var \Drupal\Migrate\Row
*/
protected $currentRow;
/**
* The primary key of the current row
* The primary key of the current row.
*
* @var array
*/
@ -92,6 +96,8 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
protected $skipCount = FALSE;
/**
* Flags whether to track changes to incloming data.
*
* If TRUE, we will maintain hashed source rows to determine whether incoming
* data has changed.
*
@ -100,6 +106,8 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
protected $trackChanges = FALSE;
/**
* Flags whether source plugin will read the map row and add to data row.
*
* By default, next() will directly read the map row and add it to the data
* row. A source plugin implementation may do this itself (in particular, the
* SQL source can incorporate the map table into the query) - if so, it should
@ -110,16 +118,22 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
protected $mapRowAdded = FALSE;
/**
* The backend cache.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* The migration ID map.
*
* @var \Drupal\migrate\Plugin\MigrateIdMapInterface
*/
protected $idMap;
/**
* The iterator to iterate over the source rows.
*
* @var \Iterator
*/
protected $iterator;
@ -150,7 +164,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
}
/**
* Initialize the iterator with the source data.
* Initializes the iterator with the source data.
*
* @return array
* An array of the data for this source.
@ -158,7 +172,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
protected abstract function initializeIterator();
/**
* Get the module handler.
* Gets the module handler.
*
* @return \Drupal\Core\Extension\ModuleHandlerInterface
* The module handler.
@ -212,6 +226,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
* Returns the iterator that will yield the row arrays to be processed.
*
* @return \Iterator
* The iterator that will yield the row arrays to be processed.
*/
protected function getIterator() {
if (!isset($this->iterator)) {
@ -228,7 +243,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
}
/**
* Get the iterator key.
* Gets the iterator key.
*
* Implementation of Iterator::key - called when entering a loop iteration,
* returning the key of the current row. It must be a scalar - we will
@ -240,17 +255,17 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
}
/**
* Whether the iterator is currently valid.
* Checks whether the iterator is currently valid.
*
* Implementation of Iterator::valid() - called at the top of the loop,
* returning TRUE to process the loop and FALSE to terminate it
* returning TRUE to process the loop and FALSE to terminate it.
*/
public function valid() {
return isset($this->currentRow);
}
/**
* Rewind the iterator.
* Rewinds the iterator.
*
* Implementation of Iterator::rewind() - subclasses of MigrateSource should
* implement performRewind() to do any class-specific setup for iterating
@ -311,14 +326,14 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
// 2. Explicitly set to update.
// 3. The row is newer than the current highwater mark.
// 4. If no such property exists then try by checking the hash of the row.
if (!$row->getIdMap() || $row->needsUpdate() || $this->aboveHighwater($row) || $this->rowChanged($row) ) {
if (!$row->getIdMap() || $row->needsUpdate() || $this->aboveHighwater($row) || $this->rowChanged($row)) {
$this->currentRow = $row->freezeSource();
}
}
}
/**
* Check if the incoming data is newer than what we've previously imported.
* Checks if the incoming data is newer than what we've previously imported.
*
* @param \Drupal\migrate\Row $row
* The row we're importing.
@ -331,7 +346,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
}
/**
* Check if the incoming row has changed since our last import.
* Checks if the incoming row has changed since our last import.
*
* @param \Drupal\migrate\Row $row
* The row we're importing.
@ -344,20 +359,20 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
}
/**
* Getter for currentSourceIds data member.
* Gets the currentSourceIds data member.
*/
public function getCurrentIds() {
return $this->currentSourceIds;
}
/**
* Get the source count.
* Gets the source count.
*
* Return a count of available source records, from the cache if appropriate.
* Returns -1 if the source is not countable.
*
* @param bool $refresh
* Whether or not to refresh the count.
* (optional) Whether or not to refresh the count. Defaults to FALSE.
*
* @return int
* The count.
@ -395,7 +410,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
}
/**
* Get the cache object.
* Gets the cache object.
*
* @return \Drupal\Core\Cache\CacheBackendInterface
* The cache object.

View file

@ -27,11 +27,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPluginInterface {
/**
* The query string.
*
* @var \Drupal\Core\Database\Query\SelectInterface
*/
protected $query;
/**
* The database object.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
@ -65,7 +69,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
}
/**
* Print the query string when the object is used a string.
* Prints the query string when the object is used as a string.
*
* @return string
* The query string.
@ -75,7 +79,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
}
/**
* Get the database connection object.
* Gets the database connection object.
*
* @return \Drupal\Core\Database\Connection
* The database connection.
@ -95,8 +99,9 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
}
/**
* Get a connection to the referenced database, adding the connection if
* necessary.
* Gets a connection to the referenced database.
*
* This method will add the database connection if necessary.
*
* @param array $database_info
* Configuration for the source database connection. The keys are:
@ -136,7 +141,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
}
/**
* A helper for adding tags and metadata to the query.
* Adds tags and metadata to the query.
*
* @return \Drupal\Core\Database\Query\SelectInterface
* The query with additional tags and metadata.
@ -164,8 +169,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
$keys = array();
// The rules for determining what conditions to add to the query are as
// follows (applying first applicable rule)
// follows (applying first applicable rule):
// 1. If the map is joinable, join it. We will want to accept all rows
// which are either not in the map, or marked in the map as NEEDS_UPDATE.
// Note that if high water fields are in play, we want to accept all rows
@ -241,7 +245,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
}
/**
* Check if we can join against the map table.
* Checks if we can join against the map table.
*
* This function specifically catches issues when we're migrating with
* unique sets of credentials for the source and destination database.

View file

@ -10,15 +10,14 @@ namespace Drupal\migrate\Tests;
use Drupal\simpletest\TestBase;
/**
* Allows tests to alter dumps after they've loaded.
* Allows tests to alter dumps after they have loaded.
*
* @s
* @see \Drupal\migrate_drupal\Tests\d6\MigrateFileTest
*/
interface MigrateDumpAlterInterface {
/**
* Allows tests to alter dumps after they've loaded.
* Allows tests to alter dumps after they have loaded.
*
* @param \Drupal\simpletest\TestBase $test
* The test that is being run.

View file

@ -43,7 +43,7 @@ class MigrateEventsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
parent::setUp();
$this->state = \Drupal::state();
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::MAP_SAVE,
@ -85,7 +85,7 @@ class MigrateEventsTest extends KernelTestBase {
$migration = Migration::create($config);
/** @var MigrationInterface $migration */
$executable = new MigrateExecutable($migration, new MigrateMessage);
$executable = new MigrateExecutable($migration, new MigrateMessage());
// As the import runs, events will be dispatched, recording the received
// information in state.
$executable->import();

View file

@ -32,7 +32,7 @@ class MigrateInterruptionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
parent::setUp();
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
array($this, 'postRowSaveEventRecorder'));
@ -64,8 +64,9 @@ class MigrateInterruptionTest extends KernelTestBase {
$migration = Migration::create($config);
/** @var MigrationInterface $migration */
$executable = new MigrateExecutable($migration, new MigrateMessage);
// When the import runs, the first row imported will trigger an interruption.
$executable = new MigrateExecutable($migration, new MigrateMessage());
// When the import runs, the first row imported will trigger an
// interruption.
$result = $executable->import();
$this->assertEqual($result, MigrationInterface::RESULT_INCOMPLETE);

View file

@ -16,7 +16,7 @@ use Drupal\migrate\MigrateMessageInterface;
use Drupal\simpletest\KernelTestBase;
/**
* Test whether idmap messages are sent to the message interface when requested.
* Tests whether idmap messages are sent to message interface when requested.
*
* @group migrate
*/
@ -46,12 +46,12 @@ class MigrateMessageTest extends KernelTestBase implements MigrateMessageInterfa
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
parent::setUp();
$this->installConfig(['system']);
// A simple migration, which will generate a message to the id map because
// A simple migration, which will generate a message to the ID map because
// the concat plugin throws an exception if its source is not an array.
$config = [
'id' => 'sample_data',

View file

@ -81,8 +81,8 @@ class MigrateRollbackTest extends MigrateTestBase {
$this->assertNotNull($map_row['destid1']);
}
// We use taxonomy terms to demonstrate importing and rolling back
// content entities.
// We use taxonomy terms to demonstrate importing and rolling back content
// entities.
$term_data_rows = [
['id' => '1', 'vocab' => '1', 'name' => 'music'],
['id' => '2', 'vocab' => '2', 'name' => 'Bach'],

View file

@ -41,7 +41,7 @@ class MigrateSkipRowTest extends KernelTestBase {
'plugin' => 'embedded_data',
'data_rows' => [
['id' => '1', 'data' => 'skip_and_record'],
['id' => '2', 'data' => 'skip_and_dont_record']
['id' => '2', 'data' => 'skip_and_dont_record'],
],
'ids' => [
'id' => ['type' => 'string'],
@ -57,7 +57,7 @@ class MigrateSkipRowTest extends KernelTestBase {
$migration = Migration::create($config);
$executable = new MigrateExecutable($migration, new MigrateMessage);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$result = $executable->import();
$this->assertEqual($result, MigrationInterface::RESULT_COMPLETED);

View file

@ -11,14 +11,14 @@ use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Entity\MigrationInterface;
/**
* Test migration status tracking.
* Tests migration status tracking.
*
* @group migrate
*/
class MigrateStatusTest extends MigrateTestBase {
/**
* Test different connection types.
* Tests different connection types.
*/
public function testStatus() {
// Create a minimally valid migration.

View file

@ -16,7 +16,7 @@ use Drupal\migrate\Row;
use Drupal\simpletest\KernelTestBase;
/**
* Base class for migration tests.
* Creates abstract base class for migration tests.
*/
abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageInterface {
@ -123,9 +123,9 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
* Prepare any dependent migrations.
*
* @param array $id_mappings
* A list of id mappings keyed by migration ids. Each id mapping is a list
* of two arrays, the first are source ids and the second are destination
* ids.
* A list of ID mappings keyed by migration IDs. Each ID mapping is a list
* of two arrays, the first are source IDs and the second are destination
* IDs.
*/
protected function prepareMigrations(array $id_mappings) {
foreach ($id_mappings as $migration_id => $data) {
@ -146,7 +146,7 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
* Executes a single migration.
*
* @param string|\Drupal\migrate\Entity\MigrationInterface $migration
* The migration to execute, or its ID.
* The migration to execute, or its ID.
*/
protected function executeMigration($migration) {
if (is_string($migration)) {
@ -200,8 +200,9 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
}
/**
* Records a failure in the map table of a specific migration in order to
* test scenarios which require a failed row.
* Records a failure in the map table of a specific migration.
*
* This is done in order to test scenarios which require a failed row.
*
* @param string|\Drupal\migrate\Entity\MigrationInterface $migration
* The migration entity, or its ID.
@ -209,7 +210,8 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
* The raw source row which "failed".
* @param int $status
* (optional) The failure status. Should be one of the
* MigrateIdMapInterface::STATUS_* constants.
* MigrateIdMapInterface::STATUS_* constants. Defaults to
* MigrateIdMapInterface::STATUS_FAILED.
*/
protected function mockFailure($migration, array $row, $status = MigrateIdMapInterface::STATUS_FAILED) {
if (is_string($migration)) {

View file

@ -19,14 +19,14 @@ use Drupal\simpletest\KernelTestBase;
class MigrationTest extends KernelTestBase {
/**
* Enable field because we're using one of its source plugins.
* Enable field because we are using one of its source plugins.
*
* @var array
*/
public static $modules = ['migrate', 'field'];
/**
* Tests Migration::set()
* Tests Migration::set().
*
* @covers ::set()
*/

View file

@ -11,14 +11,14 @@ use Drupal\migrate\Plugin\migrate\source\TestSqlBase;
use Drupal\Core\Database\Database;
/**
* Test the functionality of SqlBase.
* Tests the functionality of SqlBase.
*
* @group migrate
*/
class SqlBaseTest extends MigrateTestBase {
/**
* Test different connection types.
* Tests different connection types.
*/
public function testConnectionTypes() {
$sql_base = new TestSqlBase();
@ -34,7 +34,7 @@ class SqlBaseTest extends MigrateTestBase {
$sql_base->setConfiguration($config);
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
// Validate we've injected our custom key and target.
// Validate we have injected our custom key and target.
$this->assertIdentical($sql_base->getDatabase()->getTarget(), $target);
$this->assertIdentical($sql_base->getDatabase()->getKey(), $key);
@ -62,7 +62,7 @@ class SqlBaseTest extends MigrateTestBase {
$sql_base->setConfiguration(['database_state_key' => $database_state_key]);
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
// Validate we've injected our custom key and target.
// Validate we have injected our custom key and target.
$this->assertIdentical($sql_base->getDatabase()->getTarget(), $target);
$this->assertIdentical($sql_base->getDatabase()->getKey(), $key);
@ -96,14 +96,14 @@ namespace Drupal\migrate\Plugin\migrate\source;
class TestSqlBase extends SqlBase {
/**
* Override the constructor so we can create one easily.
* Overrides the constructor so we can create one easily.
*/
public function __construct() {
$this->state = \Drupal::state();
}
/**
* Get the database without caching it.
* Gets the database without caching it.
*/
public function getDatabase() {
$this->database = NULL;
@ -111,7 +111,7 @@ class TestSqlBase extends SqlBase {
}
/**
* Allow us to set the configuration from a test.
* Allows us to set the configuration from a test.
*
* @param array $config
* The config array.

View file

@ -8,7 +8,7 @@
namespace Drupal\migrate\Tests;
/**
* Test the migration template functionality.
* Tests the migration template functionality.
*
* @group migrate
*/
@ -22,25 +22,25 @@ class TemplateTest extends MigrateTestBase {
public static $modules = array('template_test');
/**
* Test different connection types.
* Tests different connection types.
*/
public function testTemplates() {
$migration_templates = \Drupal::service('migrate.template_storage')->findTemplatesByTag("Template Test");
$expected_url = [
'id' => 'url_template',
'label' => 'Template test - url',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'foobar'],
'destination' => ['plugin' => 'url_alias'],
'id' => 'url_template',
'label' => 'Template test - url',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'foobar'],
'destination' => ['plugin' => 'url_alias'],
];
$expected_node = [
'id' => 'node_template',
'label' => 'Template test - node',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'barfoo'],
'destination' => ['plugin' => 'entity:node'],
'id' => 'node_template',
'label' => 'Template test - node',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'barfoo'],
'destination' => ['plugin' => 'entity:node'],
];
$this->assertIdentical($migration_templates['migrate.migration.url_template'], $expected_url);
$this->assertIdentical($migration_templates['migrate.migration.node_template'], $expected_node);
@ -51,24 +51,24 @@ class TemplateTest extends MigrateTestBase {
* Tests retrieving a template by name.
*/
public function testGetTemplateByName() {
/** @var \Drupal\migrate\MigrateTemplateStorage $template_storage */
/** @var \Drupal\migrate\MigrateTemplateStorageInterface $template_storage */
$template_storage = \Drupal::service('migrate.template_storage');
$expected_url = [
'id' => 'url_template',
'label' => 'Template test - url',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'foobar'],
'destination' => ['plugin' => 'url_alias'],
'id' => 'url_template',
'label' => 'Template test - url',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'foobar'],
'destination' => ['plugin' => 'url_alias'],
];
$expected_node = [
'id' => 'node_template',
'label' => 'Template test - node',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'barfoo'],
'destination' => ['plugin' => 'entity:node'],
'id' => 'node_template',
'label' => 'Template test - node',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'barfoo'],
'destination' => ['plugin' => 'entity:node'],
];
$this->assertIdentical($template_storage->getTemplateByName('migrate.migration.url_template'), $expected_url);
$this->assertIdentical($template_storage->getTemplateByName('migrate.migration.node_template'), $expected_node);

View file

@ -45,7 +45,9 @@ class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
);
/**
* php.init memory_limit value.
* The php.ini memory_limit value.
*
* @var int
*/
protected $memoryLimit = 10000000;
@ -68,12 +70,13 @@ class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
* The second message to assert.
* @param bool $memory_exceeded
* Whether to test the memory exceeded case.
* @param int $memory_usage_first
* (optional) The first memory usage value.
* @param int $memory_usage_second
* @param int|null $memory_usage_first
* (optional) The first memory usage value. Defaults to NULL.
* @param int|null $memory_usage_second
* (optional) The fake amount of memory usage reported after memory reclaim.
* @param int $memory_limit
* (optional) The memory limit.
* Defaults to NULL.
* @param int|null $memory_limit
* (optional) The memory limit. Defaults to NULL.
*/
protected function runMemoryExceededTest($message, $memory_exceeded, $memory_usage_first = NULL, $memory_usage_second = NULL, $memory_limit = NULL) {
$this->executable->setMemoryLimit($memory_limit ?: $this->memoryLimit);

View file

@ -14,7 +14,7 @@ use Drupal\migrate\MigrateException;
use Drupal\migrate\Row;
/**
* @coversDefaultClass \Drupal\Tests\migrate\Unit\MigrateExecutableTest
* @coversDefaultClass \Drupal\migrate\MigrateExecutable
* @group migrate
*/
class MigrateExecutableTest extends MigrateTestCase {
@ -40,6 +40,11 @@ class MigrateExecutableTest extends MigrateTestCase {
*/
protected $executable;
/**
* The migration's configuration values.
*
* @var array
*/
protected $migrationConfiguration = array(
'id' => 'test',
);
@ -224,8 +229,9 @@ class MigrateExecutableTest extends MigrateTestCase {
}
/**
* Tests the import method with a MigrateException being thrown from the
* destination.
* Tests the import method with a thrown MigrateException.
*
* The MigrationException in this case is being thrown from the destination.
*/
public function testImportWithValidRowWithDestinationMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
@ -275,8 +281,9 @@ class MigrateExecutableTest extends MigrateTestCase {
}
/**
* Tests the import method with a MigrateException being thrown from a process
* plugin.
* Tests the import method with a thrown MigrateException.
*
* The MigrationException in this case is being thrown from a process plugin.
*/
public function testImportWithValidRowWithProcesMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
@ -421,6 +428,7 @@ class MigrateExecutableTest extends MigrateTestCase {
* Returns a mock migration source instance.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked migration source.
*/
protected function getMockSource() {
$iterator = $this->getMock('\Iterator');

View file

@ -61,14 +61,16 @@ class MigrateSourceTest extends MigrateTestCase {
protected $executable;
/**
* Get the source plugin to test.
* Gets the source plugin to test.
*
* @param array $configuration
* The source configuration.
* (optional) The source configuration. Defaults to an empty array.
* @param array $migrate_config
* The migration configuration to be used in parent::getMigration().
* (optional) The migration configuration to be used in
* parent::getMigration(). Defaults to an empty array.
* @param int $status
* The default status for the new rows to be imported.
* (optional) The default status for the new rows to be imported. Defaults
* to MigrateIdMapInterface::STATUS_NEEDS_UPDATE.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface
* A mocked source plugin.
@ -367,7 +369,7 @@ class MigrateSourceTest extends MigrateTestCase {
}
/**
* Get a mock executable for the test.
* Gets a mock executable for the test.
*
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration entity.
@ -394,8 +396,9 @@ class StubSourcePlugin extends SourcePluginBase {
* Helper for setting internal module handler implementation.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
function setModuleHandler(ModuleHandlerInterface $module_handler) {
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
@ -426,4 +429,5 @@ class StubSourcePlugin extends SourcePluginBase {
protected function initializeIterator() {
return [];
}
}

View file

@ -29,12 +29,22 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
'id' => 'sql_idmap_test',
];
/**
* The source IDs.
*
* @var array
*/
protected $sourceIds = [
'source_id_property' => [
'type' => 'string',
],
];
/**
* The destination IDs.
*
* @var array
*/
protected $destinationIds = [
'destination_id_property' => [
'type' => 'string',
@ -48,7 +58,10 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*/
protected $database;
public function setUp() {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->database = $this->getDatabase([]);
}
@ -56,7 +69,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* Saves a single ID mapping row in the database.
*
* @param array $map
* The row to save.
* The row to save.
*/
protected function saveMap(array $map) {
$table = 'migrate_map_sql_idmap_test';
@ -114,6 +127,12 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
/**
* Sets defaults for SQL ID map plugin tests.
*
* @return array
* An associative array with the following keys:
* - source_row_status
* - rollback_action
* - hash
*/
protected function idMapDefaults() {
$defaults = array(
@ -351,6 +370,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - Multi-value source ID to multi-value destination ID.
* - Single-value source ID to multi-value destination ID.
* - Multi-value source ID to single-value destination ID.
*
* @return array
* An array of data values.
*/
public function lookupDestinationIdMappingDataProvider() {
return [
@ -368,6 +390,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* Number of source fields to test.
* @param int $num_destination_fields
* Number of destination fields to test.
*
* @dataProvider lookupDestinationIdMappingDataProvider
*/
public function testLookupDestinationIdMapping($num_source_fields, $num_destination_fields) {
@ -435,6 +458,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - Multi-value destination ID to multi-value source ID.
* - Single-value destination ID to multi-value source ID.
* - Multi-value destination ID to single-value source ID.
*
* @return array
* An array of data values.
*/
public function lookupSourceIDMappingDataProvider() {
return [
@ -452,6 +478,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* Number of source fields to test.
* @param int $num_destination_fields
* Number of destination fields to test.
*
* @dataProvider lookupSourceIDMappingDataProvider
*/
public function testLookupSourceIDMapping($num_source_fields, $num_destination_fields) {
@ -556,6 +583,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - No updates.
* - One update.
* - Multiple updates.
*
* @return array
* An array of data values.
*/
public function updateCountDataProvider() {
return [
@ -570,6 +600,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*
* @param int $num_update_rows
* The number of update rows to test.
*
* @dataProvider updateCountDataProvider
*/
public function testUpdateCount($num_update_rows) {
@ -598,6 +629,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - No errors.
* - One error.
* - Multiple errors.
*
* @return array
* An array of data values.
*/
public function errorCountDataProvider() {
return [
@ -612,6 +646,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*
* @param int $num_error_rows
* Number of error rows to test.
*
* @dataProvider errorCountDataProvider
*/
public function testErrorCount($num_error_rows) {
@ -731,7 +766,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*/
public function testDestroy() {
$id_map = $this->getIdMap();
// Initialize the id map.
// Initialize the ID map.
$id_map->getDatabase();
$map_table_name = $id_map->mapTableName();
$message_table_name = $id_map->messageTableName();
@ -789,6 +824,12 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
$this->assertSame(iterator_to_array($this->getIdMap()), $expected_results);
}
/**
* Retrieves the contents of an ID map.
*
* @return array
* The contents of an ID map.
*/
private function getIdMapContents() {
$result = $this->database
->select('migrate_map_sql_idmap_test', 't')

View file

@ -111,7 +111,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
}
/**
* Test the source returns the same rows as expected.
* Tests that the source returns the same rows as expected.
*/
public function testRetrieval() {
$this->assertInstanceOf(SelectInterface::class, $this->source->query());
@ -119,7 +119,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
}
/**
* Test the source returns the row count expected.
* Tests that the source returns the row count expected.
*/
public function testSourceCount() {
$count = $this->source->count();
@ -128,16 +128,22 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
}
/**
* Test the source defines a valid ID.
* Tests the source defines a valid ID.
*/
public function testSourceId() {
$this->assertNotEmpty($this->source->getIds());
}
/**
* Gets the value on a row for a given key.
*
* @param \Drupal\migrate\Row $row
* The row identifier.
* @param string $key
* The key identifier.
*
* @return mixed
* The value on a row for a given key.
*/
protected function getValue($row, $key) {
return $row->getSourceProperty($key);

View file

@ -17,9 +17,16 @@ use Drupal\Tests\UnitTestCase;
*/
abstract class MigrateTestCase extends UnitTestCase {
/**
* An array of migration configuration values.
*
* @var array
*/
protected $migrationConfiguration = [];
/**
* The migration ID map.
*
* @var \Drupal\migrate\Plugin\MigrateIdMapInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $idMap;
@ -32,7 +39,7 @@ abstract class MigrateTestCase extends UnitTestCase {
protected $migrationStatus = MigrationInterface::STATUS_IDLE;
/**
* Retrieve a mocked migration.
* Retrieves a mocked migration.
*
* @return \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked migration.
@ -83,8 +90,8 @@ abstract class MigrateTestCase extends UnitTestCase {
$migration->method('set')
->willReturnCallback(function ($argument, $value) use (&$configuration) {
$configuration[$argument] = $value;
});
$configuration[$argument] = $value;
});
$migration->method('id')
->willReturn($configuration['id']);
@ -93,13 +100,14 @@ abstract class MigrateTestCase extends UnitTestCase {
}
/**
* Get an SQLite database connection object for use in tests.
* Gets an SQLite database connection object for use in tests.
*
* @param array $database_contents
* The database contents faked as an array. Each key is a table name, each
* value is a list of table rows, an associative array of field => value.
* @param array $connection_options
* (optional) Options for the database connection.
* (optional) Options for the database connection. Defaults to an empty
* array.
*
* @return \Drupal\Core\Database\Driver\sqlite\Connection
* The database connection.
@ -136,23 +144,25 @@ abstract class MigrateTestCase extends UnitTestCase {
* Generates a table schema from a row.
*
* @param array $row
* The reference row on which to base the schema.
* The reference row on which to base the schema.
*
* @return array
* The Schema API-ready table schema.
* The Schema API-ready table schema.
*/
protected function createSchemaFromRow(array $row) {
// SQLite uses loose ("affinity") typing, so it's OK for every column
// to be a text field.
// SQLite uses loose ("affinity") typing, so it is OK for every column to be
// a text field.
$fields = array_map(function() { return ['type' => 'text']; }, $row);
return ['fields' => $fields];
}
/**
* Tests a query
* Tests a query.
*
* @param array|\Traversable
* @param array|\Traversable $iter
* The countable. foreach-able actual results if a query is being run.
* @param array $expected_results
* An array of expected results.
*/
public function queryResultTest($iter, $expected_results) {
$this->assertSame(count($expected_results), count($iter), 'Number of results match');
@ -168,9 +178,15 @@ abstract class MigrateTestCase extends UnitTestCase {
}
/**
* Gets the value on a row for a given key.
*
* @param array $row
* The row information.
* @param string $key
* The key identifier.
*
* @return mixed
* The value on a row for a given key.
*/
protected function getValue($row, $key) {
return $row[$key];

View file

@ -23,11 +23,15 @@ use Drupal\Tests\UnitTestCase;
class MigrationStorageTest extends UnitTestCase {
/**
* The migration storage.
*
* @var \Drupal\Tests\migrate\Unit\TestMigrationStorage
*/
protected $storage;
/**
* The storage query.
*
* @var \Drupal\Core\Entity\Query\QueryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $query;
@ -35,7 +39,7 @@ class MigrationStorageTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
$this->query = $this->getMock(QueryInterface::class);
$this->query->method('condition')
->willReturnSelf();
@ -63,7 +67,7 @@ class MigrationStorageTest extends UnitTestCase {
->willReturn(['d6_node__page', 'd6_node__article']);
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']);
$this->assertSame(['d6_node__page', 'd6_node__article', 'd6_user'], $ids);
$this->assertSame(['d6_node__page', 'd6_node__article', 'd6_user'], $ids);
}
/**
@ -76,11 +80,13 @@ class MigrationStorageTest extends UnitTestCase {
->willReturn([]);
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']);
$this->assertSame(['d6_user'], $ids);
$this->assertSame(['d6_user'], $ids);
}
/**
* Tests getVariantIds() when no variants exist and there are no static
* Tests getVariantIds().
*
* This tests getVariantIds() when no variants exist and there are no static
* (non-variant) dependencies.
*
* @covers ::getVariantIds
@ -90,7 +96,7 @@ class MigrationStorageTest extends UnitTestCase {
->willReturn([]);
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_node_revision:*']);
$this->assertSame([], $ids);
$this->assertSame([], $ids);
}
}
@ -98,7 +104,7 @@ class MigrationStorageTest extends UnitTestCase {
/**
* Test version of \Drupal\migrate\MigrationStorage.
*
* Exposes protected methods for testing.
* This class exposes protected methods for testing.
*/
class TestMigrationStorage extends MigrationStorage {

View file

@ -120,29 +120,65 @@ class MigrationTest extends UnitTestCase {
}
/**
* Defines the TestMigration class.
*/
class TestMigration extends Migration {
/**
* Constructs an instance of TestMigration object.
*/
public function __construct() {
}
/**
* Sets the requirements values.
*
* @param array $requirements
* The array of requirement values.
*/
public function setRequirements(array $requirements) {
$this->requirements = $requirements;
}
/**
* Sets the source Plugin.
*
* @param \Drupal\migrate\Plugin\MigrateSourceInterface $source_plugin
* The source Plugin.
*/
public function setSourcePlugin(MigrateSourceInterface $source_plugin) {
$this->sourcePlugin = $source_plugin;
}
/**
* Sets the destination Plugin.
*
* @param \Drupal\migrate\Plugin\MigrateDestinationInterface $destination_plugin
* The destination Plugin.
*/
public function setDestinationPlugin(MigrateDestinationInterface $destination_plugin) {
$this->destinationPlugin = $destination_plugin;
}
/**
* Sets the entity manager service.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
*/
public function setEntityManager(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
}
/**
* Defines the RequirementsAwareSourceInterface.
*/
interface RequirementsAwareSourceInterface extends MigrateSourceInterface, RequirementsInterface {}
/**
* Defines the RequirementsAwareDestinationInterface.
*/
interface RequirementsAwareDestinationInterface extends MigrateDestinationInterface, RequirementsInterface {}

View file

@ -43,7 +43,7 @@ class EntityContentBaseTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
parent::setUp();
$this->migration = $this->prophesize(MigrationInterface::class);

View file

@ -18,16 +18,20 @@ use Drupal\Tests\UnitTestCase;
class SqlBaseTest extends UnitTestCase {
/**
* Tests that the ID map is joinable.
*
* @param bool $expected_result
* The expected result.
* @param bool $id_map_is_sql
* TRUE if we want getIdMap() to return an instance of Sql.
* @param bool $with_id_map
* TRUE if we want the id map to have a valid map of ids.
* TRUE if we want the ID map to have a valid map of IDs.
* @param array $source_options
* An array of connection options for the source connection.
* (optional) An array of connection options for the source connection.
* Defaults to an empty array.
* @param array $idmap_options
* An array of connection options for the id map connection.
* (optional) An array of connection options for the ID map connection.
* Defaults to an empty array.
*
* @dataProvider sqlBaseTestProvider
*/
@ -40,7 +44,7 @@ class SqlBaseTest extends UnitTestCase {
->method('getConnectionOptions')
->willReturn($source_options);
// Setup the id map connection.
// Setup the ID map connection.
$idmap_connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
->disableOriginalConstructor()
->getMock();
@ -86,22 +90,56 @@ class SqlBaseTest extends UnitTestCase {
public function sqlBaseTestProvider() {
return [
// Source ids are empty so mapJoinable() is false.
[FALSE, FALSE, FALSE],
[
FALSE,
FALSE,
FALSE,
],
// Still false because getIdMap() is not a subclass of Sql.
[FALSE, FALSE, TRUE],
[
FALSE,
FALSE,
TRUE,
],
// Test mapJoinable() returns false when source and id connection options
// differ.
[FALSE, TRUE, TRUE, ['username' => 'different_from_map', 'password' => 'different_from_map'], ['username' => 'different_from_source', 'password' => 'different_from_source']],
[
FALSE,
TRUE,
TRUE,
['username' => 'different_from_map', 'password' => 'different_from_map'],
['username' => 'different_from_source', 'password' => 'different_from_source'],
],
// Returns true because source and id map connection options are the same.
[TRUE, TRUE, TRUE, ['username' => 'same_value', 'password' => 'same_value'], ['username' => 'same_value', 'password' => 'same_value']],
[
TRUE,
TRUE,
TRUE,
['username' => 'same_value', 'password' => 'same_value'],
['username' => 'same_value', 'password' => 'same_value'],
],
];
}
}
/**
* Creates a base source class for SQL migration testing.
*/
class TestSqlBase extends SqlBase {
/**
* The database object.
*
* @var object
*/
protected $database;
/**
* The migration IDs.
*
* @var array
*/
protected $ids;
/**
@ -151,7 +189,10 @@ class TestSqlBase extends SqlBase {
}
/**
* Allows us to set the ids during a test.
* Allows us to set the IDs during a test.
*
* @param array $ids
* An array of identifiers.
*/
public function setIds($ids) {
$this->ids = $ids;

View file

@ -53,7 +53,7 @@ class TestMigrateExecutable extends MigrateExecutable {
* Allows access to protected sourceIdValues property.
*
* @param array $source_id_values
* The value to set.
* The values to set.
*/
public function setSourceIdValues($source_id_values) {
$this->sourceIdValues = $source_id_values;
@ -100,7 +100,7 @@ class TestMigrateExecutable extends MigrateExecutable {
* @param int $memory_usage
* The fake memory usage value.
* @param int $cleared_memory_usage
* (optional) The fake cleared memory value.
* (optional) The fake cleared memory value. Defaults to NULL.
*/
public function setMemoryUsage($memory_usage, $cleared_memory_usage = NULL) {
$this->memoryUsage = $memory_usage;

View file

@ -31,6 +31,8 @@ class TestSqlIdMap extends Sql implements \Iterator {
* The configuration for the plugin.
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration to do.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher service.
*/
public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher) {
$this->database = $database;
@ -44,6 +46,18 @@ class TestSqlIdMap extends Sql implements \Iterator {
return parent::getDatabase();
}
/**
* Gets the field schema.
*
* @param array $id_definition
* An array defining the field, with a key 'type'.
*
* @return array
* A field schema depending on value of key 'type'. An empty array is
* returned if 'type' is not defined.
*
* @throws \Drupal\migrate\MigrateException
*/
protected function getFieldSchema(array $id_definition) {
if (!isset($id_definition['type'])) {
return array();
@ -54,14 +68,17 @@ class TestSqlIdMap extends Sql implements \Iterator {
'type' => 'int',
'not null' => TRUE,
);
case 'string':
return array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
);
default:
throw new MigrateException($id_definition['type'] . ' not supported');
}
}
}

View file

@ -41,7 +41,7 @@ class EntityRevisionTest extends UnitTestCase {
*/
protected $fieldTypeManager;
public function setUp() {
protected function setUp() {
parent::setUp();
// Setup mocks to be used when creating a revision destination.